[lexical-react] Bug Fix: position the typeahead menu relative to its containing block - #8968
Closed
LeSingh1 wants to merge 1 commit into
Closed
[lexical-react] Bug Fix: position the typeahead menu relative to its containing block#8968LeSingh1 wants to merge 1 commit into
LeSingh1 wants to merge 1 commit into
Conversation
…containing block useMenuAnchorRef absolutely positions the menu anchor and computes its top and left in document coordinates (the caret viewport rect plus window.pageXOffset / pageYOffset). Those coordinates only describe the anchor position while the containing block is the initial containing block, which is the case for the default document.body parent. When a `parent` is passed to LexicalTypeaheadMenuPlugin or LexicalNodeMenuPlugin it is normally positioned so that it can contain the menu, and the menu is then displaced by the parent offset and by the parent scroll position. Translate the caret viewport rect into the coordinate space the anchor is actually laid out in, and keep the previous document-coordinate path when no ancestor establishes a containing block. Adds browser tests, since jsdom reports every rect as zero.
LeSingh1
requested review from
acywatson,
etrepum,
fantactuka,
ivailop7,
potatowagon and
zurfyx
as code owners
August 8, 2026 00:36
|
@LeSingh1 is attempting to deploy a commit to the Meta Open Source Team on Vercel. A member of the Team first needs to authorize it. |
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.
useMenuAnchorRefabsolutely positions the menu anchor and computes itstop/leftin document coordinates (the caret viewport rect pluswindow.pageXOffset/pageYOffset). Those coordinates only describe the anchor's position while its containing block is the initial containing block, which is the case for the defaultdocument.bodyparent. When aparentis passed toLexicalTypeaheadMenuPluginorLexicalNodeMenuPluginit is normally positioned so that it can contain the menu, and the menu is then displaced by the parent's own offset and scroll position — the misaligned placement described at the end of the report.The caret viewport rect is now translated into the coordinate space the anchor is actually laid out in. When no ancestor establishes a containing block the previous document-coordinate path is kept unchanged, including
shouldIncludePageYOffset__EXPERIMENTAL.Adds tests in the browser project, since jsdom reports every rect as zero. Without the change the anchor lands 120px right of the caret for a parent with
margin-left: 120px, with and without parent scroll; the default-body case is a control that passes either way.Scoping this as
Refsrather thanFixes: the menu selection and scrolling symptoms in the issue title no longer reproduce on main. I checked at 1250x1000, 900x420 and 800x300, and with the editor forced into a shortoverflow-y: autocontainer, using both keyboard and mouse — the highlighted item is always the one inserted. The issue was filed against 0.21.0 and main is 0.49.0. This addresses only the mispositioning described in the last paragraph.Refs #6989