Skip to content

Commit

Permalink
fix: ensure menu attributes are set on initial render
Browse files Browse the repository at this point in the history
  • Loading branch information
sodenn committed Feb 23, 2025
1 parent 90bc029 commit 6742465
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions packages/lexical-react/src/shared/LexicalMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,20 @@ export function LexicalMenu<TOption extends MenuOption>({
);
}

function setContainerDivAttributes(
containerDiv: HTMLElement,
className?: string,
) {
if (className != null) {
containerDiv.className = className;
}
containerDiv.setAttribute('aria-label', 'Typeahead menu');
containerDiv.setAttribute('id', 'typeahead-menu');
containerDiv.setAttribute('role', 'listbox');
containerDiv.style.display = 'block';
containerDiv.style.position = 'absolute';
}

export function useMenuAnchorRef(
resolution: MenuResolution | null,
setResolution: (r: MenuResolution | null) => void,
Expand Down Expand Up @@ -540,14 +554,7 @@ export function useMenuAnchorRef(
}

if (!containerDiv.isConnected) {
if (className != null) {
containerDiv.className = className;
}
containerDiv.setAttribute('aria-label', 'Typeahead menu');
containerDiv.setAttribute('id', 'typeahead-menu');
containerDiv.setAttribute('role', 'listbox');
containerDiv.style.display = 'block';
containerDiv.style.position = 'absolute';
setContainerDivAttributes(containerDiv, className);
parent.append(containerDiv);
}
anchorElementRef.current = containerDiv;
Expand Down Expand Up @@ -599,7 +606,7 @@ export function useMenuAnchorRef(
// Append the context for the menu immediately
const containerDiv = anchorElementRef.current;
if (containerDiv != null) {
containerDiv.style.position = 'absolute';
setContainerDivAttributes(containerDiv, className);
if (parent != null) {
parent.append(containerDiv);
}
Expand Down

0 comments on commit 6742465

Please sign in to comment.