/** * Context plumbing for `` → contained ``s. Mirrors * `packages/react/src/menubar/MenubarContext.ts` but threads reactive * accessors instead of React mutable objects. * * `createContext(null)` + `== null` sentinel — a * `` may be used standalone (no menubar above), in which case * parent-from-context detection returns `null`. */ import { type Accessor, createContext, useContext } from "solid-js"; import type { MutableRef } from "../internals/floating-ui/types"; import type { MenuRootOrientation } from "../menu/root/menu-root-context"; export interface MenubarContextValue { /** Whether the menubar is modal. */ modal: Accessor; /** Whether the menubar is disabled. */ disabled: Accessor; /** The root `role="menubar"` element (for outside-press containment). */ contentElement: Accessor; setContentElement: (el: HTMLElement | null) => void; /** Whether any child menu is currently open. */ hasSubmenuOpen: Accessor; setHasSubmenuOpen: (open: boolean) => void; /** Visual/keyboard orientation of the menubar. */ orientation: Accessor; /** Whether mouseup on a menu item should commit (used by child menus). */ allowMouseUpTriggerRef: MutableRef; /** DOM id of the `` element, useful for `aria-controls`. */ rootId: Accessor; /** * Called by contained ``s when their open state changes. Used to * coordinate sibling auto-close (only one menu open at a time) and to keep * `hasSubmenuOpen` in sync. * * The `closer` callback is invoked on the previously-open menu to request * its closure when another sibling opens. Returns a cleanup function the * child should call on unmount or when its open state flips back. */ registerOpenMenu: (closer: () => void) => () => void; } export const MenubarContext = createContext(null); export function useMenubarContext(): MenubarContextValue; export function useMenubarContext(optional: true): MenubarContextValue | null; export function useMenubarContext( optional?: boolean, ): MenubarContextValue | null { const ctx = useContext(MenubarContext); if (ctx == null && !optional) { throw new Error( "Base UI: MenubarContext is missing. Menubar parts must be placed within .", ); } return ctx; }