Theme
Customize appearance
Components
Menubar
Expose groups of commands in a desktop-style menu bar.
View component source ↗Preview
A minimal example to get started.
Installation
Install this component and its dependencies in a project initialized with shadcn.
pnpm dlx shadcn@latest add https://ui.hyunjoon.net/r/menubar.jsonUsage
This is the basic example. Use the Code tab above for the selected example. Adjust import aliases to match your project.
import {
Menubar,
MenubarMenu,
MenubarTrigger,
MenubarContent,
MenubarItem,
} from "@/components/ui/menubar";
export default function Example() {
return (
<Menubar>
<MenubarMenu>
<MenubarTrigger>File</MenubarTrigger>
<MenubarContent>
<MenubarItem>New file</MenubarItem>
<MenubarItem>Open file</MenubarItem>
</MenubarContent>
</MenubarMenu>
<MenubarMenu>
<MenubarTrigger>Edit</MenubarTrigger>
<MenubarContent>
<MenubarItem>Undo</MenubarItem>
<MenubarItem>Redo</MenubarItem>
</MenubarContent>
</MenubarMenu>
</Menubar>
);
}
API reference
Derived from the installed component types. Native DOM props are also supported where applicable. A dash means no explicit default is documented. Some props depend on the selected mode.
Menubar
| Prop | Type | Default | Description |
|---|---|---|---|
modal | boolean | undefinedboolean | undefined | true | Whether the menubar is modal. |
disabled | boolean | undefinedboolean | undefined | false | Whether the whole menubar is disabled. |
orientation | MenuRootOrientation | undefinedMenuRootOrientation | undefined | 'horizontal' | The orientation of the menubar. |
loopFocus | boolean | undefinedboolean | undefined | true | Whether to loop keyboard focus back to the first item when the end of the list is reached while using the arrow keys. |
ref | React.Ref<HTMLDivElement> | undefinedReact.Ref<HTMLDivElement> | undefined | — | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). |
id | string | undefinedstring | undefined | — | Unique identifier used to associate labels and descriptions. |
children | React.ReactNodeReact.ReactNode | — | Content rendered inside this component. |
onFocus | ((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined | — | Called when the control receives focus. |
onBlur | ((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined | — | Called when the control loses focus. |
onChange | ((event: BaseUIEvent<React.ChangeEvent<HTMLDivElement, Element>>) => void) | undefined((event: BaseUIEvent<React.ChangeEvent<HTMLDivElement, Element>>) => void) | undefined | — | Called when the underlying form control changes; inspect the event for its value. |
onKeyDown | ((event: BaseUIEvent<React.KeyboardEvent<HTMLDivElement>>) => void) | undefined((event: BaseUIEvent<React.KeyboardEvent<HTMLDivElement>>) => void) | undefined | — | Called when a key is pressed while this element is focused. |
onClick | ((event: BaseUIEvent<React.MouseEvent<HTMLDivElement, MouseEvent>>) => void) | undefined((event: BaseUIEvent<React.MouseEvent<HTMLDivElement, MouseEvent>>) => void) | undefined | — | Called when the element is activated. |
className | string | ((state: MenubarState) => string | undefined) | undefinedstring | ((state: MenubarState) => string | undefined) | undefined | — | CSS class applied to the element, or a function that returns a class based on the component's state. |
render | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn…React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, MenubarState> | undefined | — | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
style | React.CSSProperties | ((state: MenubarState) => React.CSSProperties | undefined) | undefin…React.CSSProperties | ((state: MenubarState) => React.CSSProperties | undefined) | undefined | — | Style applied to the element, or a function that returns a style object based on the component's state. |
MenubarPortal
| Prop | Type | Default | Description |
|---|---|---|---|
keepMounted | boolean | undefinedboolean | undefined | false | Whether to keep the portal mounted in the DOM while the popup is hidden. |
container | HTMLElement | ShadowRoot | React.RefObject<HTMLElement | ShadowRoot | null> | null | undef…HTMLElement | ShadowRoot | React.RefObject<HTMLElement | ShadowRoot | null> | null | undefined | — | A parent element to render the portal element into. |
ref | React.Ref<HTMLDivElement> | undefinedReact.Ref<HTMLDivElement> | undefined | — | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). |
id | string | undefinedstring | undefined | — | Unique identifier used to associate labels and descriptions. |
children | React.ReactNodeReact.ReactNode | — | Content rendered inside this component. |
onFocus | ((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined | — | Called when the control receives focus. |
onBlur | ((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined | — | Called when the control loses focus. |
onChange | ((event: BaseUIEvent<React.ChangeEvent<HTMLDivElement, Element>>) => void) | undefined((event: BaseUIEvent<React.ChangeEvent<HTMLDivElement, Element>>) => void) | undefined | — | Called when the underlying form control changes; inspect the event for its value. |
onKeyDown | ((event: BaseUIEvent<React.KeyboardEvent<HTMLDivElement>>) => void) | undefined((event: BaseUIEvent<React.KeyboardEvent<HTMLDivElement>>) => void) | undefined | — | Called when a key is pressed while this element is focused. |
onClick | ((event: BaseUIEvent<React.MouseEvent<HTMLDivElement, MouseEvent>>) => void) | undefined((event: BaseUIEvent<React.MouseEvent<HTMLDivElement, MouseEvent>>) => void) | undefined | — | Called when the element is activated. |
className | string | ((state: MenuPortalState) => string | undefined) | undefinedstring | ((state: MenuPortalState) => string | undefined) | undefined | — | CSS class applied to the element, or a function that returns a class based on the component's state. |
render | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn…React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, MenuPortalState> | undefined | — | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
style | React.CSSProperties | ((state: MenuPortalState) => React.CSSProperties | undefined) | unde…React.CSSProperties | ((state: MenuPortalState) => React.CSSProperties | undefined) | undefined | — | Style applied to the element, or a function that returns a style object based on the component's state. |
MenubarMenu
| Prop | Type | Default | Description |
|---|---|---|---|
defaultOpen | boolean | undefinedboolean | undefined | false | Whether the menu is initially open. To render a controlled menu, use the `open` prop instead. |
loopFocus | boolean | undefinedboolean | undefined | true | Whether to loop keyboard focus back to the first item when the end of the list is reached while using the arrow keys. |
highlightItemOnHover | boolean | undefinedboolean | undefined | true | Whether moving the pointer over items should highlight them. Disabling this prop allows CSS `:hover` to be differentiated from the `:focus` (`data-highlighted`) state. |
modal | boolean | undefinedboolean | undefined | true | Determines if the menu enters a modal state when open. - `true`: user interaction is limited to the menu: document page scroll is locked and pointer interactions on outside elements are disabled. - `false`: user interaction with the rest of the document is allowed. |
onOpenChange | ((open: boolean, eventDetails: MenuPrimitive.Root.ChangeEventDetails) => void) | undefined((open: boolean, eventDetails: MenuPrimitive.Root.ChangeEventDetails) => void) | undefined | — | Event handler called when the menu is opened or closed. |
onOpenChangeComplete | ((open: boolean) => void) | undefined((open: boolean) => void) | undefined | — | Event handler called after any animations complete when the menu is closed. |
open | boolean | undefinedboolean | undefined | — | Whether the menu is currently open. |
orientation | MenuRootOrientation | undefinedMenuRootOrientation | undefined | 'vertical' | The visual orientation of the menu. Controls whether roving focus uses up/down or left/right arrow keys. |
disabled | boolean | undefinedboolean | undefined | false | Whether the component should ignore user interaction. |
closeParentOnEsc | boolean | undefinedboolean | undefined | false | When in a submenu, determines whether pressing the Escape key closes the entire menu, or only the current child menu. |
actionsRef | React.RefObject<MenuRootActions | null> | undefinedReact.RefObject<MenuRootActions | null> | undefined | — | 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. |
triggerId | string | null | undefinedstring | null | undefined | — | ID of the trigger that the popover is associated with. This is useful in conjunction with the `open` prop to create a controlled popover. There's no need to specify this prop when the popover is uncontrolled (that is, when the `open` prop is not set). |
defaultTriggerId | string | null | undefinedstring | null | undefined | — | ID of the trigger that the popover is associated with. This is useful in conjunction with the `defaultOpen` prop to create an initially open popover. |
handle | MenuPrimitive.Handle<unknown> | undefinedMenuPrimitive.Handle<unknown> | undefined | — | A handle to associate the menu with a trigger. If specified, allows external triggers to control the menu's open state. |
children | React.ReactNode | PayloadChildRenderFunction<unknown>React.ReactNode | PayloadChildRenderFunction<unknown> | — | The content of the popover. This can be a regular React node or a render function that receives the `payload` of the active trigger. |
MenubarTrigger
| Prop | Type | Default | Description |
|---|---|---|---|
children | React.ReactNodeReact.ReactNode | — | Content rendered inside this component. |
disabled | boolean | undefinedboolean | undefined | false | Whether the component should ignore user interaction. |
handle | MenuPrimitive.Handle<unknown> | undefinedMenuPrimitive.Handle<unknown> | undefined | — | A handle to associate the trigger with a menu. |
payload | unknownunknown | — | A payload to pass to the menu when it is opened. |
delay | number | undefinednumber | undefined | 100 | How long to wait before the menu may be opened on hover. Specified in milliseconds. Requires the `openOnHover` prop. |
closeDelay | number | undefinednumber | undefined | 0 | How long to wait before closing the menu that was opened on hover. Specified in milliseconds. Requires the `openOnHover` prop. |
openOnHover | boolean | undefinedboolean | undefined | — | Whether the menu should also open when the trigger is hovered. |
nativeButton | boolean | undefinedboolean | undefined | true | Whether the component renders a native `<button>` element when replacing it via the `render` prop. Set to `false` if the rendered element is not a button (for example, `<div>`). |
ref | React.Ref<HTMLButtonElement> | undefinedReact.Ref<HTMLButtonElement> | undefined | — | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). |
id | string | undefinedstring | undefined | — | Unique identifier used to associate labels and descriptions. |
onFocus | ((event: BaseUIEvent<React.FocusEvent<HTMLButtonElement, Element>>) => void) | undefined((event: BaseUIEvent<React.FocusEvent<HTMLButtonElement, Element>>) => void) | undefined | — | Called when the control receives focus. |
onBlur | ((event: BaseUIEvent<React.FocusEvent<HTMLButtonElement, Element>>) => void) | undefined((event: BaseUIEvent<React.FocusEvent<HTMLButtonElement, Element>>) => void) | undefined | — | Called when the control loses focus. |
onChange | ((event: BaseUIEvent<React.ChangeEvent<HTMLButtonElement, Element>>) => void) | undefined((event: BaseUIEvent<React.ChangeEvent<HTMLButtonElement, Element>>) => void) | undefined | — | Called when the underlying form control changes; inspect the event for its value. |
onKeyDown | ((event: BaseUIEvent<React.KeyboardEvent<HTMLButtonElement>>) => void) | undefined((event: BaseUIEvent<React.KeyboardEvent<HTMLButtonElement>>) => void) | undefined | — | Called when a key is pressed while this element is focused. |
onClick | ((event: BaseUIEvent<React.MouseEvent<HTMLButtonElement, MouseEvent>>) => void) | undefine…((event: BaseUIEvent<React.MouseEvent<HTMLButtonElement, MouseEvent>>) => void) | undefined | — | Called when the element is activated. |
name | string | undefinedstring | undefined | — | Field name used in form data. |
type | "button" | "submit" | "reset" | undefined"button" | "submit" | "reset" | undefined | — | The native input or button behavior. |
value | string | number | readonly string[] | undefinedstring | number | readonly string[] | undefined | — | The current value when controlled by the application. |
className | string | ((state: MenuTriggerState) => string | undefined) | undefinedstring | ((state: MenuTriggerState) => string | undefined) | undefined | — | CSS class applied to the element, or a function that returns a class based on the component's state. |
render | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn…React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, MenuTriggerState> | undefined | — | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
style | React.CSSProperties | ((state: MenuTriggerState) => React.CSSProperties | undefined) | und…React.CSSProperties | ((state: MenuTriggerState) => React.CSSProperties | undefined) | undefined | — | Style applied to the element, or a function that returns a style object based on the component's state. |
MenubarContent
| Prop | Type | Default | Description |
|---|---|---|---|
children | React.ReactNodeReact.ReactNode | — | Content rendered inside this component. |
id | string | undefinedstring | undefined | — | Unique identifier used to associate labels and descriptions. |
finalFocus | boolean | React.RefObject<HTMLElement | null> | ((closeType: InteractionType) => boolean |…boolean | React.RefObject<HTMLElement | null> | ((closeType: InteractionType) => boolean | HTMLElement | null | void) | undefined | — | Determines the element to focus when the menu is closed. - `false`: Do not move focus. - `true`: Move focus based on the default behavior (trigger or previously focused element). - `RefObject`: Move focus to the ref element. - `function`: Called with the interaction type (`mouse`, `touch`, `pen`, or `keyboard`). Return an element to focus, `true` to use the default behavior, or `false`/`undefined` to do nothing. |
ref | React.Ref<HTMLDivElement> | undefinedReact.Ref<HTMLDivElement> | undefined | — | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). |
onFocus | ((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined | — | Called when the control receives focus. |
onBlur | ((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined | — | Called when the control loses focus. |
onChange | ((event: BaseUIEvent<React.ChangeEvent<HTMLDivElement, Element>>) => void) | undefined((event: BaseUIEvent<React.ChangeEvent<HTMLDivElement, Element>>) => void) | undefined | — | Called when the underlying form control changes; inspect the event for its value. |
onKeyDown | ((event: BaseUIEvent<React.KeyboardEvent<HTMLDivElement>>) => void) | undefined((event: BaseUIEvent<React.KeyboardEvent<HTMLDivElement>>) => void) | undefined | — | Called when a key is pressed while this element is focused. |
onClick | ((event: BaseUIEvent<React.MouseEvent<HTMLDivElement, MouseEvent>>) => void) | undefined((event: BaseUIEvent<React.MouseEvent<HTMLDivElement, MouseEvent>>) => void) | undefined | — | Called when the element is activated. |
className | string | ((state: MenuPopupState) => string | undefined) | undefinedstring | ((state: MenuPopupState) => string | undefined) | undefined | — | CSS class applied to the element, or a function that returns a class based on the component's state. |
render | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn…React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, MenuPopupState> | undefined | — | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
style | React.CSSProperties | ((state: MenuPopupState) => React.CSSProperties | undefined) | undef…React.CSSProperties | ((state: MenuPopupState) => React.CSSProperties | undefined) | undefined | — | Style applied to the element, or a function that returns a style object based on the component's state. |
align | Align | undefinedAlign | undefined | "start" | How to align the popup relative to the specified side. |
side | Side | undefinedSide | undefined | 'bottom' | Which side of the anchor element to align the popup against. May automatically change to avoid collisions. |
sideOffset | number | OffsetFunction | undefinednumber | OffsetFunction | undefined | 8 | Distance between the anchor and the popup in pixels. Also accepts a function that returns the distance to read the dimensions of the anchor and positioner elements, along with its side and alignment. The function takes a `data` object parameter with the following properties: - `data.anchor`: the dimensions of the anchor element with properties `width` and `height`. - `data.positioner`: the dimensions of the positioner element with properties `width` and `height`. - `data.side`: which side of the anchor element the positioner is aligned against. - `data.align`: how the positioner is aligned relative to the specified side. |
alignOffset | number | OffsetFunction | undefinednumber | OffsetFunction | undefined | -4 | Additional offset along the alignment axis in pixels. Also accepts a function that returns the offset to read the dimensions of the anchor and positioner elements, along with its side and alignment. The function takes a `data` object parameter with the following properties: - `data.anchor`: the dimensions of the anchor element with properties `width` and `height`. - `data.positioner`: the dimensions of the positioner element with properties `width` and `height`. - `data.side`: which side of the anchor element the positioner is aligned against. - `data.align`: how the positioner is aligned relative to the specified side. |
MenubarGroup
| Prop | Type | Default | Description |
|---|---|---|---|
children | React.ReactNodeReact.ReactNode | — | The content of the component. |
ref | React.Ref<HTMLDivElement> | undefinedReact.Ref<HTMLDivElement> | undefined | — | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). |
id | string | undefinedstring | undefined | — | Unique identifier used to associate labels and descriptions. |
onFocus | ((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined | — | Called when the control receives focus. |
onBlur | ((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined | — | Called when the control loses focus. |
onChange | ((event: BaseUIEvent<React.ChangeEvent<HTMLDivElement, Element>>) => void) | undefined((event: BaseUIEvent<React.ChangeEvent<HTMLDivElement, Element>>) => void) | undefined | — | Called when the underlying form control changes; inspect the event for its value. |
onKeyDown | ((event: BaseUIEvent<React.KeyboardEvent<HTMLDivElement>>) => void) | undefined((event: BaseUIEvent<React.KeyboardEvent<HTMLDivElement>>) => void) | undefined | — | Called when a key is pressed while this element is focused. |
onClick | ((event: BaseUIEvent<React.MouseEvent<HTMLDivElement, MouseEvent>>) => void) | undefined((event: BaseUIEvent<React.MouseEvent<HTMLDivElement, MouseEvent>>) => void) | undefined | — | Called when the element is activated. |
className | string | ((state: MenuGroupState) => string | undefined) | undefinedstring | ((state: MenuGroupState) => string | undefined) | undefined | — | CSS class applied to the element, or a function that returns a class based on the component's state. |
render | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn…React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, MenuGroupState> | undefined | — | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
style | React.CSSProperties | ((state: MenuGroupState) => React.CSSProperties | undefined) | undef…React.CSSProperties | ((state: MenuGroupState) => React.CSSProperties | undefined) | undefined | — | Style applied to the element, or a function that returns a style object based on the component's state. |
MenubarSeparator
| Prop | Type | Default | Description |
|---|---|---|---|
orientation | Orientation | undefinedOrientation | undefined | 'horizontal' | The orientation of the separator. |
ref | React.Ref<HTMLDivElement> | undefinedReact.Ref<HTMLDivElement> | undefined | — | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). |
id | string | undefinedstring | undefined | — | Unique identifier used to associate labels and descriptions. |
children | React.ReactNodeReact.ReactNode | — | Content rendered inside this component. |
onFocus | ((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined | — | Called when the control receives focus. |
onBlur | ((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined | — | Called when the control loses focus. |
onChange | ((event: BaseUIEvent<React.ChangeEvent<HTMLDivElement, Element>>) => void) | undefined((event: BaseUIEvent<React.ChangeEvent<HTMLDivElement, Element>>) => void) | undefined | — | Called when the underlying form control changes; inspect the event for its value. |
onKeyDown | ((event: BaseUIEvent<React.KeyboardEvent<HTMLDivElement>>) => void) | undefined((event: BaseUIEvent<React.KeyboardEvent<HTMLDivElement>>) => void) | undefined | — | Called when a key is pressed while this element is focused. |
onClick | ((event: BaseUIEvent<React.MouseEvent<HTMLDivElement, MouseEvent>>) => void) | undefined((event: BaseUIEvent<React.MouseEvent<HTMLDivElement, MouseEvent>>) => void) | undefined | — | Called when the element is activated. |
className | string | ((state: SeparatorState) => string | undefined) | undefinedstring | ((state: SeparatorState) => string | undefined) | undefined | — | CSS class applied to the element, or a function that returns a class based on the component's state. |
render | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn…React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, SeparatorState> | undefined | — | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
style | React.CSSProperties | ((state: SeparatorState) => React.CSSProperties | undefined) | undef…React.CSSProperties | ((state: SeparatorState) => React.CSSProperties | undefined) | undefined | — | Style applied to the element, or a function that returns a style object based on the component's state. |
MenubarLabel
| Prop | Type | Default | Description |
|---|---|---|---|
ref | React.Ref<HTMLDivElement> | undefinedReact.Ref<HTMLDivElement> | undefined | — | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). |
id | string | undefinedstring | undefined | — | Unique identifier used to associate labels and descriptions. |
children | React.ReactNodeReact.ReactNode | — | Content rendered inside this component. |
onFocus | ((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined | — | Called when the control receives focus. |
onBlur | ((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined | — | Called when the control loses focus. |
onChange | ((event: BaseUIEvent<React.ChangeEvent<HTMLDivElement, Element>>) => void) | undefined((event: BaseUIEvent<React.ChangeEvent<HTMLDivElement, Element>>) => void) | undefined | — | Called when the underlying form control changes; inspect the event for its value. |
onKeyDown | ((event: BaseUIEvent<React.KeyboardEvent<HTMLDivElement>>) => void) | undefined((event: BaseUIEvent<React.KeyboardEvent<HTMLDivElement>>) => void) | undefined | — | Called when a key is pressed while this element is focused. |
onClick | ((event: BaseUIEvent<React.MouseEvent<HTMLDivElement, MouseEvent>>) => void) | undefined((event: BaseUIEvent<React.MouseEvent<HTMLDivElement, MouseEvent>>) => void) | undefined | — | Called when the element is activated. |
className | string | ((state: MenuGroupLabelState) => string | undefined) | undefinedstring | ((state: MenuGroupLabelState) => string | undefined) | undefined | — | CSS class applied to the element, or a function that returns a class based on the component's state. |
render | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn…React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, MenuGroupLabelState> | undefined | — | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
style | React.CSSProperties | ((state: MenuGroupLabelState) => React.CSSProperties | undefined) | …React.CSSProperties | ((state: MenuGroupLabelState) => React.CSSProperties | undefined) | undefined | — | Style applied to the element, or a function that returns a style object based on the component's state. |
inset | boolean | undefinedboolean | undefined | — | Configures inset; see the accepted type. |
MenubarItem
| Prop | Type | Default | Description |
|---|---|---|---|
onClick | ((event: BaseUIEvent<React.MouseEvent<HTMLDivElement, MouseEvent>>) => void) | undefined((event: BaseUIEvent<React.MouseEvent<HTMLDivElement, MouseEvent>>) => void) | undefined | — | The click handler for the menu item. |
disabled | boolean | undefinedboolean | undefined | false | Whether the component should ignore user interaction. |
label | string | undefinedstring | undefined | — | Overrides the text label to use when the item is matched during keyboard text navigation. |
id | string | undefinedstring | undefined | — | Unique identifier used to associate labels and descriptions. |
closeOnClick | boolean | undefinedboolean | undefined | true | Whether to close the menu when the item is clicked. |
nativeButton | boolean | undefinedboolean | undefined | false | Whether the component renders a native `<button>` element when replacing it via the `render` prop. Set to `true` if the rendered element is a native button. |
ref | React.Ref<HTMLDivElement> | undefinedReact.Ref<HTMLDivElement> | undefined | — | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). |
children | React.ReactNodeReact.ReactNode | — | Content rendered inside this component. |
onFocus | ((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined | — | Called when the control receives focus. |
onBlur | ((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined | — | Called when the control loses focus. |
onChange | ((event: BaseUIEvent<React.ChangeEvent<HTMLDivElement, Element>>) => void) | undefined((event: BaseUIEvent<React.ChangeEvent<HTMLDivElement, Element>>) => void) | undefined | — | Called when the underlying form control changes; inspect the event for its value. |
onKeyDown | ((event: BaseUIEvent<React.KeyboardEvent<HTMLDivElement>>) => void) | undefined((event: BaseUIEvent<React.KeyboardEvent<HTMLDivElement>>) => void) | undefined | — | Called when a key is pressed while this element is focused. |
className | string | ((state: MenuItemState) => string | undefined) | undefinedstring | ((state: MenuItemState) => string | undefined) | undefined | — | CSS class applied to the element, or a function that returns a class based on the component's state. |
render | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn…React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, MenuItemState> | undefined | — | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
style | React.CSSProperties | ((state: MenuItemState) => React.CSSProperties | undefined) | undefi…React.CSSProperties | ((state: MenuItemState) => React.CSSProperties | undefined) | undefined | — | Style applied to the element, or a function that returns a style object based on the component's state. |
inset | boolean | undefinedboolean | undefined | — | Configures inset; see the accepted type. |
variant | "default" | "destructive" | undefined"default" | "destructive" | undefined | "default" | Visual treatment of the component. |
MenubarShortcut
| Prop | Type | Default | Description |
|---|---|---|---|
ref | React.Ref<HTMLSpanElement> | undefinedReact.Ref<HTMLSpanElement> | undefined | — | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). |
defaultChecked | boolean | undefinedboolean | undefined | — | Initial checked state for an uncontrolled control. |
defaultValue | string | number | readonly string[] | undefinedstring | number | readonly string[] | undefined | — | Initial value for an uncontrolled component. |
className | string | undefinedstring | undefined | — | Additional CSS classes merged with the component styles. |
id | string | undefinedstring | undefined | — | Unique identifier used to associate labels and descriptions. |
children | React.ReactNodeReact.ReactNode | — | Content rendered inside this component. |
onFocus | React.FocusEventHandler<HTMLSpanElement> | undefinedReact.FocusEventHandler<HTMLSpanElement> | undefined | — | Called when the control receives focus. |
onBlur | React.FocusEventHandler<HTMLSpanElement> | undefinedReact.FocusEventHandler<HTMLSpanElement> | undefined | — | Called when the control loses focus. |
onChange | React.ChangeEventHandler<HTMLSpanElement, Element> | undefinedReact.ChangeEventHandler<HTMLSpanElement, Element> | undefined | — | Called when the underlying form control changes; inspect the event for its value. |
onKeyDown | React.KeyboardEventHandler<HTMLSpanElement> | undefinedReact.KeyboardEventHandler<HTMLSpanElement> | undefined | — | Called when a key is pressed while this element is focused. |
onClick | React.MouseEventHandler<HTMLSpanElement> | undefinedReact.MouseEventHandler<HTMLSpanElement> | undefined | — | Called when the element is activated. |
MenubarCheckboxItem
| Prop | Type | Default | Description |
|---|---|---|---|
checked | boolean | undefinedboolean | undefined | — | Whether the checkbox item is currently ticked. To render an uncontrolled checkbox item, use the `defaultChecked` prop instead. |
defaultChecked | boolean | undefinedboolean | undefined | false | Whether the checkbox item is initially ticked. To render a controlled checkbox item, use the `checked` prop instead. |
onCheckedChange | ((checked: boolean, eventDetails: MenuPrimitive.CheckboxItem.ChangeEventDetails) => void) …((checked: boolean, eventDetails: MenuPrimitive.CheckboxItem.ChangeEventDetails) => void) | undefined | — | Event handler called when the checkbox item is ticked or unticked. |
onClick | ((event: BaseUIEvent<React.MouseEvent<HTMLDivElement, MouseEvent>>) => void) | undefined((event: BaseUIEvent<React.MouseEvent<HTMLDivElement, MouseEvent>>) => void) | undefined | — | The click handler for the menu item. |
disabled | boolean | undefinedboolean | undefined | false | Whether the component should ignore user interaction. |
label | string | undefinedstring | undefined | — | Overrides the text label to use when the item is matched during keyboard text navigation. |
id | string | undefinedstring | undefined | — | Unique identifier used to associate labels and descriptions. |
closeOnClick | boolean | undefinedboolean | undefined | false | Whether to close the menu when the item is clicked. |
nativeButton | boolean | undefinedboolean | undefined | false | Whether the component renders a native `<button>` element when replacing it via the `render` prop. Set to `true` if the rendered element is a native button. |
ref | React.Ref<HTMLDivElement> | undefinedReact.Ref<HTMLDivElement> | undefined | — | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). |
children | React.ReactNodeReact.ReactNode | — | Content rendered inside this component. |
onFocus | ((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined | — | Called when the control receives focus. |
onBlur | ((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined | — | Called when the control loses focus. |
onChange | ((event: BaseUIEvent<React.ChangeEvent<HTMLDivElement, Element>>) => void) | undefined((event: BaseUIEvent<React.ChangeEvent<HTMLDivElement, Element>>) => void) | undefined | — | Called when the underlying form control changes; inspect the event for its value. |
onKeyDown | ((event: BaseUIEvent<React.KeyboardEvent<HTMLDivElement>>) => void) | undefined((event: BaseUIEvent<React.KeyboardEvent<HTMLDivElement>>) => void) | undefined | — | Called when a key is pressed while this element is focused. |
className | string | ((state: MenuCheckboxItemState) => string | undefined) | undefinedstring | ((state: MenuCheckboxItemState) => string | undefined) | undefined | — | CSS class applied to the element, or a function that returns a class based on the component's state. |
render | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn…React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, MenuCheckboxItemState> | undefined | — | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
style | React.CSSProperties | ((state: MenuCheckboxItemState) => React.CSSProperties | undefined) …React.CSSProperties | ((state: MenuCheckboxItemState) => React.CSSProperties | undefined) | undefined | — | Style applied to the element, or a function that returns a style object based on the component's state. |
inset | boolean | undefinedboolean | undefined | — | Configures inset; see the accepted type. |
MenubarRadioGroup
| Prop | Type | Default | Description |
|---|---|---|---|
children | React.ReactNodeReact.ReactNode | — | The content of the component. |
value | anyany | — | The controlled value of the radio item that should be currently selected. To render an uncontrolled radio group, use the `defaultValue` prop instead. |
defaultValue | anyany | — | The uncontrolled value of the radio item that should be initially selected. To render a controlled radio group, use the `value` prop instead. |
onValueChange | ((value: any, eventDetails: MenuPrimitive.RadioGroup.ChangeEventDetails) => void) | undefi…((value: any, eventDetails: MenuPrimitive.RadioGroup.ChangeEventDetails) => void) | undefined | — | Function called when the selected value changes. |
disabled | boolean | undefinedboolean | undefined | false | Whether the component should ignore user interaction. |
ref | React.Ref<HTMLDivElement> | undefinedReact.Ref<HTMLDivElement> | undefined | — | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). |
id | string | undefinedstring | undefined | — | Unique identifier used to associate labels and descriptions. |
onFocus | ((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined | — | Called when the control receives focus. |
onBlur | ((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined | — | Called when the control loses focus. |
onChange | ((event: BaseUIEvent<React.ChangeEvent<HTMLDivElement, Element>>) => void) | undefined((event: BaseUIEvent<React.ChangeEvent<HTMLDivElement, Element>>) => void) | undefined | — | Called when the underlying form control changes; inspect the event for its value. |
onKeyDown | ((event: BaseUIEvent<React.KeyboardEvent<HTMLDivElement>>) => void) | undefined((event: BaseUIEvent<React.KeyboardEvent<HTMLDivElement>>) => void) | undefined | — | Called when a key is pressed while this element is focused. |
onClick | ((event: BaseUIEvent<React.MouseEvent<HTMLDivElement, MouseEvent>>) => void) | undefined((event: BaseUIEvent<React.MouseEvent<HTMLDivElement, MouseEvent>>) => void) | undefined | — | Called when the element is activated. |
className | string | ((state: MenuRadioGroupState) => string | undefined) | undefinedstring | ((state: MenuRadioGroupState) => string | undefined) | undefined | — | CSS class applied to the element, or a function that returns a class based on the component's state. |
render | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn…React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, MenuRadioGroupState> | undefined | — | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
style | React.CSSProperties | ((state: MenuRadioGroupState) => React.CSSProperties | undefined) | …React.CSSProperties | ((state: MenuRadioGroupState) => React.CSSProperties | undefined) | undefined | — | Style applied to the element, or a function that returns a style object based on the component's state. |
MenubarRadioItem
| Prop | Type | Default | Description |
|---|---|---|---|
valueRequired | anyany | — | Value of the radio item. This is the value that will be set in the MenuRadioGroup when the item is selected. |
onClick | ((event: BaseUIEvent<React.MouseEvent<HTMLDivElement, MouseEvent>>) => void) | undefined((event: BaseUIEvent<React.MouseEvent<HTMLDivElement, MouseEvent>>) => void) | undefined | — | The click handler for the menu item. |
disabled | boolean | undefinedboolean | undefined | false | Whether the component should ignore user interaction. |
label | string | undefinedstring | undefined | — | Overrides the text label to use when the item is matched during keyboard text navigation. |
id | string | undefinedstring | undefined | — | Unique identifier used to associate labels and descriptions. |
closeOnClick | boolean | undefinedboolean | undefined | false | Whether to close the menu when the item is clicked. |
nativeButton | boolean | undefinedboolean | undefined | false | Whether the component renders a native `<button>` element when replacing it via the `render` prop. Set to `true` if the rendered element is a native button. |
ref | React.Ref<HTMLDivElement> | undefinedReact.Ref<HTMLDivElement> | undefined | — | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). |
children | React.ReactNodeReact.ReactNode | — | Content rendered inside this component. |
onFocus | ((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined | — | Called when the control receives focus. |
onBlur | ((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined | — | Called when the control loses focus. |
onChange | ((event: BaseUIEvent<React.ChangeEvent<HTMLDivElement, Element>>) => void) | undefined((event: BaseUIEvent<React.ChangeEvent<HTMLDivElement, Element>>) => void) | undefined | — | Called when the underlying form control changes; inspect the event for its value. |
onKeyDown | ((event: BaseUIEvent<React.KeyboardEvent<HTMLDivElement>>) => void) | undefined((event: BaseUIEvent<React.KeyboardEvent<HTMLDivElement>>) => void) | undefined | — | Called when a key is pressed while this element is focused. |
className | string | ((state: MenuRadioItemState) => string | undefined) | undefinedstring | ((state: MenuRadioItemState) => string | undefined) | undefined | — | CSS class applied to the element, or a function that returns a class based on the component's state. |
render | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn…React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, MenuRadioItemState> | undefined | — | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
style | React.CSSProperties | ((state: MenuRadioItemState) => React.CSSProperties | undefined) | u…React.CSSProperties | ((state: MenuRadioItemState) => React.CSSProperties | undefined) | undefined | — | Style applied to the element, or a function that returns a style object based on the component's state. |
inset | boolean | undefinedboolean | undefined | — | Configures inset; see the accepted type. |
MenubarSub
| Prop | Type | Default | Description |
|---|---|---|---|
onOpenChange | ((open: boolean, eventDetails: MenuPrimitive.SubmenuRoot.ChangeEventDetails) => void) | un…((open: boolean, eventDetails: MenuPrimitive.SubmenuRoot.ChangeEventDetails) => void) | undefined | — | Event handler called when the menu is opened or closed. |
closeParentOnEsc | boolean | undefinedboolean | undefined | false | When in a submenu, determines whether pressing the Escape key closes the entire menu, or only the current child menu. |
children | React.ReactNode | PayloadChildRenderFunction<unknown>React.ReactNode | PayloadChildRenderFunction<unknown> | — | The content of the popover. This can be a regular React node or a render function that receives the `payload` of the active trigger. |
disabled | boolean | undefinedboolean | undefined | false | Whether the component should ignore user interaction. |
actionsRef | React.RefObject<MenuRootActions | null> | undefinedReact.RefObject<MenuRootActions | null> | undefined | — | 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. |
handle | MenuPrimitive.Handle<unknown> | undefinedMenuPrimitive.Handle<unknown> | undefined | — | A handle to associate the menu with a trigger. If specified, allows external triggers to control the menu's open state. |
open | boolean | undefinedboolean | undefined | — | Whether the menu is currently open. |
defaultOpen | boolean | undefinedboolean | undefined | false | Whether the menu is initially open. To render a controlled menu, use the `open` prop instead. |
onOpenChangeComplete | ((open: boolean) => void) | undefined((open: boolean) => void) | undefined | — | Event handler called after any animations complete when the menu is closed. |
triggerId | string | null | undefinedstring | null | undefined | — | ID of the trigger that the popover is associated with. This is useful in conjunction with the `open` prop to create a controlled popover. There's no need to specify this prop when the popover is uncontrolled (that is, when the `open` prop is not set). |
defaultTriggerId | string | null | undefinedstring | null | undefined | — | ID of the trigger that the popover is associated with. This is useful in conjunction with the `defaultOpen` prop to create an initially open popover. |
orientation | MenuRootOrientation | undefinedMenuRootOrientation | undefined | 'vertical' | The visual orientation of the menu. Controls whether roving focus uses up/down or left/right arrow keys. |
highlightItemOnHover | boolean | undefinedboolean | undefined | true | Whether moving the pointer over items should highlight them. Disabling this prop allows CSS `:hover` to be differentiated from the `:focus` (`data-highlighted`) state. |
loopFocus | boolean | undefinedboolean | undefined | true | Whether to loop keyboard focus back to the first item when the end of the list is reached while using the arrow keys. |
MenubarSubTrigger
| Prop | Type | Default | Description |
|---|---|---|---|
onClick | ((event: BaseUIEvent<React.MouseEvent<HTMLDivElement, MouseEvent>>) => void) | undefined((event: BaseUIEvent<React.MouseEvent<HTMLDivElement, MouseEvent>>) => void) | undefined | — | Called when the element is activated. |
label | string | undefinedstring | undefined | — | Overrides the text label to use when the item is matched during keyboard text navigation. |
id | string | undefinedstring | undefined | — | Unique identifier used to associate labels and descriptions. |
disabled | boolean | undefinedboolean | undefined | false | Whether the component should ignore user interaction. |
delay | number | undefinednumber | undefined | 100 | How long to wait before the menu may be opened on hover. Specified in milliseconds. Requires the `openOnHover` prop. |
closeDelay | number | undefinednumber | undefined | 0 | How long to wait before closing the menu that was opened on hover. Specified in milliseconds. Requires the `openOnHover` prop. |
openOnHover | boolean | undefinedboolean | undefined | — | Whether the menu should also open when the trigger is hovered. |
nativeButton | boolean | undefinedboolean | undefined | false | Whether the component renders a native `<button>` element when replacing it via the `render` prop. Set to `true` if the rendered element is a native button. |
ref | React.Ref<HTMLDivElement> | undefinedReact.Ref<HTMLDivElement> | undefined | — | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). |
children | React.ReactNodeReact.ReactNode | — | Content rendered inside this component. |
onFocus | ((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined | — | Called when the control receives focus. |
onBlur | ((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined | — | Called when the control loses focus. |
onChange | ((event: BaseUIEvent<React.ChangeEvent<HTMLDivElement, Element>>) => void) | undefined((event: BaseUIEvent<React.ChangeEvent<HTMLDivElement, Element>>) => void) | undefined | — | Called when the underlying form control changes; inspect the event for its value. |
onKeyDown | ((event: BaseUIEvent<React.KeyboardEvent<HTMLDivElement>>) => void) | undefined((event: BaseUIEvent<React.KeyboardEvent<HTMLDivElement>>) => void) | undefined | — | Called when a key is pressed while this element is focused. |
className | string | ((state: MenuSubmenuTriggerState) => string | undefined) | undefinedstring | ((state: MenuSubmenuTriggerState) => string | undefined) | undefined | — | CSS class applied to the element, or a function that returns a class based on the component's state. |
render | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn…React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, MenuSubmenuTriggerState> | undefined | — | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
style | React.CSSProperties | ((state: MenuSubmenuTriggerState) => React.CSSProperties | undefined…React.CSSProperties | ((state: MenuSubmenuTriggerState) => React.CSSProperties | undefined) | undefined | — | Style applied to the element, or a function that returns a style object based on the component's state. |
inset | boolean | undefinedboolean | undefined | — | Configures inset; see the accepted type. |
MenubarSubContent
| Prop | Type | Default | Description |
|---|---|---|---|
children | React.ReactNodeReact.ReactNode | — | Content rendered inside this component. |
id | string | undefinedstring | undefined | — | Unique identifier used to associate labels and descriptions. |
finalFocus | boolean | React.RefObject<HTMLElement | null> | ((closeType: InteractionType) => boolean |…boolean | React.RefObject<HTMLElement | null> | ((closeType: InteractionType) => boolean | HTMLElement | null | void) | undefined | — | Determines the element to focus when the menu is closed. - `false`: Do not move focus. - `true`: Move focus based on the default behavior (trigger or previously focused element). - `RefObject`: Move focus to the ref element. - `function`: Called with the interaction type (`mouse`, `touch`, `pen`, or `keyboard`). Return an element to focus, `true` to use the default behavior, or `false`/`undefined` to do nothing. |
ref | React.Ref<HTMLDivElement> | undefinedReact.Ref<HTMLDivElement> | undefined | — | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). |
onFocus | ((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined | — | Called when the control receives focus. |
onBlur | ((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined((event: BaseUIEvent<React.FocusEvent<HTMLDivElement, Element>>) => void) | undefined | — | Called when the control loses focus. |
onChange | ((event: BaseUIEvent<React.ChangeEvent<HTMLDivElement, Element>>) => void) | undefined((event: BaseUIEvent<React.ChangeEvent<HTMLDivElement, Element>>) => void) | undefined | — | Called when the underlying form control changes; inspect the event for its value. |
onKeyDown | ((event: BaseUIEvent<React.KeyboardEvent<HTMLDivElement>>) => void) | undefined((event: BaseUIEvent<React.KeyboardEvent<HTMLDivElement>>) => void) | undefined | — | Called when a key is pressed while this element is focused. |
onClick | ((event: BaseUIEvent<React.MouseEvent<HTMLDivElement, MouseEvent>>) => void) | undefined((event: BaseUIEvent<React.MouseEvent<HTMLDivElement, MouseEvent>>) => void) | undefined | — | Called when the element is activated. |
className | string | ((state: MenuPopupState) => string | undefined) | undefinedstring | ((state: MenuPopupState) => string | undefined) | undefined | — | CSS class applied to the element, or a function that returns a class based on the component's state. |
render | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn…React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, MenuPopupState> | undefined | — | Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render. |
style | React.CSSProperties | ((state: MenuPopupState) => React.CSSProperties | undefined) | undef…React.CSSProperties | ((state: MenuPopupState) => React.CSSProperties | undefined) | undefined | — | Style applied to the element, or a function that returns a style object based on the component's state. |
align | Align | undefinedAlign | undefined | 'center' | How to align the popup relative to the specified side. |
side | Side | undefinedSide | undefined | 'bottom' | Which side of the anchor element to align the popup against. May automatically change to avoid collisions. |
sideOffset | number | OffsetFunction | undefinednumber | OffsetFunction | undefined | 0 | Distance between the anchor and the popup in pixels. Also accepts a function that returns the distance to read the dimensions of the anchor and positioner elements, along with its side and alignment. The function takes a `data` object parameter with the following properties: - `data.anchor`: the dimensions of the anchor element with properties `width` and `height`. - `data.positioner`: the dimensions of the positioner element with properties `width` and `height`. - `data.side`: which side of the anchor element the positioner is aligned against. - `data.align`: how the positioner is aligned relative to the specified side. |
alignOffset | number | OffsetFunction | undefinednumber | OffsetFunction | undefined | 0 | Additional offset along the alignment axis in pixels. Also accepts a function that returns the offset to read the dimensions of the anchor and positioner elements, along with its side and alignment. The function takes a `data` object parameter with the following properties: - `data.anchor`: the dimensions of the anchor element with properties `width` and `height`. - `data.positioner`: the dimensions of the positioner element with properties `width` and `height`. - `data.side`: which side of the anchor element the positioner is aligned against. - `data.align`: how the positioner is aligned relative to the specified side. |
Usage notes
Each menu has its own trigger and content. Use command names that make sense outside their visual grouping.