Components

Menu

A list of actions in a dropdown, enhanced with keyboard navigation.

Anatomy#

Import the component and assemble its parts:

Anatomytsx
import { Menu } from '@egoist/solid-base/menu';

<Menu.FilterProvider>
  <Menu.Root>
    <Menu.Trigger />
    <Menu.Portal>
      <Menu.Backdrop />
      <Menu.Positioner>
        <Menu.Popup>
          <Menu.Arrow />
          <Menu.Input />
          <Menu.Clear />
          <Menu.Empty />

          <Menu.List>
            <Menu.Item />
            <Menu.LinkItem />
            <Menu.Separator />

            <Menu.SubmenuRoot>
              <Menu.SubmenuTrigger />
            </Menu.SubmenuRoot>

            <Menu.Group>
              <Menu.GroupLabel />
            </Menu.Group>

            <Menu.RadioGroup>
              <Menu.GroupLabel />
              <Menu.RadioItem>
                <Menu.RadioItemIndicator />
              </Menu.RadioItem>
            </Menu.RadioGroup>

            <Menu.CheckboxItem>
              <Menu.CheckboxItemIndicator />
            </Menu.CheckboxItem>
          </Menu.List>

          <Menu.Viewport />
        </Menu.Popup>
      </Menu.Positioner>
    </Menu.Portal>
  </Menu.Root>
</Menu.FilterProvider>;

Examples#

Open on hover#

To create a menu that opens on hover, add the openOnHover prop to <Menu.Trigger>. You can additionally configure how quickly the menu opens on hover using the delay prop.

Checkbox items#

Use the <Menu.CheckboxItem> part to create a menu item that can toggle a setting on or off.

Radio items#

Use the <Menu.RadioGroup> and <Menu.RadioItem> parts to create menu items that work like radio buttons.

Close on click#

Use the closeOnClick prop to change whether the menu closes when an item is clicked.

Control whether the menu closes on clicktsx
// Close the menu when a checkbox item is clicked
<Menu.CheckboxItem closeOnClick />

// Keep the menu open when an item is clicked
<Menu.Item closeOnClick={false} />

Group labels#

Use the <Menu.GroupLabel> part to add a label to a <Menu.Group> or <Menu.RadioGroup>.

Nested menu#

To create a submenu, nest another menu inside the parent menu with <Menu.SubmenuRoot>. Use the <Menu.SubmenuTrigger> part for the menu item that opens the nested menu.

Adding a submenutsx
<Menu.Root>
  <Menu.Trigger />
  <Menu.Portal>
    <Menu.Positioner>
      <Menu.Popup>
        <Menu.Item />

        {/* Submenu */}
        <Menu.SubmenuRoot>
          <Menu.SubmenuTrigger />
          <Menu.Portal>
            <Menu.Positioner>
              <Menu.Popup>{/* Submenu items */}</Menu.Popup>
            </Menu.Positioner>
          </Menu.Portal>
        </Menu.SubmenuRoot>
      </Menu.Popup>
    </Menu.Positioner>
  </Menu.Portal>
</Menu.Root>

Use the <Menu.LinkItem> part to create a link.

A menu item that opens a linktsx
<Menu.LinkItem href="/projects">Go to Projects</Menu.LinkItem>

To navigate with a client-side router, render the router's link component (see Composition):

Using a router linktsx
import { A } from '@solidjs/router';

<Menu.LinkItem render={(props) => <A href="/projects" {...props} />}>Go to Projects</Menu.LinkItem>;

Detached triggers#

A menu can be opened by a trigger that lives either inside or outside the <Menu.Root>. Keep the trigger inside <Menu.Root> for simple, tightly coupled layouts like the hero demo at the top of this page. When the trigger and menu content need to live in different parts of the tree (for example, in a card list that controls a menu rendered near the document root), create a handle with Menu.createHandle() and pass it to both the trigger and the root.

Note that only top-level menus can have detached triggers. Submenus must have their triggers defined within the SubmenuRoot part.

The imperative methods on the handle, such as open() and close(), require a <Menu.Root> using the same handle to be mounted. Calls made while no root is attached to the handle — before one mounts, or after it unmounts — are ignored. Each time a root mounts, it starts from fresh state: a call made while no root was attached is not replayed, and no open state carries over from a previous mount.

Detached triggerstsx
const demoMenu = Menu.createHandle();

<Menu.Trigger handle={demoMenu}>Actions</Menu.Trigger>

<Menu.Root handle={demoMenu}>
  <Menu.Portal>
    <Menu.Positioner>
      <Menu.Popup>
        <Menu.Item>Edit</Menu.Item>
        <Menu.Item>Share</Menu.Item>
      </Menu.Popup>
    </Menu.Positioner>
  </Menu.Portal>
</Menu.Root>

Multiple triggers#

One menu can be opened by several triggers. You can either render multiple <Menu.Trigger> components inside the same <Menu.Root>, or attach several detached triggers to the same handle.

Multiple triggers within the Root parttsx
<Menu.Root>
  <Menu.Trigger>Row actions</Menu.Trigger>
  <Menu.Trigger>Quick actions</Menu.Trigger>
  {/* Rest of the menu */}
</Menu.Root>
Multiple detached triggerstsx
const projectMenu = Menu.createHandle();

<Menu.Trigger handle={projectMenu}>Row actions</Menu.Trigger>
<Menu.Trigger handle={projectMenu}>Quick actions</Menu.Trigger>

<Menu.Root handle={projectMenu}>
  {/* Rest of the menu */}
</Menu.Root>

Menus can render different content depending on which trigger opened them. Pass a payload prop to each <Menu.Trigger> and read it via a function child on <Menu.Root>. Provide a type argument to createHandle() to strongly type the payload.

Detached triggers with payloadtsx
const menus = {
  file: ['New', 'Open', 'Save'],
  edit: ['Undo', 'Redo', 'Cut', 'Copy', 'Paste'],
};

const demoMenu = Menu.createHandle<{ items: string[] }>();

<Menu.Trigger handle={demoMenu} payload={{ items: menus.file }}>
  File
</Menu.Trigger>

<Menu.Trigger handle={demoMenu} payload={{ items: menus.edit }}>
  Edit
</Menu.Trigger>

<Menu.Root handle={demoMenu}>
  {(menu) => (
    <Menu.Portal>
      <Menu.Positioner>
        <Menu.Popup>
          <Menu.Viewport>
            <For each={menu.payload?.items ?? []}>
              {(item) => <Menu.Item>{item}</Menu.Item>}
            </For>
          </Menu.Viewport>
        </Menu.Popup>
      </Menu.Positioner>
    </Menu.Portal>
  )}
</Menu.Root>

Controlled mode with multiple triggers#

Control a menu's open state externally with the open and onOpenChange props on <Menu.Root>. When more than one trigger can open the menu, track the active trigger with the triggerId prop on <Menu.Root> and matching id props on each <Menu.Trigger>. The onOpenChange callback receives eventDetails, which includes the DOM element that initiated the change, so you can update your triggerId state when the user activates a different trigger.

Arrow#

Use the <Menu.Arrow> part inside the popup to visually connect the menu to its trigger.

Animating the Menu#

When one menu is opened by multiple detached triggers, you can animate the menu as it moves between triggers. This includes animating position, size, and content.

Position and size

To animate the menu's position, apply CSS transitions to the left, right, top, and bottom properties of the Positioner part. To animate its size, transition the width and height of the Popup part.

Content

The menu also supports content transitions. This is useful when different triggers display different content within the same menu.

To enable content animations, wrap the menu content in the <Menu.Viewport> part. This part renders a div with data-activation-direction, containing up to two space-separated tokens — a horizontal (left or right) and a vertical (up or down) value — so you can make direction-aware animations.

Inside <Menu.Viewport>, content is wrapped in divs with transition data attributes:

  • data-current: The currently visible content when no transitions are present or the incoming content.
  • data-previous: The outgoing content during a transition.

The Viewport is optional — reach for it only when a single popup is opened by multiple triggers, its content differs per trigger, and the switch between them is animated. When used, set width: var(--positioner-width) and height: var(--positioner-height) on the Positioner so its box is frozen to the measured size during the transition; otherwise content-driven resizing can make the popup thrash or flip to another side.

Filtering#

Wrap <Menu.Root> in <Menu.FilterProvider>, add <Menu.Input> to the popup, and put the items inside <Menu.List>.

Filterable menutsx
<Menu.FilterProvider>
  <Menu.Root>
    <Menu.Trigger>Actions</Menu.Trigger>
    <Menu.Portal>
      <Menu.Positioner>
        <Menu.Popup>
          <Menu.Input aria-label="Filter actions" />
          <Menu.Clear>Clear</Menu.Clear>
          <Menu.Empty>No results.</Menu.Empty>
          <Menu.List>
            <Menu.Item>Rename</Menu.Item>
            <Menu.Item>Delete</Menu.Item>
          </Menu.List>
        </Menu.Popup>
      </Menu.Positioner>
    </Menu.Portal>
  </Menu.Root>
</Menu.FilterProvider>

Label the input with aria-label, aria-labelledby, or a visible <label>. Type to narrow the actions, then use the arrow keys to move through matching items.

Matching items

Items match their text by default. Use label to override it.

Labelstsx
<Menu.Item label="Move to folder">Move</Menu.Item>

Groups with no matching items get the hidden attribute and stay mounted. If your styles set display on a group, add a [hidden] rule so it still hides.

Hiding styled groupscss
.Group {
  display: flex;
}

.Group[hidden] {
  display: none;
}

<Menu.Empty> appears when no items match.

By default, an item matches when its text contains the query, ignoring case, accents, and punctuation. Use filter to replace the matching. It receives each item's text and the trimmed query, and keeps the item when it returns true. Menu.useFilter provides the same locale-aware comparisons.

Custom matchingtsx
const { startsWith } = Menu.useFilter();

<Menu.FilterProvider filter={startsWith}>
  <Menu.Root>{/* menu parts */}</Menu.Root>
</Menu.FilterProvider>;

For external filtering, pass filter={null} and render the results yourself, omitting empty groups.

External filteringtsx
const { contains } = Menu.useFilter();
const [query, setQuery] = createSignal('');
const results = () => actions.filter((action) => contains(action.label, query()));

<Menu.FilterProvider filter={null} value={query()} onValueChange={(value) => setQuery(value)}>
  <Menu.Root>{/* render `results()` */}</Menu.Root>
</Menu.FilterProvider>;

Controlling the query

value and onValueChange on <Menu.FilterProvider> control the query. It resets to an empty string when the menu closes, reported with the 'popup-close' reason. Cancel that change to keep the query.

Highlighting

Use autoHighlight to highlight the first match while filtering, or autoHighlight="always" to highlight it even when the query is empty. The highlighted item has the data-highlighted attribute, and onItemHighlighted on <Menu.Root> reports each change.

Focus and keyboard

Opening the menu with a click or the keyboard focuses the input. Opening it on hover, touch, or with a pen does not, so the on-screen keyboard stays hidden. The arrow keys move the highlight while the input keeps focus. Tab closes the menu, and Shift+Tab returns focus to the trigger. The popup is a dialog that holds the searchbox input and the menu list.

Wrap each searchable <Menu.SubmenuRoot> in its own <Menu.FilterProvider>. Submenus without a provider remain unfiltered.

Filtering with detached triggers

Use the same Menu.createHandle() handle for the root and its detached trigger:

Detached triggertsx
const handle = Menu.createHandle();

<Menu.Trigger handle={handle}>Actions</Menu.Trigger>
<Menu.FilterProvider>
  <Menu.Root handle={handle}>{/* menu parts */}</Menu.Root>
</Menu.FilterProvider>

API reference#

<Menu.Root>

Groups all parts of the menu. Doesn't render its own HTML element.

PropTypeDefault
defaultOpenbooleanfalse

Whether the menu is initially open.

To render a controlled menu, use the open prop instead.

loopFocusbooleantrue

Whether to loop keyboard focus back to the first item when the end of the list is reached while using the arrow keys.

highlightItemOnHoverbooleantrue

Whether moving the pointer over items should highlight them. Disabling this prop allows CSS :hover to be differentiated from the :focus (data-highlighted) state.

modalbooleantrue

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.

On touch devices, a true modal blocks outside taps but leaves the page scrollable unless the popup spans nearly the full viewport width, matching native iOS behavior.

Nested menus ignore this prop, and menus opened by hover are never modal.

onOpenChange((open: boolean, eventDetails: MenuRoot.ChangeEventDetails) => void)—

Event handler called when the menu is opened or closed.

onOpenChangeComplete((open: boolean) => void)—

Event handler called after any animations complete when the menu is opened or closed.

onItemHighlighted| (( highlightedItem: HTMLElement, eventDetails: MenuRoot.HighlightEventDetails, ) => void)—

Callback fired when an item is highlighted or unhighlighted. Receives the highlighted item element (or undefined if no item is highlighted) and details containing the reason for the change, the event, and the item's text label. The reason can be: - 'keyboard': the highlight changed due to keyboard navigation. - 'pointer': the highlight changed due to pointer hovering. The event may be a MouseEvent rather than a PointerEvent. - 'none': the highlight changed for another reason, such as automatic highlighting while filtering, the item list changing, or the popup opening or closing.

openboolean—

Whether the menu is currently open.

orientationMenuRoot.Orientation'vertical'

The visual orientation of the menu. Controls whether roving focus uses up/down or left/right arrow keys.

disabledbooleanfalse

Whether the component should ignore user interaction.

closeParentOnEscbooleanfalse

When in a submenu, determines whether pressing the Escape key closes the entire menu, or only the current child menu.

actionsRefActionsRef<MenuRoot.Actions>—

A ref to imperative actions: a ref object ({ current: null }) or a callback receiving them. - unmount: Ends the closing phase of the menu after an externally controlled closing animation finishes. Call preventUnmountOnClose() in onOpenChange first, otherwise the menu completes closing on its own. Whether it leaves the DOM is decided by keepMounted on the portal. - close: Closes the menu imperatively when called.

triggerIdstring | null—

ID of the trigger that the menu is associated with. This is useful in conjunction with the open prop to create a controlled menu. There's no need to specify this prop when the menu is uncontrolled (that is, when the open prop is not set).

defaultTriggerIdstring | null—

ID of the trigger that the menu is associated with. This is useful in conjunction with the defaultOpen prop to create an initially open menu.

handleMenuHandle<Payload>—

A handle to associate the menu with a trigger. If specified, allows external triggers to control the menu's open state.

<Menu.Trigger>

A button that opens the menu. Renders a <button> element.

PropTypeDefault
disabledbooleanfalse

Whether the component should ignore user interaction.

handleMenuHandle<Payload>—

A handle to associate the trigger with a menu.

payloadPayload—

A payload to pass to the menu when it is opened.

idstring—

ID of the trigger. In addition to being forwarded to the rendered element, it is also used to specify the active trigger for the menu in controlled mode (with the MenuRoot triggerId prop).

delaynumber100

How long to wait before the menu may be opened on hover. Specified in milliseconds.

Requires the openOnHover prop.

closeDelaynumber0

How long to wait before closing the menu that was opened on hover. Specified in milliseconds.

Requires the openOnHover prop.

openOnHoverboolean—

Whether the menu should also open when the trigger is hovered.

nativeButtonbooleantrue

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>).

classstring | ClassValue | ((state: State) => ClassValue)—

CSS class applied to the element, or a function that returns a class based on the component's state.

styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—

Style applied to the element, or a function that returns a style based on the component's state.

renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—

Allows you to replace the component's HTML element with a different tag, or compose it with another component.

Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.

Data attributeDescription
data-disabled

Present when the trigger is disabled.

<Menu.Arrow>

Displays an element positioned against the menu anchor. Renders a <div> element.

PropTypeDefault
classstring | ClassValue | ((state: State) => ClassValue)—

CSS class applied to the element, or a function that returns a class based on the component's state.

styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—

Style applied to the element, or a function that returns a style based on the component's state.

renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—

Allows you to replace the component's HTML element with a different tag, or compose it with another component.

Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.

Data attributeDescription
data-uncentered

Present when the menu arrow is uncentered.

<Menu.Backdrop>

An overlay displayed beneath the menu popup. Renders a <div> element.

PropTypeDefault
classstring | ClassValue | ((state: State) => ClassValue)—

CSS class applied to the element, or a function that returns a class based on the component's state.

styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—

Style applied to the element, or a function that returns a style based on the component's state.

renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—

Allows you to replace the component's HTML element with a different tag, or compose it with another component.

Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.

<Menu.CheckboxItem>

A menu item that toggles a setting on or off. Renders a <div> element.

PropTypeDefault
checkedboolean—

Whether the checkbox item is currently ticked.

To render an uncontrolled checkbox item, use the defaultChecked prop instead.

defaultCheckedbooleanfalse

Whether the checkbox item is initially ticked.

To render a controlled checkbox item, use the checked prop instead.

onCheckedChange| (( checked: boolean, eventDetails: MenuCheckboxItem.ChangeEventDetails, ) => void)—

Event handler called when the checkbox item is ticked or unticked.

disabledbooleanfalse

Whether the component should ignore user interaction.

labelstring—

Overrides the text used for keyboard text navigation and filtering. Falls back to the rendered text when not provided.

closeOnClickbooleanfalse

Whether to close the menu when the item is clicked.

nativeButtonbooleanfalse

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.

classstring | ClassValue | ((state: State) => ClassValue)—

CSS class applied to the element, or a function that returns a class based on the component's state.

styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—

Style applied to the element, or a function that returns a style based on the component's state.

renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—

Allows you to replace the component's HTML element with a different tag, or compose it with another component.

Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.

Data attributeDescription
data-checked

Present when the menu checkbox item is checked.

data-unchecked

Present when the menu checkbox item is not checked.

data-disabled

Present when the menu checkbox item is disabled.

data-highlighted

Present when the menu checkbox item is highlighted.

<Menu.CheckboxItemIndicator>

Indicates whether the checkbox item is ticked. Renders a <span> element.

PropTypeDefault
keepMountedbooleanfalse

Whether to keep the HTML element in the DOM when the checkbox item is not checked.

classstring | ClassValue | ((state: State) => ClassValue)—

CSS class applied to the element, or a function that returns a class based on the component's state.

styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—

Style applied to the element, or a function that returns a style based on the component's state.

renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—

Allows you to replace the component's HTML element with a different tag, or compose it with another component.

Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.

Data attributeDescription
data-checked

Present when the menu checkbox item is checked.

data-unchecked

Present when the menu checkbox item is not checked.

data-highlighted

Present when the menu checkbox item is highlighted.

data-disabled

Present when the menu checkbox item is disabled.

<Menu.Group>

Groups related menu items with the corresponding label. Renders a <div> element.

PropTypeDefault
classstring | ClassValue | ((state: State) => ClassValue)—

CSS class applied to the element, or a function that returns a class based on the component's state.

styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—

Style applied to the element, or a function that returns a style based on the component's state.

renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—

Allows you to replace the component's HTML element with a different tag, or compose it with another component.

Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.

<Menu.GroupLabel>

An accessible label that is automatically associated with its parent group. Renders a <div> element.

PropTypeDefault
idstring—
classstring | ClassValue | ((state: State) => ClassValue)—

CSS class applied to the element, or a function that returns a class based on the component's state.

styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—

Style applied to the element, or a function that returns a style based on the component's state.

renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—

Allows you to replace the component's HTML element with a different tag, or compose it with another component.

Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.

<Menu.Item>

An individual interactive item in the menu. Renders a <div> element.

PropTypeDefault
disabledbooleanfalse

Whether the component should ignore user interaction.

labelstring—

Overrides the text used for keyboard text navigation and filtering. Falls back to the rendered text when not provided.

closeOnClickbooleantrue

Whether to close the menu when the item is clicked.

nativeButtonbooleanfalse

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.

classstring | ClassValue | ((state: State) => ClassValue)—

CSS class applied to the element, or a function that returns a class based on the component's state.

styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—

Style applied to the element, or a function that returns a style based on the component's state.

renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—

Allows you to replace the component's HTML element with a different tag, or compose it with another component.

Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.

Data attributeDescription
data-highlighted

Present when the menu item is highlighted.

data-disabled

Present when the menu item is disabled.

<Menu.LinkItem>

A link in the menu that can be used to navigate to a different page or section. Renders an <a> element.

PropTypeDefault
labelstring—

Overrides the text used for keyboard text navigation and filtering. Falls back to the rendered text when not provided.

closeOnClickbooleanfalse

Whether to close the menu when the item is clicked.

classstring | ClassValue | ((state: State) => ClassValue)—

CSS class applied to the element, or a function that returns a class based on the component's state.

styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—

Style applied to the element, or a function that returns a style based on the component's state.

renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—

Allows you to replace the component's HTML element with a different tag, or compose it with another component.

Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.

Data attributeDescription
data-highlighted

Present when the link is highlighted.

<Menu.Popup>

A container for the menu items. Renders a <div> element.

PropTypeDefault
finalFocusFocusTargetProp—

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). - An element or a ref object ({ current }): Move focus to that 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.

classstring | ClassValue | ((state: State) => ClassValue)—

CSS class applied to the element, or a function that returns a class based on the component's state.

styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—

Style applied to the element, or a function that returns a style based on the component's state.

renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—

Allows you to replace the component's HTML element with a different tag, or compose it with another component.

Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.

Data attributeDescription
data-nested

Present when the menu is a submenu.

data-instant

Present if animations should be instant.

<Menu.Portal>

A portal element that moves the popup to a different part of the DOM. By default, the portal element is appended to <body>. Renders a <div> element.

PropTypeDefault
keepMountedbooleanfalse

Whether to keep the portal mounted in the DOM while the popup is hidden.

containerPortalContainer—

A parent element to render the portal element into.

classstring | ClassValue | ((state: State) => ClassValue)—

CSS class applied to the element, or a function that returns a class based on the component's state.

styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—

Style applied to the element, or a function that returns a style based on the component's state.

renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—

Allows you to replace the component's HTML element with a different tag, or compose it with another component.

Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.

<Menu.Positioner>

Positions the menu popup against the trigger. Renders a <div> element.

PropTypeDefault
alignCreateAnchorPositioningSharedParameters['align']'center'

How to align the popup relative to the specified side.

Submenus and menubars default to 'start'.

sideCreateAnchorPositioningSharedParameters['side']'bottom'

Which side of the anchor element to align the popup against. May automatically change to avoid collisions.

Submenus and vertical menubars default to 'inline-end'.

anchor| Element | null | VirtualElement | RefObject<Element | null> | (() => Element | VirtualElement | null)—

An element to position the popup against. By default, the popup will be positioned against the trigger.

Accepts an element, a virtual element, a ref object, or a function (such as a signal accessor) that returns an element or a virtual element.

positionMethod'absolute' | 'fixed''absolute'

Determines which CSS position property to use.

sideOffsetnumber | OffsetFunction0

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.

alignOffsetnumber | OffsetFunction0

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.

collisionBoundaryBoundary'clipping-ancestors'

An element or a rectangle that delimits the area that the popup is confined to.

collisionPaddingPadding5

Additional space to maintain from the edge of the collision boundary.

stickybooleanfalse

Whether to maintain the popup in the viewport after the anchor element was scrolled out of view.

arrowPaddingnumber5

Minimum distance to maintain between the arrow and the edges of the popup.

Use it to prevent the arrow element from hanging out of the rounded corners of a popup.

disableAnchorTrackingbooleanfalse

Whether to disable the popup from tracking any layout shift of its positioning anchor.

collisionAvoidanceCollisionAvoidance—

Determines how to handle collisions when positioning the popup.

side controls overflow on the preferred placement axis (top/bottom or left/right): - 'flip': keep the requested side when it fits; otherwise try the opposite side (top and bottom, or left and right). - 'shift': never change side; keep the requested side and move the popup within the clipping boundary so it stays visible. - 'none': do not correct side-axis overflow.

align controls overflow on the alignment axis (start/center/end): - 'flip': keep side, but swap start and end when the requested alignment overflows. - 'shift': keep side and requested alignment, then nudge the popup along the alignment axis to fit. - 'none': do not correct alignment-axis overflow.

fallbackAxisSide controls fallback behavior on the perpendicular axis when the preferred axis cannot fit: - 'start': allow perpendicular fallback and try the logical start side first (top before bottom, or left before right in LTR). - 'end': allow perpendicular fallback and try the logical end side first (bottom before top, or right before left in LTR). - 'none': do not fallback to the perpendicular axis.

When side is 'shift', explicitly setting align only supports 'shift' or 'none'. If align is omitted, it defaults to 'flip'.

classstring | ClassValue | ((state: State) => ClassValue)—

CSS class applied to the element, or a function that returns a class based on the component's state.

styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—

Style applied to the element, or a function that returns a style based on the component's state.

renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—

Allows you to replace the component's HTML element with a different tag, or compose it with another component.

Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.

Data attributeDescription
data-nested

Present when the menu is a submenu.

CSS variableDescription
--available-width

The available width between the anchor and the edge of the viewport.

--available-height

The available height between the anchor and the edge of the viewport.

--anchor-width

The anchor's width.

--anchor-height

The anchor's height.

--transform-origin

The coordinates that this element is anchored to. Used for animations and transitions.

--positioner-width

The width of the menu's positioner. It is important to set width to this value when using CSS to animate size changes.

--positioner-height

The height of the menu's positioner. It is important to set height to this value when using CSS to animate size changes.

<Menu.RadioGroup>

Groups related radio items. Renders a <div> element.

PropTypeDefault
valueValue—

The controlled value of the radio item that should be currently selected.

To render an uncontrolled radio group, use the defaultValue prop instead.

defaultValueValue—

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: Value, eventDetails: MenuRadioGroup.ChangeEventDetails) => void)—

Function called when the selected value changes.

disabledbooleanfalse

Whether the component should ignore user interaction.

classstring | ClassValue | ((state: State) => ClassValue)—

CSS class applied to the element, or a function that returns a class based on the component's state.

styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—

Style applied to the element, or a function that returns a style based on the component's state.

renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—

Allows you to replace the component's HTML element with a different tag, or compose it with another component.

Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.

Data attributeDescription
data-disabled

Present when the menu radio group is disabled.

<Menu.RadioItem>

A menu item that works like a radio button in a given group. Renders a <div> element.

PropTypeDefault
value*any—

Value of the radio item. This is the value that will be set in the MenuRadioGroup when the item is selected.

disabledbooleanfalse

Whether the component should ignore user interaction.

labelstring—

Overrides the text used for keyboard text navigation and filtering. Falls back to the rendered text when not provided.

closeOnClickbooleanfalse

Whether to close the menu when the item is clicked.

nativeButtonbooleanfalse

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.

classstring | ClassValue | ((state: State) => ClassValue)—

CSS class applied to the element, or a function that returns a class based on the component's state.

styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—

Style applied to the element, or a function that returns a style based on the component's state.

renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—

Allows you to replace the component's HTML element with a different tag, or compose it with another component.

Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.

Data attributeDescription
data-checked

Present when the menu radio item is selected.

data-unchecked

Present when the menu radio item is not selected.

data-disabled

Present when the menu radio item is disabled.

data-highlighted

Present when the menu radio item is highlighted.

<Menu.RadioItemIndicator>

Indicates whether the radio item is selected. Renders a <span> element.

PropTypeDefault
keepMountedbooleanfalse

Whether to keep the HTML element in the DOM when the radio item is not selected.

classstring | ClassValue | ((state: State) => ClassValue)—

CSS class applied to the element, or a function that returns a class based on the component's state.

styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—

Style applied to the element, or a function that returns a style based on the component's state.

renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—

Allows you to replace the component's HTML element with a different tag, or compose it with another component.

Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.

Data attributeDescription
data-checked

Present when the menu radio item is selected.

data-unchecked

Present when the menu radio item is not selected.

data-highlighted

Present when the menu radio item is highlighted.

data-disabled

Present when the menu radio item is disabled.

<Menu.SubmenuRoot>

Groups all parts of a submenu. Doesn't render its own HTML element.

PropTypeDefault
onOpenChange| ((open: boolean, eventDetails: MenuSubmenuRoot.ChangeEventDetails) => void)—

Event handler called when the menu is opened or closed.

closeParentOnEscbooleanfalse

When in a submenu, determines whether pressing the Escape key closes the entire menu, or only the current child menu.

disabledbooleanfalse

Whether the component should ignore user interaction.

highlightItemOnHoverbooleantrue

Whether moving the pointer over items should highlight them. Disabling this prop allows CSS :hover to be differentiated from the :focus (data-highlighted) state.

actionsRefActionsRef<MenuRoot.Actions>—

A ref to imperative actions: a ref object ({ current: null }) or a callback receiving them. - unmount: Ends the closing phase of the menu after an externally controlled closing animation finishes. Call preventUnmountOnClose() in onOpenChange first, otherwise the menu completes closing on its own. Whether it leaves the DOM is decided by keepMounted on the portal. - close: Closes the menu imperatively when called.

defaultOpenbooleanfalse

Whether the menu is initially open.

To render a controlled menu, use the open prop instead.

openboolean—

Whether the menu is currently open.

onOpenChangeComplete((open: boolean) => void)—

Event handler called after any animations complete when the menu is opened or closed.

loopFocusbooleantrue

Whether to loop keyboard focus back to the first item when the end of the list is reached while using the arrow keys.

onItemHighlighted| (( highlightedItem: HTMLElement, eventDetails: MenuRoot.HighlightEventDetails, ) => void)—

Callback fired when an item is highlighted or unhighlighted. Receives the highlighted item element (or undefined if no item is highlighted) and details containing the reason for the change, the event, and the item's text label. The reason can be: - 'keyboard': the highlight changed due to keyboard navigation. - 'pointer': the highlight changed due to pointer hovering. The event may be a MouseEvent rather than a PointerEvent. - 'none': the highlight changed for another reason, such as automatic highlighting while filtering, the item list changing, or the popup opening or closing.

orientationMenuRoot.Orientation'vertical'

The visual orientation of the menu. Controls whether roving focus uses up/down or left/right arrow keys.

<Menu.Viewport>

A viewport for displaying content transitions. This component is only required if one popup can be opened by multiple triggers, its content changes based on the trigger, and switching between them is animated. Renders a <div> element.

PropTypeDefault
classstring | ClassValue | ((state: State) => ClassValue)—

CSS class applied to the element, or a function that returns a class based on the component's state.

styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—

Style applied to the element, or a function that returns a style based on the component's state.

renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—

Allows you to replace the component's HTML element with a different tag, or compose it with another component.

Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.

Data attributeDescription
data-current

Applied to the direct child of the viewport when no transitions are present or the new content when it's entering.

data-previous

Applied to the direct child of the viewport that contains the exiting content when transitions are present.

data-activation-direction

Indicates the direction from which the popup was activated. This can be used to create directional animations based on how the popup was triggered. Contains space-separated values for both horizontal and vertical axes.

data-transitioning

Indicates that the viewport is currently transitioning between old and new content.

data-instant

Present if animations should be instant.

CSS variableDescription
--popup-width

The width of the parent popup. This variable is placed on the 'previous' container and stores the width of the popup when the previous content was rendered. It can be used to freeze the dimensions of the popup when animating between different content.

--popup-height

The height of the parent popup. This variable is placed on the 'previous' container and stores the height of the popup when the previous content was rendered. It can be used to freeze the dimensions of the popup when animating between different content.

<Menu.Separator>

A separator element accessible to screen readers. Renders a <div> element.

PropTypeDefault
orientationOrientation'horizontal'

The orientation of the separator.

classstring | ClassValue | ((state: State) => ClassValue)—

CSS class applied to the element, or a function that returns a class based on the component's state.

styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—

Style applied to the element, or a function that returns a style based on the component's state.

renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—

Allows you to replace the component's HTML element with a different tag, or compose it with another component.

Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.

<Menu.SubmenuTrigger>

A menu item that opens a submenu. Renders a <div> element.

PropTypeDefault
labelstring—

Overrides the text used for keyboard text navigation and filtering. Falls back to the rendered text when not provided.

disabledbooleanfalse

Whether the component should ignore user interaction.

delaynumber100

How long to wait before the menu may be opened on hover. Specified in milliseconds.

Requires the openOnHover prop.

closeDelaynumber0

How long to wait before closing the menu that was opened on hover. Specified in milliseconds.

Requires the openOnHover prop.

openOnHoverbooleantrue

Whether the menu should also open when the trigger is hovered.

nativeButtonbooleanfalse

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.

classstring | ClassValue | ((state: State) => ClassValue)—

CSS class applied to the element, or a function that returns a class based on the component's state.

styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—

Style applied to the element, or a function that returns a style based on the component's state.

renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—

Allows you to replace the component's HTML element with a different tag, or compose it with another component.

Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.

Data attributeDescription
data-highlighted

Present when the submenu trigger is highlighted.

data-disabled

Present when the submenu trigger is disabled.

<Menu.FilterProvider>

Enables filtering for the menu or submenu it wraps. Add Menu.Input to the popup and place its items in Menu.List. Wrap each searchable submenu in its own provider. Doesn't render its own HTML element.

PropTypeDefault
filter((text: string, query: string) => boolean) | null—

Filter function used to match items against the query. Receives each item's label (or its rendered text) and the trimmed query, and keeps the item when it returns true. By default, items match when they contain the query, ignoring case, accents, and punctuation. Pass null when rendering filtered items yourself.

autoHighlightboolean | 'always'false

Whether filtering highlights the first matching item automatically. - true: highlight it while the query is not empty. - 'always': highlight it even when the query is empty.

Opening the menu from the keyboard highlights the first item either way, and the arrow keys can move the highlight to another item. With either value, the arrow keys wrap within the list rather than returning to the input, and with 'always' a pointer highlight stays when the pointer leaves.

localeIntl.LocalesArgument—

The locale the default filter uses for string comparison. Defaults to the user's runtime locale.

defaultValuestring—

The uncontrolled filter query when the menu is initially rendered. To render a controlled query, use the value prop instead.

valuestring—

The filter query. Use when controlled. When the popup closes, onValueChange is called with an empty query. The controlled value changes only when the consumer updates this prop.

onValueChange((value: string, eventDetails: MenuFilterProvider.ChangeEventDetails) => void)—

Event handler called when the filter query changes.

<Menu.Input>

A search field that filters the menu items. Requires the menu to be wrapped in Menu.FilterProvider. Renders an <input> element.

PropTypeDefault
classstring | ClassValue | ((state: State) => ClassValue)—

CSS class applied to the element, or a function that returns a class based on the component's state.

styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—

Style applied to the element, or a function that returns a style based on the component's state.

renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—

Allows you to replace the component's HTML element with a different tag, or compose it with another component.

Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.

Data attributeDescription
data-highlighted

Present while the input shows its focus ring. Cleared when keyboard navigation highlights an item.

<Menu.List>

Groups menu items so other content, such as a filter input, can share the popup. Renders a <div> element.

PropTypeDefault
classstring | ClassValue | ((state: State) => ClassValue)—

CSS class applied to the element, or a function that returns a class based on the component's state.

styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—

Style applied to the element, or a function that returns a style based on the component's state.

renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—

Allows you to replace the component's HTML element with a different tag, or compose it with another component.

Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.

<Menu.Clear>

A button that clears the input text. Requires the menu to be wrapped in Menu.FilterProvider. Renders a <button> element when the input has text.

PropTypeDefault
disabledbooleanfalse

Whether the component should ignore user interaction.

nativeButtonbooleantrue

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>).

classstring | ClassValue | ((state: State) => ClassValue)—

CSS class applied to the element, or a function that returns a class based on the component's state.

styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—

Style applied to the element, or a function that returns a style based on the component's state.

renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—

Allows you to replace the component's HTML element with a different tag, or compose it with another component.

Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.

Data attributeDescription
data-disabled

Present when the button is disabled.

<Menu.Empty>

A message shown when the menu has no matching items. Requires the menu to be wrapped in Menu.FilterProvider. Renders a <div> element.

PropTypeDefault
classstring | ClassValue | ((state: State) => ClassValue)—

CSS class applied to the element, or a function that returns a class based on the component's state.

styleJSX.CSSProperties | string | ((state: State) => JSX.CSSProperties | string)—

Style applied to the element, or a function that returns a style based on the component's state.

renderkeyof JSX.IntrinsicElements | ((props: HTMLProps, state: State) => JSX.Element)—

Allows you to replace the component's HTML element with a different tag, or compose it with another component.

Accepts a tag name, or a function that receives the props to spread and the component's state, and returns the element to render.

useFilter#

When filtering items yourself, Menu.useFilter matches text according to the user's locale.

Signaturets
function useFilter(options?: Intl.CollatorOptions & { locale?: Intl.LocalesArgument }): {
  contains: (item: Item, query: string, itemToString?: (item: Item) => string) => boolean;
  startsWith: (item: Item, query: string, itemToString?: (item: Item) => string) => boolean;
  endsWith: (item: Item, query: string, itemToString?: (item: Item) => string) => boolean;
};

The collator defaults to usage: 'search', sensitivity: 'base' and ignorePunctuation: true.

createHandle#

Creates a handle that connects a <Menu.Root> with detached <Menu.Trigger> components. The optional type argument types the triggers' payload.

Signaturets
function createHandle<Payload>(): Menu.Handle<Payload>;

Handle#

Member Description
open(triggerId) Opens the menu and associates it with the trigger with the given id. The trigger must be a Menu.Trigger with this handle.
close() Closes the menu.
isOpen Whether the menu is open. false while no root is attached. Tracked when read in a reactive scope.

Call open() and close() from event handlers or effects, not while rendering.