-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Allow arrow keys to navigate MenuAnchor independently of global shortcut definition
#155728
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
gspencergoog
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bleroux
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the test failures, the problem is that DropdownMenu reuses MenuAnchor and defines its own Shortcuts which are superceeded by the Shortcuts added by this PR.
flutter/packages/flutter/lib/src/material/dropdown_menu.dart
Lines 972 to 985 in 7bb9352
| return Shortcuts( | |
| shortcuts: _kMenuTraversalShortcuts, | |
| child: Actions( | |
| actions: <Type, Action<Intent>>{ | |
| _ArrowUpIntent: CallbackAction<_ArrowUpIntent>( | |
| onInvoke: handleUpKeyInvoke, | |
| ), | |
| _ArrowDownIntent: CallbackAction<_ArrowDownIntent>( | |
| onInvoke: handleDownKeyInvoke, | |
| ), | |
| }, | |
| child: menuAnchor, | |
| ), | |
| ); |
| child: child, | ||
| // This `Shortcuts` is needed so that shortcuts work when the focus is on | ||
| // MenuAnchor (specifically, the root menu, since submenus have their own | ||
| // `Shortcuts`.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // `Shortcuts`.) | |
| // `Shortcuts`). |
In french it would be that way, not sure if it is the same in english. 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Period outside the parenthesis is correct in English too 👍
justinmc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch by @bleroux on the Dropdown thing. I'm not sure if it's helpful here but things like Action.overridable also exist.
| child: child, | ||
| // This `Shortcuts` is needed so that shortcuts work when the focus is on | ||
| // MenuAnchor (specifically, the root menu, since submenus have their own | ||
| // `Shortcuts`.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Period outside the parenthesis is correct in English too 👍
|
Yeah I was unsure how to fix the drop down menu, both to make it functional and semantically correct. Thank you for letting me know |
MenuAnchor independently of global shortcut definition
…obal shortcut definition (flutter/flutter#155728)
…obal shortcut definition (flutter/flutter#155728)
…obal shortcut definition (flutter/flutter#155728)
…obal shortcut definition (flutter/flutter#155728)
…obal shortcut definition (flutter/flutter#155728)
…obal shortcut definition (flutter/flutter#155728)
…obal shortcut definition (flutter/flutter#155728)
…obal shortcut definition (flutter/flutter#155728)
Manual roll requested by [email protected] flutter/flutter@ec2e12b...0917e9d 2024-10-05 [email protected] Roll Flutter Engine from 2068577e510b to 01de9dcf6bbf (1 revision) (flutter/flutter#156274) 2024-10-05 [email protected] Roll Flutter Engine from 6d6bc39fe8b1 to 2068577e510b (1 revision) (flutter/flutter#156267) 2024-10-05 [email protected] Roll Flutter Engine from 92b5b318190b to 6d6bc39fe8b1 (4 revisions) (flutter/flutter#156266) 2024-10-05 [email protected] Roll Flutter Engine from fd6082ab6693 to 92b5b318190b (1 revision) (flutter/flutter#156261) 2024-10-05 [email protected] Roll Flutter Engine from bc5f9fc80b06 to fd6082ab6693 (4 revisions) (flutter/flutter#156258) 2024-10-04 [email protected] Roll Flutter Engine from eece6c3ec63a to bc5f9fc80b06 (2 revisions) (flutter/flutter#156252) 2024-10-04 [email protected] Roll pub packages (flutter/flutter#156254) 2024-10-04 [email protected] Roll Flutter Engine from 9fa363bdde20 to eece6c3ec63a (1 revision) (flutter/flutter#156250) 2024-10-04 [email protected] Roll Flutter Engine from d38f5e560a98 to 9fa363bdde20 (1 revision) (flutter/flutter#156249) 2024-10-04 [email protected] remove bringup from Windows tool_integration_tests_* (flutter/flutter#156179) 2024-10-04 [email protected] Roll Flutter Engine from 205484009711 to d38f5e560a98 (4 revisions) (flutter/flutter#156239) 2024-10-04 [email protected] Normalize `ThemeData.cardTheme` (flutter/flutter#153254) 2024-10-04 [email protected] Roll Packages from 429650f to 05bf1d4 (5 revisions) (flutter/flutter#156225) 2024-10-04 [email protected] Roll Flutter Engine from e0109f0fd5b2 to 205484009711 (1 revision) (flutter/flutter#156216) 2024-10-04 [email protected] Roll pub packages (flutter/flutter#156215) 2024-10-04 [email protected] Roll Flutter Engine from c2a9fb051bd0 to e0109f0fd5b2 (1 revision) (flutter/flutter#156213) 2024-10-04 [email protected] Roll Flutter Engine from 66d397dff87a to c2a9fb051bd0 (5 revisions) (flutter/flutter#156206) 2024-10-04 [email protected] Roll Flutter Engine from 20369c5d2b93 to 66d397dff87a (5 revisions) (flutter/flutter#156188) 2024-10-03 [email protected] Roll Flutter Engine from de1762dbc5cc to 20369c5d2b93 (7 revisions) (flutter/flutter#156174) 2024-10-03 [email protected] Refactor devfs_web_ddc_modules_test.dart (flutter/flutter#155609) 2024-10-03 [email protected] Allow arrow keys to navigate `MenuAnchor` independently of global shortcut definition (flutter/flutter#155728) 2024-10-03 [email protected] Inherited Theme: zero rebuilds (flutter/flutter#155699) 2024-10-03 [email protected] Roll Flutter Engine from 247bc68c578e to de1762dbc5cc (4 revisions) (flutter/flutter#156160) 2024-10-03 [email protected] Roll pub packages (flutter/flutter#156159) 2024-10-03 [email protected] pattern-matching refactor (flutter/flutter#154753) 2024-10-03 [email protected] Add autocorrect and enableSuggestions to SearchDelegate (flutter/flutter#154932) 2024-10-03 [email protected] Roll Packages from 7c97c88 to 429650f (6 revisions) (flutter/flutter#156155) 2024-10-03 [email protected] Move some tools test ownership to Ben (flutter/flutter#156123) 2024-10-03 [email protected] further shard the Windows tool_integration_tests* targets (flutter/flutter#156121) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC [email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
…obal shortcut definition (flutter/flutter#155728)
…obal shortcut definition (flutter/flutter#155728)

This PR adjusts the implementation of handling navigational shortcuts (i.e. arrow keys) on
MenuAnchorandDropdownMenu.Motivation
The direct outcome of this PR is to allow keyboard to enter submenus on Web: When the focus is on a
MenuAnchorwhile the menu is open, pressing arrow keys should move the focus to the menu item.MenuAnchorcreated menus to traverse the submenu via keyboard. #119532 (comment).It is caused by the fact that
MenuAnchordoes not wrap itself with aShortcuts, and therefore key events when the focus is on aMenuAnchorhas been working only because the event falls back to theShortcutswidget defined byWidgetsApp, whose default value happens to satisfyMenuAnchor's needs - except on Web where arrow keys are defined to scroll instead of traverse.Instead of defining this problem as "just a patch for Web", I think it's better to define it as a problem of all platforms:
MenuAnchor's shortcuts should be independent ofWidgetsApp.shortcuts. Because even ifWidgetsApp.shortcutsis redefined as something else, people should probably still expect arrow keys to work onMenuAnchor.Therefore this PR makes
MenuAnchorproduce aShortcutsby itself.Dropdown menu
The fix above breaks
DropdownMenu.DropdownMenuusesMenuAnchor, while defining its own shortcuts because, when filter is enabled:Before the PR,
DropdownMenudefines these shortcuts out ofMenuAnchor. In order for theDropdownMenu's shortcuts to take priority, these shortcuts are moved to betweenMenuAnchorand theTextfield.A test is added to verify that the left/right keys move text carets.
Below are psuedo-widget-trees after the PR:
Known issues
After this PR, traversing the menu still have quite a few problems, which are left for other PRs.
Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.