Skip to content

Commit

Permalink
[lexical-react] menu positioning: Unrevert PR6510 but with gating (#6566
Browse files Browse the repository at this point in the history
)
  • Loading branch information
potatowagon committed Aug 28, 2024
1 parent 0683d58 commit cd934af
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions packages/lexical-react/src/shared/LexicalMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ export function useMenuAnchorRef(
setResolution: (r: MenuResolution | null) => void,
className?: string,
parent: HTMLElement = document.body,
shouldIncludePageYOffset__EXPERIMENTAL: boolean = true,
): MutableRefObject<HTMLElement> {
const [editor] = useLexicalComposerContext();
const anchorElementRef = useRef<HTMLElement>(document.createElement('div'));
Expand All @@ -495,7 +496,10 @@ export function useMenuAnchorRef(
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__EXPERIMENTAL ? window.pageYOffset : 0)
}px`;
containerDiv.style.left = `${left + window.pageXOffset}px`;
containerDiv.style.height = `${height}px`;
Expand All @@ -519,7 +523,10 @@ export function useMenuAnchorRef(
top - rootElementRect.top > menuHeight + height
) {
containerDiv.style.top = `${
top - menuHeight + window.pageYOffset - height
top -
menuHeight -
height +
(shouldIncludePageYOffset__EXPERIMENTAL ? window.pageYOffset : 0)
}px`;
}
}
Expand All @@ -538,7 +545,13 @@ export function useMenuAnchorRef(
anchorElementRef.current = containerDiv;
rootElement.setAttribute('aria-controls', 'typeahead-menu');
}
}, [editor, resolution, className, parent]);
}, [
editor,
resolution,
shouldIncludePageYOffset__EXPERIMENTAL,
className,
parent,
]);

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

0 comments on commit cd934af

Please sign in to comment.