Add keyboard navigation for overflow CommandBar popup by jsuarezruiz · Pull Request #21005 · AvaloniaUI/Avalonia (original) (raw)
What does the pull request do?
Adds keyboard navigation support to the CommandBar overflow popup and improves Tab accessibility for the primary bar. Fix #21000.
What is the current behavior?
Opening the overflow (···) menu with the keyboard was not useful: Up, Down, Home, End, and Escape had no effect, and focus was not moved to the menu when it opened. Tab navigation could not reach the primary command items or the overflow button.
What is the updated/expected behavior with this PR?
- When the overflow popup opens, focus is automatically placed on the first focusable item.
- Up / Down move focus between items, wrapping from last to first and back.
- Home / End jump to the first or last focusable item.
- Escape closes the menu and returns focus to the
···overflow button. AppBarSeparator, disabled, invisible, and non-focusable items are skipped during navigation.- Tab navigation now walks through primary command items and the
···button in order
(KeyboardNavigation.TabNavigation="Local"on the templateDockPanel).
How was the solution implemented (if it's not obvious)?
PART_OverflowPresenter(theItemsControlinside the popup) is now a named template part.CommandBar.OnApplyTemplatesubscribes to itsKeyDownevent — events from focusedAppBarButton/AppBarToggleButtonitems bubble up to it.Popup.Openedtriggers a deferred focus call (Dispatcher.PostatLoadedpriority) so layout is complete beforeFocus()is called. AGetFocusableOverflowItems()helper builds the navigation list on each key press, filtering byIsEnabled,IsVisible,Focusable, and excludingAppBarSeparator.
Checklist
- Added unit tests (if possible)?
- Added XML documentation to any related classes?
- Consider submitting a PR to https://github.com/AvaloniaUI/avalonia-docs with user documentation
Breaking changes
None.
Obsoletions / Deprecations
None.
Fixed issues
Fixes #21000
