Menu

A list of actions and settings that opens from a button.

Items can carry a shortcut hint, toggle a setting, pick one of a group, or open a submenu. variant="destructive" marks an action that can’t be undone. The arrow keys move through the list, and typing jumps to an item.

Preview
basic.tsx
import { Button } from "~/components/ui/button"
import {
  Menu,
  MenuCheckboxItem,
  MenuContent,
  MenuGroup,
  MenuGroupLabel,
  MenuItem,
  MenuRadioGroup,
  MenuRadioItem,
  MenuSeparator,
  MenuSub,
  MenuSubContent,
  MenuSubTrigger,
  MenuTrigger,
} from "~/components/ui/menu"

export default function Example() {
  return (
    <Menu>
      <MenuTrigger render={<Button variant="outline" />}>Edition</MenuTrigger>
      <MenuContent className="w-56">
        <MenuItem value="open" shortcut="mod+o">
          Open…
        </MenuItem>
        <MenuItem value="duplicate" shortcut="mod+d">
          Duplicate
        </MenuItem>
        <MenuSub>
          <MenuSubTrigger>Export as</MenuSubTrigger>
          <MenuSubContent>
            <MenuItem value="pdf">PDF</MenuItem>
            <MenuItem value="png">PNG pages</MenuItem>
          </MenuSubContent>
        </MenuSub>
        <MenuSeparator />
        <MenuGroup>
          <MenuGroupLabel>Show</MenuGroupLabel>
          <MenuCheckboxItem value="guides" defaultChecked>
            Guides
          </MenuCheckboxItem>
          <MenuCheckboxItem value="baselines">Baselines</MenuCheckboxItem>
        </MenuGroup>
        <MenuSeparator />
        <MenuRadioGroup defaultValue="35">
          <MenuGroupLabel>Zoom</MenuGroupLabel>
          <MenuRadioItem value="35">35%</MenuRadioItem>
          <MenuRadioItem value="100">100%</MenuRadioItem>
        </MenuRadioGroup>
        <MenuSeparator />
        <MenuItem value="delete" variant="destructive">
          Delete edition
        </MenuItem>
      </MenuContent>
    </Menu>
  )
}

Dependencies

What it's built from and what's built from it in Base, read from the imports in its source.

UsesKbdScroll AreaprimitiveTextprimitive
Used byMenubar
Packages @ui-sdk/core@0.1.0-beta.20@ui-sdk/react@0.1.0-beta.20lucide-react@1.73.0

Installation

Set the project up for Base once first, as Getting started shows. Then add it with the CLI, or by hand.

With the CLI

terminal
npx shadcn@latest add https://design.zepez.dev/r/base/menu.json

Manually

Install its packages:

terminal
npm install @ui-sdk/core@0.1.0-beta.20 @ui-sdk/react@0.1.0-beta.20 lucide-react@1.73.0

Add the components it uses first, listed under Dependencies.

Then copy the source:

components/ui/menu.tsx
import {
  Menu,
  MenuCheckboxItem as MenuCheckboxItemPrimitive,
  MenuContent as MenuContentPrimitive,
  MenuGroup,
  MenuGroupLabel as MenuGroupLabelPrimitive,
  MenuItem as MenuItemPrimitive,
  MenuItemIndicator,
  MenuRadioGroup,
  MenuRadioItem as MenuRadioItemPrimitive,
  MenuSeparator as MenuSeparatorPrimitive,
  MenuShortcut as MenuShortcutPrimitive,
  MenuSub,
  MenuSubContent as MenuSubContentPrimitive,
  MenuSubTrigger as MenuSubTriggerPrimitive,
  MenuTrigger,
} from "@ui-sdk/react/menu"
import { Check, ChevronRight } from "lucide-react"
import type * as React from "react"

import { Kbd } from "~/components/ui/kbd"
import { ScrollArea } from "~/components/ui/scroll-area"
import { textVariants } from "~/components/ui/text"
import { cnState } from "~/lib/utils"

const content = [
  textVariants({ size: "sm" }),
  "flex flex-col overflow-hidden m-0 max-h-(--available-height) min-w-36 rounded-lg border-0 bg-overlay text-overlay-foreground shadow-lg ring-1 ring-foreground/5 outline-none dark:ring-foreground/10",
  "origin-(--transform-origin) transition-[opacity,scale] duration-100 ease-out data-starting-style:scale-95 data-starting-style:opacity-0 data-ending-style:scale-95 data-ending-style:opacity-0 motion-reduce:transition-none",
].join(" ")

const item = [
  textVariants({ size: "sm" }),
  "relative flex min-h-7 w-full cursor-default items-center gap-sm rounded-md px-sm py-xs outline-none select-none",
  "data-highlighted:bg-accent data-highlighted:text-accent-foreground",
  "data-disabled:pointer-events-none data-disabled:opacity-50",
  "[&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
  "*:data-[slot=menu-shortcut]:ml-auto",
].join(" ")

const check = <Check className="size-3.5" />

/** The menu's popup. Placed below its trigger with a 4px gap unless you set `side` and `sideOffset`. */
function MenuContent({
  className,
  children,
  sideOffset = 4,
  ...props
}: React.ComponentProps<typeof MenuContentPrimitive>) {
  return (
    <MenuContentPrimitive
      sideOffset={sideOffset}
      className={cnState(content, className)}
      {...props}
    >
      {(state) => (
        <ScrollArea className="min-h-0">
          <div className="p-2xs">{typeof children === "function" ? children(state) : children}</div>
        </ScrollArea>
      )}
    </MenuContentPrimitive>
  )
}

/** A submenu's popup. */
function MenuSubContent({
  className,
  children,
  ...props
}: React.ComponentProps<typeof MenuSubContentPrimitive>) {
  return (
    <MenuSubContentPrimitive className={cnState(content, className)} {...props}>
      {(state) => (
        <ScrollArea className="min-h-0">
          <div className="p-2xs">{typeof children === "function" ? children(state) : children}</div>
        </ScrollArea>
      )}
    </MenuSubContentPrimitive>
  )
}

type MenuItemProps = React.ComponentProps<typeof MenuItemPrimitive> & {
  /** `destructive` marks an action that deletes or can't be undone. */
  variant?: "default" | "destructive"
}

/** An action. Its `shortcut` shows as a hint at the end of the row. */
function MenuItem({ variant = "default", className, ...props }: MenuItemProps) {
  return (
    <MenuItemPrimitive
      data-variant={variant}
      className={cnState(
        `${item} data-[variant=destructive]:text-destructive data-[variant=destructive]:data-highlighted:bg-destructive/10 data-[variant=destructive]:data-highlighted:text-destructive dark:data-[variant=destructive]:data-highlighted:bg-destructive/20`,
        className,
      )}
      {...props}
    />
  )
}

/** An item that turns a setting on and off, with its check mark built in. */
function MenuCheckboxItem({
  className,
  children,
  ...props
}: React.ComponentProps<typeof MenuCheckboxItemPrimitive>) {
  return (
    <MenuCheckboxItemPrimitive className={cnState(`${item} pl-2xl`, className)} {...props}>
      {(state) => (
        <>
          <MenuItemIndicator className="absolute left-2 inline-flex size-4 items-center justify-center">
            {check}
          </MenuItemIndicator>
          {typeof children === "function" ? children(state) : children}
        </>
      )}
    </MenuCheckboxItemPrimitive>
  )
}

/** One choice in a `MenuRadioGroup`, with its dot built in. */
function MenuRadioItem({
  className,
  children,
  ...props
}: React.ComponentProps<typeof MenuRadioItemPrimitive>) {
  return (
    <MenuRadioItemPrimitive className={cnState(`${item} pl-2xl`, className)} {...props}>
      {(state) => (
        <>
          <MenuItemIndicator className="absolute left-2 inline-flex size-4 items-center justify-center">
            <span className="size-1.5 rounded-full bg-current" />
          </MenuItemIndicator>
          {typeof children === "function" ? children(state) : children}
        </>
      )}
    </MenuRadioItemPrimitive>
  )
}

/** Opens a submenu, with its chevron built in. */
function MenuSubTrigger({
  className,
  children,
  ...props
}: React.ComponentProps<typeof MenuSubTriggerPrimitive>) {
  return (
    <MenuSubTriggerPrimitive
      className={cnState(`${item} data-open:bg-accent`, className)}
      {...props}
    >
      {(state) => (
        <>
          {typeof children === "function" ? children(state) : children}
          <ChevronRight className="ml-auto" />
        </>
      )}
    </MenuSubTriggerPrimitive>
  )
}

/** Names a group of items. */
function MenuGroupLabel({
  className,
  ...props
}: React.ComponentProps<typeof MenuGroupLabelPrimitive>) {
  return (
    <MenuGroupLabelPrimitive
      className={cnState(
        [textVariants({ size: "xs", weight: "medium", tone: "muted" }), "px-sm py-xs"],
        className,
      )}
      {...props}
    />
  )
}

/** A line between groups of items. */
function MenuSeparator({
  className,
  ...props
}: React.ComponentProps<typeof MenuSeparatorPrimitive>) {
  return (
    <MenuSeparatorPrimitive
      className={cnState("-mx-2xs my-2xs h-px bg-border", className)}
      {...props}
    />
  )
}

/** A keyboard hint at the end of an item, when you render one yourself. */
function MenuShortcut(props: React.ComponentProps<typeof MenuShortcutPrimitive>) {
  return <MenuShortcutPrimitive render={<Kbd className="ml-auto" />} {...props} />
}

export {
  Menu,
  MenuCheckboxItem,
  MenuContent,
  MenuGroup,
  MenuGroupLabel,
  MenuItem,
  MenuRadioGroup,
  MenuRadioItem,
  MenuSeparator,
  MenuShortcut,
  MenuSub,
  MenuSubContent,
  MenuSubTrigger,
  MenuTrigger,
}
export type { MenuItemProps }

API reference

Generated from Base's types. Props marked ours are added here; the rest come from the ui-sdk part it wraps. Every part also accepts its element's native attributes.

Menu

A list of actions and options, opened from a button or a right-click. Put its trigger and content inside.

container

Renders the popup into this element instead of in place, like a container inside a shadow root or an iframe. On web components, a CSS selector. Nested popups stay inside their parent.

Type Element | DocumentFragment | null

controller

Opens, closes and inspects the menu from anywhere, and connects triggers outside it. Create one with createMenuController().

Type PopupController<any, MenuOpenChangeReason, MenuOpenOptions, string, MenuPayloadChangeReason>

debug

Logs every state change with its reason to the console, in development builds.

Type boolean

defaultOpen

Whether the menu starts open, when uncontrolled.

Type boolean · Default false

delay

Milliseconds the pointer rests on a submenu trigger before its submenu opens.

Type number · Default 100

dismissible

Whether Escape, an outside press, focus or the window leaving, Android's back gesture and a sheet's swipe can close it. Triggers, Close parts and the controller always can. Pass false while it holds unsaved work, and ask in onDismissAttempt.

Type boolean · Default true

items

The menu as data. Renders the content for you, unless you place a content part of your own, and runs the items' shortcuts.

Type MenuData

itemShortcuts

Whether a data menu runs its items' shortcuts while closed.

Type boolean · Default true

loop

Whether arrow keys wrap from the last item to the first.

Type boolean · Default true

modal

"pointer": an outside press only closes the menu. true: also locks scroll, traps focus and makes the rest of the page inert. false: outside presses reach what they hit.

Type boolean | "pointer" · Default "pointer", or true while it presents as a sheet

onAction

Runs for every plain item, including items in submenus, with the item's value. Return a Promise to mark the item pending until it settles: it gets data-pending, aria-busy and aria-disabled, the menu stays open, and choosing it again waits. It closes once the Promise resolves, and a rejection keeps it open with the reason in the item's error state until the next try.

Type (value: string, details: MenuActionDetails) => unknown

onCheckedChange

Runs when any checkbox item in the menu or its submenus toggles, with the item's value in details.value. Made for data menus.

Type (checked: boolean, details: MenuCheckedChangeDetails) => void

onDismissAttempt

Runs when dismissible refused a dismissal made on purpose: Escape, an outside press, back or a swipe. Focus or the window leaving is refused without it. Ask "Discard changes?" here.

Type (details: { reason: "outside-press"; event?: MouseEvent; } | { reason: "escape-key"; event?: KeyboardEvent; } | { reason: "back"; event?: Event; } | { reason: "swipe"; event?: PointerEvent | TouchEvent; }) => void

onOpenChange

Runs when the menu wants to open or close. details.reason says why, and details.cancel() stops it.

Type (open: boolean, details: ChangeDetails<MenuOpenChangeReason>) => void

onOpenChangeComplete

Runs once the menu has finished opening or closing, after any animation.

Type (open: boolean) => void

onPayloadChange

Runs when the payload the content shows changes: a trigger or context area with another payload opens the menu, or takes the open menu over, which fires no onOpenChange, and so does a controller's open({ payload }) on the open menu. details.cancel() keeps the previous payload.

Type (payload: unknown, details: ChangeDetails<MenuPayloadChangeReason>) => void

onValueChange

Runs when any radio group in the menu or its submenus changes, with the group in details.group. Made for data menus.

Type (value: string, details: MenuValueChangeDetails) => void

open

Whether the menu is open. Pass it to control the menu.

Type boolean

pendingAnnouncement

What screen readers hear once an item has been pending for a second, so a slow action doesn't pass in silence. Set it in the page's language. An empty string says nothing.

Type string · Default "Loading"

presentation

How the menu presents. "sheet" slides it up from the bottom of the screen, where it can be swiped away and submenus open in its place, and "auto" does that on small touch screens. Decided each time it opens; the server renders "popover" for "auto". A context menu and a menu in a menubar are always popovers.

Type PresentationSetting<"popover"> · Default "popover"

MenuCheckboxItem

An item that turns a setting on and off, with its check mark built in.

checked

Whether the item is checked. Pass it to control the item.

Type boolean

children

Content, or a function of the part's state that returns it.

Type ReactNode | ((state: MenuCheckboxItemState) => ReactNode)

className

Class names, or a function of the part's state that returns them.

Type string | ((state: MenuCheckboxItemState) => string)

closeOnSelect

Whether toggling closes the menu.

Type boolean · Default false

defaultChecked

Whether the item starts checked, when uncontrolled.

Type boolean · Default false

disabled

Keeps the item focusable but stops it from toggling, as the menu pattern asks.

Type boolean

label

The text typeahead matches, when the content isn't plain text. It isn't the accessible name: use aria-label for that.

Type string

onCheckedChange

Runs when the item wants to toggle. details.reason says why, and details.cancel() stops it.

Type (checked: boolean, details: ChangeDetails<MenuCheckedChangeReason>) => void

render

Renders your own element: one that receives the part's props, or a function of the props and the state.

Type RenderProp<MenuCheckboxItemState>

style

Styles, or a function of the part's state that returns them.

Type CSSProperties | ((state: MenuCheckboxItemState) => CSSProperties)

value*

Identifies the item, in the menu's onCheckedChange.

Type string

MenuContent

The menu's popup. Placed below its trigger with a 4px gap unless you set side and sideOffset.

align

How the popup lines up with the anchor along that side. start and end follow the reading direction. How the menu lines up with the trigger along that side.

Type "center" | "start" | "end" · Default "start"

alignOffset

Shift along the anchor, in pixels. Shift along the trigger, in pixels. Submenus default to lining up their first item with the trigger.

Type number

anchor

Positions the popup against this instead of its trigger: an element, a CSS selector, a point like { x, y }, or anything with getBoundingClientRect(). It's read on every check, so it can move. A controller's open({ anchor }) wins for that open.

Type string | Anchor | null

arrowPadding

Space to keep between the arrow and the popup's corners, in pixels.

Type number · Default 6

children

Content, or a function of the part's state that returns it.

Type ReactNode | ((state: MenuContentState<unknown>) => ReactNode)

className

Class names, or a function of the part's state that returns them.

Type string | ((state: MenuContentState<unknown>) => string)

collisionPadding

Space to keep from the viewport edges, in pixels.

Type number · Default 8

container

Renders the popup into this element instead of in place, like a container inside a shadow root or an iframe. On web components, a CSS selector. Nested popups stay inside their parent.

Type Element | DocumentFragment | null

finalFocus

Where focus goes when the menu closes while focus is inside it. "trigger" returns it to the trigger and "none" leaves it. A CSS selector, an element or a function picks a specific element.

Type PopupFocusTarget · Default "trigger"

keepMounted

Whether the menu stays in the page, hidden, while closed. Its content keeps its state between opens.

Type boolean · Default false

render

Renders your own element: one that receives the part's props, or a function of the props and the state.

Type RenderProp<MenuContentState<unknown>>

side

Which side of the anchor the popup opens on. Flips to the other side when there isn't room. Which side of the trigger the menu opens on. Submenus open to the side, mirrored in right-to-left layouts.

Type "start" | "end" | "top" | "bottom" | "left" | "right" · Default "bottom"

sideOffset

Gap between the anchor and the popup, in pixels. Gap between the trigger and the menu, in pixels.

Type number · Default 4

style

Styles, or a function of the part's state that returns them.

Type CSSProperties | ((state: MenuContentState<unknown>) => CSSProperties)

MenuGroup

A group of items, named by its MenuGroupLabel.

children

Content, or a function of the part's state that returns it.

Type ReactNode | ((state: {}) => ReactNode)

className

Class names, or a function of the part's state that returns them.

Type string | ((state: {}) => string)

render

Renders your own element: one that receives the part's props, or a function of the props and the state.

Type RenderProp<{}>

style

Styles, or a function of the part's state that returns them.

Type CSSProperties | ((state: {}) => CSSProperties)

MenuGroupLabel

Names a group of items.

children

Content, or a function of the part's state that returns it.

Type ReactNode | ((state: {}) => ReactNode)

className

Class names, or a function of the part's state that returns them.

Type string | ((state: {}) => string)

render

Renders your own element: one that receives the part's props, or a function of the props and the state.

Type RenderProp<{}>

style

Styles, or a function of the part's state that returns them.

Type CSSProperties | ((state: {}) => CSSProperties)

MenuItem

An action. Its shortcut shows as a hint at the end of the row.

variantours

destructive marks an action that deletes or can't be undone.

Type "default" | "destructive" · Default default

children

Content, or a function of the part's state that returns it.

Type ReactNode | ((state: MenuItemState) => ReactNode)

className

Class names, or a function of the part's state that returns them.

Type string | ((state: MenuItemState) => string)

closeOnSelect

Whether running the item closes the menu.

Type boolean · Default true

destructive

Styles the item as dangerous, like Delete. Sets data-destructive.

Type boolean

disabled

Keeps the item focusable but stops it from running, as the menu pattern asks. Sets data-disabled and aria-disabled.

Type boolean

label

The text typeahead matches, when the content isn't plain text. It isn't the accessible name: use aria-label for that.

Type string

onSelect

Runs when the item is selected, by pointer or keyboard, with the event that selected it, or a new select Event when no DOM event did. Call event.preventDefault() to keep the menu open and skip onAction. Return a Promise to mark the item pending until it settles, like onAction.

Type (event: Event) => unknown

render

Renders your own element: one that receives the part's props, or a function of the props and the state.

Type RenderProp<MenuItemState>

shortcut

A keyboard shortcut like "mod+n". Shows ⌘N on Apple platforms and Ctrl+N elsewhere, and sets aria-keyshortcuts.

Type string

style

Styles, or a function of the part's state that returns them.

Type CSSProperties | ((state: MenuItemState) => CSSProperties)

value

Passed to onAction when the item runs.

Type string

MenuRadioGroup

Radio items that share one value. T is inferred from value, defaultValue or onValueChange.

children

Content, or a function of the part's state that returns it.

Type ReactNode | ((state: MenuRadioGroupState) => ReactNode)

className

Class names, or a function of the part's state that returns them.

Type string | ((state: MenuRadioGroupState) => string)

defaultValue

The value selected at first, when uncontrolled.

Type string | null

name

Identifies the group in the menu's onValueChange. Defaults to a generated id, and the group then keeps its choice by its place among the menu's groups. Give a group that's shown only some of the time a name, so it keeps its own.

Type string

onValueChange

Runs when the selection wants to change. details.reason says why, and details.cancel() stops it.

Type (value: T, details: ChangeDetails<MenuValueChangeReason>) => void

render

Renders your own element: one that receives the part's props, or a function of the props and the state.

Type RenderProp<MenuRadioGroupState>

style

Styles, or a function of the part's state that returns them.

Type CSSProperties | ((state: MenuRadioGroupState) => CSSProperties)

value

The selected value. Pass it to control the group. null selects nothing.

Type string | null

MenuRadioItem

One choice in a MenuRadioGroup, with its dot built in.

children

Content, or a function of the part's state that returns it.

Type ReactNode | ((state: MenuRadioItemState) => ReactNode)

className

Class names, or a function of the part's state that returns them.

Type string | ((state: MenuRadioItemState) => string)

closeOnSelect

Whether choosing the item closes the menu.

Type boolean · Default false

disabled

Keeps the item focusable but stops it from being chosen, as the menu pattern asks.

Type boolean

label

The text typeahead matches, when the content isn't plain text. It isn't the accessible name: use aria-label for that.

Type string

render

Renders your own element: one that receives the part's props, or a function of the props and the state.

Type RenderProp<MenuRadioItemState>

style

Styles, or a function of the part's state that returns them.

Type CSSProperties | ((state: MenuRadioItemState) => CSSProperties)

value*

Selected in the group when the item is chosen.

Type string

MenuSeparator

A line between groups of items.

children

Content, or a function of the part's state that returns it.

Type ReactNode | ((state: {}) => ReactNode)

className

Class names, or a function of the part's state that returns them.

Type string | ((state: {}) => string)

render

Renders your own element: one that receives the part's props, or a function of the props and the state.

Type RenderProp<{}>

style

Styles, or a function of the part's state that returns them.

Type CSSProperties | ((state: {}) => CSSProperties)

MenuShortcut

A keyboard hint at the end of an item, when you render one yourself.

children

Content, or a function of the part's state that returns it.

Type ReactNode | ((state: {}) => ReactNode)

className

Class names, or a function of the part's state that returns them.

Type string | ((state: {}) => string)

render

Renders your own element: one that receives the part's props, or a function of the props and the state.

Type RenderProp<{}>

style

Styles, or a function of the part's state that returns them.

Type CSSProperties | ((state: {}) => CSSProperties)

MenuSub

A submenu. Put its MenuSubTrigger and MenuSubContent inside, in a menu's content.

controller

Opens, closes and inspects the menu from anywhere, and connects triggers outside it. Create one with createMenuController().

Type PopupController<any, MenuOpenChangeReason, MenuOpenOptions, string, MenuPayloadChangeReason>

debug

Logs every state change with its reason to the console, in development builds.

Type boolean

defaultOpen

Whether the menu starts open, when uncontrolled.

Type boolean · Default false

delay

Milliseconds the pointer rests on a submenu trigger before its submenu opens.

Type number · Default 100

loop

Whether arrow keys wrap from the last item to the first.

Type boolean · Default true

onOpenChange

Runs when the menu wants to open or close. details.reason says why, and details.cancel() stops it.

Type (open: boolean, details: ChangeDetails<MenuOpenChangeReason>) => void

onOpenChangeComplete

Runs once the menu has finished opening or closing, after any animation.

Type (open: boolean) => void

open

Whether the menu is open. Pass it to control the menu.

Type boolean

MenuSubContent

A submenu's popup.

align

How the popup lines up with the anchor along that side. start and end follow the reading direction. How the menu lines up with the trigger along that side.

Type "center" | "start" | "end" · Default "start"

alignOffset

Shift along the anchor, in pixels. Shift along the trigger, in pixels. Submenus default to lining up their first item with the trigger.

Type number

anchor

Positions the popup against this instead of its trigger: an element, a CSS selector, a point like { x, y }, or anything with getBoundingClientRect(). It's read on every check, so it can move. A controller's open({ anchor }) wins for that open.

Type string | Anchor | null

arrowPadding

Space to keep between the arrow and the popup's corners, in pixels.

Type number · Default 6

children

Content, or a function of the part's state that returns it.

Type ReactNode | ((state: MenuContentState<unknown>) => ReactNode)

className

Class names, or a function of the part's state that returns them.

Type string | ((state: MenuContentState<unknown>) => string)

collisionPadding

Space to keep from the viewport edges, in pixels.

Type number · Default 8

container

Renders the popup into this element instead of in place, like a container inside a shadow root or an iframe. On web components, a CSS selector. Nested popups stay inside their parent.

Type Element | DocumentFragment | null

finalFocus

Where focus goes when the menu closes while focus is inside it. "trigger" returns it to the trigger and "none" leaves it. A CSS selector, an element or a function picks a specific element.

Type PopupFocusTarget · Default "trigger"

keepMounted

Whether the menu stays in the page, hidden, while closed. Its content keeps its state between opens.

Type boolean · Default false

render

Renders your own element: one that receives the part's props, or a function of the props and the state.

Type RenderProp<MenuContentState<unknown>>

side

Which side of the anchor the popup opens on. Flips to the other side when there isn't room. Which side of the trigger the menu opens on. Submenus open to the side, mirrored in right-to-left layouts.

Type "start" | "end" | "top" | "bottom" | "left" | "right" · Default "bottom"

sideOffset

Gap between the anchor and the popup, in pixels. Gap between the trigger and the menu, in pixels.

Type number · Default 4

style

Styles, or a function of the part's state that returns them.

Type CSSProperties | ((state: MenuContentState<unknown>) => CSSProperties)

MenuSubTrigger

Opens a submenu, with its chevron built in.

children

Content, or a function of the part's state that returns it.

Type ReactNode | ((state: MenuTriggerState) => ReactNode)

className

Class names, or a function of the part's state that returns them.

Type string | ((state: MenuTriggerState) => string)

disabled

Keeps the submenu trigger focusable but stops it from opening its submenu, as the menu pattern asks. Sets data-disabled and aria-disabled.

Type boolean

render

Renders your own element: one that receives the part's props, or a function of the props and the state.

Type RenderProp<MenuTriggerState>

style

Styles, or a function of the part's state that returns them.

Type CSSProperties | ((state: MenuTriggerState) => CSSProperties)

MenuTrigger

The button that opens the menu. A trigger outside the menu connects through controller.

children

Content, or a function of the part's state that returns it.

Type ReactNode | ((state: MenuTriggerState) => ReactNode)

className

Class names, or a function of the part's state that returns them.

Type string | ((state: MenuTriggerState) => string)

controller

Connects a trigger outside the menu, like one per table row, to the menu with this controller.

Type PopupController<any, MenuOpenChangeReason, MenuOpenOptions, string, MenuPayloadChangeReason>

disabled

Stops presses. The button is natively disabled, so it leaves the tab order and its form doesn't submit through it, unless focusableWhenDisabled is set.

Type boolean · Default false

focusableWhenDisabled

Keeps a disabled trigger in the tab order with aria-disabled instead of the native attribute, so it can host a tooltip that says why. Presses still do nothing.

Type boolean · Default false

payload

Data for the content to render when this trigger opens the menu, like the row it belongs to.

Type unknown

render

Renders your own element: one that receives the part's props, or a function of the props and the state.

Type RenderProp<MenuTriggerState>

shortcut

A keyboard shortcut that opens the menu from anywhere, like "mod+j". mod is Command on Apple platforms and Control elsewhere. Sets aria-keyshortcuts.

Type string

style

Styles, or a function of the part's state that returns them.

Type CSSProperties | ((state: MenuTriggerState) => CSSProperties)