Repository navigation
[material_ui] Fix Escape key not closing MenuAnchor opened by tap or click - #13430
Merged
auto-submit[bot] merged 3 commits intoOct 30, 2026
Merged
auto-submit[bot] merged 3 commits into
auto-submit[bot] merged 3 commits into
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request modifies MenuAnchor to manage focus when opened by a tap or click, ensuring that pressing Escape closes the menu. It also adjusts the widget hierarchy in _Submenu and adds corresponding regression tests. Review feedback suggests adding a mounted check in the close animation's completion callback to prevent potential crashes upon disposal, removing redundant detach logic in dispose, and simplifying the focus request logic by removing dead code.
navaronbracke
approved these changes
Oct 29, 2026
flutter-zl
pushed a commit
to flutter-zl/flutter
that referenced
this pull request
Oct 30, 2026
…er#195686) flutter/packages@0b72e92...3742a4e 2026-10-30 stuart.morgan@gmail.com [pigeon] Allow event channel unregistration (flutter/packages#13438) 2026-10-30 mmohankrishna@google.com [material_ui] Fix Escape key not closing MenuAnchor opened by tap or click (flutter/packages#13430) 2026-10-30 tarrinneal@gmail.com manual roll and manual build and copy (flutter/packages#13495) 2026-10-29 tarrinneal@gmail.com [pigeon] Separate native interop Dart bindings into a conditionally imported companion file (flutter/packages#13393) 2026-10-29 victor.orozco@cloudsufi.com [image_picker_ios] PR 4/5 Migrate the view provider, PHPicker save operation, and image utilities to Swift (flutter/packages#13394) 2026-10-29 fluttergithubbot@gmail.com Sync release-material_ui-1.9.0 to main (flutter/packages#13479) 2026-10-29 1961493+harryterkelsen@users.noreply.github.com [material_ui] Unskip web tests that pass on CanvasKit and Skwasm: time_picker_test (flutter/packages#13471) 2026-10-29 48776784+mackings@users.noreply.github.com [vector_graphics] Dispose pictures decoded after their VectorGraphic is removed (flutter/packages#13435) 2026-10-29 50643541+Mairramer@users.noreply.github.com [camera_android_x] implement CameraX RecordingStats and VideoRecordEvent APIs (flutter/packages#13330) 2026-10-29 fluttergithubbot@gmail.com Sync release-go_router-18.1.2 to main (flutter/packages#13480) 2026-10-29 fluttergithubbot@gmail.com Sync release-cupertino_ui-1.1.5 to main (flutter/packages#13481) 2026-10-29 34390549+rohanjariwala03@users.noreply.github.com [vector_graphics_compiler] Fix em units in text positions (flutter/packages#13388) If this roll has caused a breakage, revert this CL and set the roller to dry run mode using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC flutter-ecosystem@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes an issue where pressing the
Escapekey does not close aMenuAnchormenu that was opened by a tap or click whenchildFocusNodeis not provided.Root Cause
MenuAnchoris opened via a tap or click (e.g. from aTextButtonorIconButton) without achildFocusNode, the button does not request focus on tap andRawMenuAnchorState.openonly requests focus onwidget.childFocusNode. As a result,FocusManager.instance.primaryFocusremains outside bothRawMenuAnchorand_Submenu, so key events never route through theirShortcutsorActionswidgets._Submenu.build,FocusScope(node: anchor._menuScopeNode)was placed aboveActionsandShortcuts, so even when_menuScopeNodeitself had primary focus, key events walked up pastFocusScopewithout passing through_Submenu'sShortcutsandActions.Fix
FocusScope(node: anchor._menuScopeNode)insideActionsandShortcutsin_Submenu.buildso key events dispatched to_menuScopeNodewalk up through_kMenuTraversalShortcutsandDismissMenuAction._MenuAnchorState._handleMenuOpenRequest, when a root menu opens without achildFocusNodeand focus is not already inside theMenuAnchorsubtree, move focus to_menuScopeNodeviaFocusScope.of(context).setFirstFocus(_menuScopeNode)(and detach_menuScopeNodecleanly if closed/disposed beforeFocusScopemounts).Fixes flutter/flutter#195059
Pre-Review Checklist
[shared_preferences]///).If you need help, consider asking for advice on the #hackers-new channel on Discord.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assistbot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.Footnotes
Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2