Skip to content

Commit fc1600a

Browse files
committed
fix(base-ui): connect MenuStore floating root context to useSyncedFloatingRootContext
MenuRoot built a local floating root via useSyncedFloatingRootContext but never installed it on MenuStore, which kept the empty placeholder from createInitialPopupStoreState. This caused MenuTrigger, MenuPopup, MenuPositioner, and MenuStore.setOpen to read a different (inert) context than Root's dismiss/list-navigation hooks. Fix: follow the same pattern as Dialog/Popover/Tooltip stores—create a real FloatingRootStore via createPopupFloatingRootContext in the MenuStore constructor, and pass store.state.floatingRootContext into useSyncedFloatingRootContext so the sync hook reuses it instead of minting a private disconnected instance.
1 parent b4d2510 commit fc1600a

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

‎packages/base-ui/src/menu.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ import type { ContextMenuRootContextValue } from './utils/ContextMenuRootContext
119119
import {
120120
attachPreventUnmountOnClose,
121121
createInitialPopupStoreState,
122+
createPopupFloatingRootContext,
122123
popupStoreSelectors,
123124
setPopupOpenState,
124125
useImplicitActiveTrigger,
@@ -325,8 +326,12 @@ export class MenuStore<Payload> extends ReactStore<
325326
private unsubscribeParentListener: (() => void) | null = null;
326327

327328
constructor(initialState?: Partial<MenuState<Payload>>) {
329+
const initial = { ...createInitialMenuState<Payload>(), ...initialState };
330+
const triggerElements = new PopupTriggerMap();
331+
initial.floatingRootContext = createPopupFloatingRootContext(triggerElements);
332+
328333
super(
329-
{ ...createInitialMenuState<Payload>(), ...initialState },
334+
initial,
330335
{
331336
positionerRef: { current: null },
332337
popupRef: { current: null },
@@ -337,7 +342,7 @@ export class MenuStore<Payload> extends ReactStore<
337342
triggerFocusTargetRef: { current: null },
338343
beforeContentFocusGuardRef: { current: null },
339344
onOpenChangeComplete: undefined,
340-
triggerElements: new PopupTriggerMap(),
345+
triggerElements,
341346
} as MenuContext,
342347
menuSelectors,
343348
);
@@ -821,6 +826,7 @@ function MenuRoot<Payload>(props: any): any {
821826
const floatingRootContext = useSyncedFloatingRootContext(
822827
{
823828
popupStore: store as any,
829+
floatingRootContext: store.state.floatingRootContext,
824830
floatingId,
825831
nested: floatingParentNodeIdFromContext != null,
826832
onOpenChange: setOpen,

0 commit comments

Comments
 (0)