Skip to content
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

[lexical-react] menu positioning: Unrevert PR6510 but with gating #6566

Merged
merged 2 commits into from
Aug 28, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions packages/lexical-react/src/shared/LexicalMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@
setResolution: (r: MenuResolution | null) => void,
className?: string,
parent: HTMLElement = document.body,
shouldIncludePageYOffset: boolean = true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prob just fine for a temporary use case but otherwise I'd be keen a suffix __EXPERIMENTAL or __DEPRECATED so that it doesn't leak into product code in OSS which is harder to deprecate

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suffixed with __EXPERIMENTAL

): MutableRefObject<HTMLElement> {
const [editor] = useLexicalComposerContext();
const anchorElementRef = useRef<HTMLElement>(document.createElement('div'));
Expand All @@ -495,7 +496,10 @@
const {left, top, width, height} = resolution.getRect();
const anchorHeight = anchorElementRef.current.offsetHeight; // use to position under anchor
containerDiv.style.top = `${
top + window.pageYOffset + anchorHeight + 3
top +
anchorHeight +
3 +
(shouldIncludePageYOffset ? window.pageYOffset : 0)
}px`;
containerDiv.style.left = `${left + window.pageXOffset}px`;
containerDiv.style.height = `${height}px`;
Expand All @@ -519,7 +523,10 @@
top - rootElementRect.top > menuHeight + height
) {
containerDiv.style.top = `${
top - menuHeight + window.pageYOffset - height
top -
menuHeight -
height +
(shouldIncludePageYOffset ? window.pageYOffset : 0)
}px`;
}
}
Expand All @@ -538,7 +545,7 @@
anchorElementRef.current = containerDiv;
rootElement.setAttribute('aria-controls', 'typeahead-menu');
}
}, [editor, resolution, className, parent]);

Check warning on line 548 in packages/lexical-react/src/shared/LexicalMenu.ts

View workflow job for this annotation

GitHub Actions / core-tests / integrity (20.11.0)

React Hook useCallback has a missing dependency: 'shouldIncludePageYOffset'. Either include it or remove the dependency array

useEffect(() => {
const rootElement = editor.getRootElement();
Expand Down
Loading