Repository navigation
[material_ui] Fix positioned MenuAnchor menus opening away from the position near screen edges - #13772
Open
muralikrishmt wants to merge 1 commit into
Open
[material_ui] Fix positioned MenuAnchor menus opening away from the position near screen edges#13772muralikrishmt wants to merge 1 commit into
muralikrishmt wants to merge 1 commit into
Conversation
…osition near screen edges When a menu opened with `MenuController.open(position: ...)` doesn't fit, place it relative to the position instead of the bounds of the anchor, so that, for example, a context menu near the bottom of the screen opens just above the pointer instead of above the whole anchor. Fixes flutter/flutter#146086
Contributor
There was a problem hiding this comment.
Code Review
This pull request updates MenuAnchor to ensure that menus opened at a specific position via MenuController.open are positioned and flipped relative to that position rather than the entire anchor. It introduces attachmentRect and attachmentOffset in _MenuLayout._positionChild to handle these calculations and ensures that positioned menus grow upward from their position during animation if they open above it. Comprehensive tests have been added to verify these behaviors under various constraints. There are no review comments, and I have no feedback to provide.
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.
When a menu is opened at a position with
MenuController.open(position: ...), such as a context menu opened at the pointer, and it doesn't fit below that position, it is moved above the top of the wholeMenuAnchorchild instead of above the position. The larger the anchor (for example, a list item, or a whole page used as a context menu region), the further the menu ends up from the pointer. If there is no room above the anchor, the menu is shifted to fit and covers the pointer instead.This happens because
_MenuLayout._positionChildalways computes the fallback positions from the bounds of the anchor. That is right for menus attached to a button, but not for menus attached to a position.As suggested in flutter/flutter#146086, this PR treats the position as an empty anchor rectangle for positioned menus:
alignmentOffsetisn't applied when the menu is moved to the other side of the position, since it isn't applied to positioned menus otherwise.animatedis true, a menu that opens above the position grows upward from the position, so it still starts animating at the pointer, as intended by flutter/flutter%23182932.Menus that aren't opened at a position are not affected. A top-level positioned menu that doesn't fit to the right of the position is still shifted to fit, as before, so the existing
menu position in LTRandmenu position in RTLtests pass unchanged.Six tests are added. Without the fix, five of them fail. The sixth covers the existing behavior when the menu fits neither above nor below the position.
Before:
After:
Fixes flutter/flutter#146086
%23%23 Pre-Review Checklist
[shared_preferences]///).If you need help, consider asking for advice on the %23hackers-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