UNPKG

@base-ui-components/react

Version:

Base UI is a library of headless ('unstyled') React components and low-level hooks. You gain complete control over your app's CSS and accessibility features.

127 lines 5.03 kB
import * as React from 'react'; import { MenuRootContext } from "./MenuRootContext.js"; import { MenubarContext } from "../../menubar/MenubarContext.js"; import { type BaseUIChangeEventDetails } from "../../utils/createBaseUIEventDetails.js"; import { REASONS } from "../../utils/reasons.js"; import { ContextMenuRootContext } from "../../context-menu/root/ContextMenuRootContext.js"; import { MenuStore } from "../store/MenuStore.js"; import { MenuHandle } from "../store/MenuHandle.js"; import { PayloadChildRenderFunction } from "../../utils/popups/index.js"; /** * Groups all parts of the menu. * Doesn’t render its own HTML element. * * Documentation: [Base UI Menu](https://base-ui.com/react/components/menu) */ export declare function MenuRoot<Payload>(props: MenuRoot.Props<Payload>): import("react/jsx-runtime").JSX.Element; export interface MenuRootProps<Payload = unknown> { /** * Whether the menu is initially open. * * To render a controlled menu, use the `open` prop instead. * @default false */ defaultOpen?: boolean; /** * Whether to loop keyboard focus back to the first item * when the end of the list is reached while using the arrow keys. * @default true */ loopFocus?: boolean; /** * Determines if the menu enters a modal state when open. * - `true`: user interaction is limited to the menu: document page scroll is locked and and pointer interactions on outside elements are disabled. * - `false`: user interaction with the rest of the document is allowed. * @default true */ modal?: boolean; /** * Event handler called when the menu is opened or closed. */ onOpenChange?: (open: boolean, eventDetails: MenuRoot.ChangeEventDetails) => void; /** * Event handler called after any animations complete when the menu is closed. */ onOpenChangeComplete?: (open: boolean) => void; /** * Whether the menu is currently open. */ open?: boolean; /** * The visual orientation of the menu. * Controls whether roving focus uses up/down or left/right arrow keys. * @default 'vertical' */ orientation?: MenuRoot.Orientation; /** * Whether the component should ignore user interaction. * @default false */ disabled?: boolean; /** * When in a submenu, determines whether pressing the Escape key * closes the entire menu, or only the current child menu. * @default true */ closeParentOnEsc?: boolean; /** * A ref to imperative actions. * - `unmount`: When specified, the menu will not be unmounted when closed. * Instead, the `unmount` function must be called to unmount the menu manually. * Useful when the menu's animation is controlled by an external library. * - `close`: When specified, the menu can be closed imperatively. */ actionsRef?: React.RefObject<MenuRoot.Actions>; /** * ID of the trigger that the popover is associated with. * This is useful in conjuntion with the `open` prop to create a controlled popover. * There's no need to specify this prop when the popover is uncontrolled (i.e. when the `open` prop is not set). */ triggerId?: string | null; /** * ID of the trigger that the popover is associated with. * This is useful in conjuntion with the `defaultOpen` prop to create an initially open popover. */ defaultTriggerId?: string | null; /** * A handle to associate the popover with a trigger. * If specified, allows external triggers to control the popover's open state. */ handle?: MenuHandle<Payload>; /** * The content of the popover. * This can be a regular React node or a render function that receives the `payload` of the active trigger. */ children?: React.ReactNode | PayloadChildRenderFunction<Payload>; } export interface MenuRootActions { unmount: () => void; } export type MenuRootChangeEventReason = typeof REASONS.triggerHover | typeof REASONS.triggerFocus | typeof REASONS.triggerPress | typeof REASONS.outsidePress | typeof REASONS.focusOut | typeof REASONS.listNavigation | typeof REASONS.escapeKey | typeof REASONS.itemPress | typeof REASONS.closePress | typeof REASONS.siblingOpen | typeof REASONS.cancelOpen | typeof REASONS.imperativeAction | typeof REASONS.none; export type MenuRootChangeEventDetails = BaseUIChangeEventDetails<MenuRoot.ChangeEventReason> & { preventUnmountOnClose(): void; }; export type MenuRootOrientation = 'horizontal' | 'vertical'; export type MenuParent = { type: 'menu'; store: MenuStore<unknown>; } | { type: 'menubar'; context: MenubarContext; } | { type: 'context-menu'; context: ContextMenuRootContext; } | { type: 'nested-context-menu'; context: ContextMenuRootContext; menuContext: MenuRootContext; } | { type: undefined; }; export declare namespace MenuRoot { type Props<Payload = unknown> = MenuRootProps<Payload>; type Actions = MenuRootActions; type ChangeEventReason = MenuRootChangeEventReason; type ChangeEventDetails = MenuRootChangeEventDetails; type Orientation = MenuRootOrientation; }