Add keyboard navigation and focus styles to TreeComboBox and MultiComboBox (#808)
* Initial plan * Add keyboard navigation and focus styles to TreeComboBox Co-authored-by: rabbitism <14807942+rabbitism@users.noreply.github.com> * Fix keyboard handler - add parentheses for clarity and handle Tab key properly Co-authored-by: rabbitism <14807942+rabbitism@users.noreply.github.com> * Add keyboard navigation to MultiComboBox Co-authored-by: rabbitism <14807942+rabbitism@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: rabbitism <14807942+rabbitism@users.noreply.github.com>
This commit is contained in:
@@ -206,6 +206,39 @@ public class MultiComboBox : SelectingItemsControl, IInnerContentControl, IPopup
|
||||
SetCurrentValue(IsDropDownOpenProperty, !IsDropDownOpen);
|
||||
}
|
||||
|
||||
protected override void OnKeyDown(KeyEventArgs e)
|
||||
{
|
||||
base.OnKeyDown(e);
|
||||
if (e.Handled)
|
||||
return;
|
||||
|
||||
// F4 or Alt+Down/Up toggles dropdown
|
||||
if ((e.Key == Key.F4 && !e.KeyModifiers.HasFlag(KeyModifiers.Alt)) ||
|
||||
((e.Key == Key.Down || e.Key == Key.Up) && e.KeyModifiers.HasFlag(KeyModifiers.Alt)))
|
||||
{
|
||||
SetCurrentValue(IsDropDownOpenProperty, !IsDropDownOpen);
|
||||
e.Handled = true;
|
||||
}
|
||||
// Escape closes dropdown
|
||||
else if (IsDropDownOpen && e.Key == Key.Escape)
|
||||
{
|
||||
SetCurrentValue(IsDropDownOpenProperty, false);
|
||||
e.Handled = true;
|
||||
}
|
||||
// Enter or Space opens dropdown when closed
|
||||
else if (!IsDropDownOpen && (e.Key == Key.Return || e.Key == Key.Space))
|
||||
{
|
||||
SetCurrentValue(IsDropDownOpenProperty, true);
|
||||
e.Handled = true;
|
||||
}
|
||||
// Tab closes dropdown
|
||||
else if (IsDropDownOpen && e.Key == Key.Tab)
|
||||
{
|
||||
SetCurrentValue(IsDropDownOpenProperty, false);
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
internal void ItemFocused(MultiComboBoxItem dropDownItem)
|
||||
{
|
||||
if (IsDropDownOpen && dropDownItem.IsFocused && dropDownItem.IsArrangeValid) dropDownItem.BringIntoView();
|
||||
|
||||
@@ -190,6 +190,39 @@ public class TreeComboBox: ItemsControl, IClearControl, IInnerContentControl, IP
|
||||
ContainerForItemPreparedOverride(container, item, index);
|
||||
}
|
||||
|
||||
protected override void OnKeyDown(KeyEventArgs e)
|
||||
{
|
||||
base.OnKeyDown(e);
|
||||
if (e.Handled)
|
||||
return;
|
||||
|
||||
// F4 or Alt+Down/Up toggles dropdown
|
||||
if ((e.Key == Key.F4 && !e.KeyModifiers.HasFlag(KeyModifiers.Alt)) ||
|
||||
((e.Key == Key.Down || e.Key == Key.Up) && e.KeyModifiers.HasFlag(KeyModifiers.Alt)))
|
||||
{
|
||||
SetCurrentValue(IsDropDownOpenProperty, !IsDropDownOpen);
|
||||
e.Handled = true;
|
||||
}
|
||||
// Escape closes dropdown
|
||||
else if (IsDropDownOpen && e.Key == Key.Escape)
|
||||
{
|
||||
SetCurrentValue(IsDropDownOpenProperty, false);
|
||||
e.Handled = true;
|
||||
}
|
||||
// Enter or Space opens dropdown when closed
|
||||
else if (!IsDropDownOpen && (e.Key == Key.Return || e.Key == Key.Space))
|
||||
{
|
||||
SetCurrentValue(IsDropDownOpenProperty, true);
|
||||
e.Handled = true;
|
||||
}
|
||||
// Tab closes dropdown
|
||||
else if (IsDropDownOpen && e.Key == Key.Tab)
|
||||
{
|
||||
SetCurrentValue(IsDropDownOpenProperty, false);
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnPointerReleased(PointerReleasedEventArgs e)
|
||||
{
|
||||
base.OnPointerReleased(e);
|
||||
|
||||
Reference in New Issue
Block a user