Skip to content
View as Markdown

Menu ​

The Menu component provides a dropdown menu with a compound component API. It is backed by Base UI's Menu primitive.

Import ​

tsx
import { Menu } from "@tailor-platform/app-shell";

The runnable examples also import useState from react, Button and Text from @tailor-platform/app-shell, and EllipsisVerticalIcon from lucide-react.

Basic Usage ​

tsx
function BasicUsage() {
  return (
    <Menu.Root>
      <Menu.Trigger>Open menu</Menu.Trigger>
      <Menu.Content>
        <Menu.Item>Edit</Menu.Item>
        <Menu.Item>Duplicate</Menu.Item>
        <Menu.Separator />
        <Menu.Item>Delete</Menu.Item>
      </Menu.Content>
    </Menu.Root>
  );
}

Sub-components ​

Sub-componentDescription
Menu.RootManages menu open/close state
Menu.TriggerElement that opens the menu when clicked
Menu.ContentThe menu popup containing menu items
Menu.ItemAn individual interactive item
Menu.LinkItemA link item for navigation
Menu.CheckboxItemA menu item that toggles a setting on or off
Menu.CheckboxItemIndicatorIndicates whether the checkbox item is ticked
Menu.RadioItemA menu item that works like a radio button within a group
Menu.RadioItemIndicatorIndicates whether the radio item is selected
Menu.RadioGroupGroups related radio items
Menu.GroupGroups related menu items
Menu.GroupLabelAn accessible label for a Menu.Group
Menu.SeparatorA visual separator between menu items
Menu.SubmenuRootGroups all parts of a nested sub-menu
Menu.SubmenuTriggerA menu item that opens a sub-menu

Props ​

PropTypeDefaultDescription
openboolean-Controlled open state
defaultOpenbooleanfalseInitial open state (uncontrolled)
onOpenChange(open: boolean) => void-Callback when open state changes
modalbooleantrueWhether the menu is modal
disabledbooleanfalseDisables the entire menu
childrenReact.ReactNode-Menu sub-components
PropTypeDefaultDescription
position{ side?: "top" | "right" | "bottom" | "left"; align?: "start" | "center" | "end"; sideOffset?: number }{ side: "bottom", align: "start", sideOffset: 4 }Placement of the popup
classNamestring-Additional CSS classes
childrenReact.ReactNode-Menu items and other sub-components

Accepts className, disabled, and all standard Base UI Menu.Item props.

PropTypeDefaultDescription
openboolean-Controlled open state
defaultOpenbooleanfalseInitial open state (uncontrolled)
onOpenChange(open: boolean) => void-Callback when open state changes
disabledbooleanfalseDisables the entire sub-menu
childrenReact.ReactNode-Sub-menu sub-components

Grouped Items ​

Use Menu.Group and Menu.GroupLabel to visually group related items:

tsx
function GroupedItems() {
  return (
    <Menu.Root>
      <Menu.Trigger>Actions</Menu.Trigger>
      <Menu.Content>
        <Menu.Group>
          <Menu.GroupLabel>File</Menu.GroupLabel>
          <Menu.Item>New</Menu.Item>
          <Menu.Item>Open</Menu.Item>
        </Menu.Group>
        <Menu.Separator />
        <Menu.Group>
          <Menu.GroupLabel>Edit</Menu.GroupLabel>
          <Menu.Item>Cut</Menu.Item>
          <Menu.Item>Copy</Menu.Item>
          <Menu.Item>Paste</Menu.Item>
        </Menu.Group>
      </Menu.Content>
    </Menu.Root>
  );
}

Checkbox Items ​

Open Format text and toggle Bold or Italic. The sample text and the reported settings update together.

tsx
function CheckboxItems() {
  const [bold, setBold] = useState(false);
  const [italic, setItalic] = useState(false);

  return (
    <div className="space-y-3">
      <Menu.Root>
        <Menu.Trigger render={<Button variant="outline" />}>Format text</Menu.Trigger>
        <Menu.Content>
          <Menu.CheckboxItem checked={bold} onCheckedChange={setBold}>
            <Menu.CheckboxItemIndicator>✓</Menu.CheckboxItemIndicator>
            Bold
          </Menu.CheckboxItem>
          <Menu.CheckboxItem checked={italic} onCheckedChange={setItalic}>
            <Menu.CheckboxItemIndicator>✓</Menu.CheckboxItemIndicator>
            Italic
          </Menu.CheckboxItem>
        </Menu.Content>
      </Menu.Root>
      <Text.p
        style={{ fontWeight: bold ? "bold" : "normal", fontStyle: italic ? "italic" : "normal" }}
      >
        Format this sample text.
      </Text.p>
      <Text.p role="status">
        Bold: {bold ? "on" : "off"}; italic: {italic ? "on" : "off"}
      </Text.p>
    </div>
  );
}

Radio Items ​

Choose an alignment from Align text. Only one radio item is selected, and the sample text moves to that alignment.

tsx
function RadioItems() {
  const [align, setAlign] = useState("left");

  return (
    <div className="space-y-3">
      <Menu.Root>
        <Menu.Trigger render={<Button variant="outline" />}>Align text</Menu.Trigger>
        <Menu.Content>
          <Menu.RadioGroup value={align} onValueChange={setAlign}>
            {["left", "center", "right"].map((value) => (
              <Menu.RadioItem key={value} value={value}>
                <Menu.RadioItemIndicator>●</Menu.RadioItemIndicator>
                {value}
              </Menu.RadioItem>
            ))}
          </Menu.RadioGroup>
        </Menu.Content>
      </Menu.Root>
      <Text.p
        className={
          align === "center" ? "text-center" : align === "right" ? "text-right" : "text-left"
        }
      >
        Align this sample text.
      </Text.p>
      <Text.p role="status">Alignment: {align}</Text.p>
    </div>
  );
}

Nested Sub-menus ​

tsx
function NestedSubmenus() {
  return (
    <Menu.Root>
      <Menu.Trigger>Edit</Menu.Trigger>
      <Menu.Content>
        <Menu.Item>Cut</Menu.Item>
        <Menu.Item>Copy</Menu.Item>
        <Menu.SubmenuRoot>
          <Menu.SubmenuTrigger>Paste Special ›</Menu.SubmenuTrigger>
          <Menu.Content>
            <Menu.Item>Paste as Plain Text</Menu.Item>
            <Menu.Item>Paste and Match Style</Menu.Item>
          </Menu.Content>
        </Menu.SubmenuRoot>
      </Menu.Content>
    </Menu.Root>
  );
}

Examples ​

Row Actions Menu ​

Open the order's three-dot button and choose an action. This is a button-triggered dropdown, not a right-click context menu. The example records the chosen action locally without modifying an order or navigating away. Use render to make the styled Button the trigger itself, rather than nesting two buttons.

tsx
function RowActions() {
  const orderNumber = "ORD-1001";
  const [lastAction, setLastAction] = useState("None");

  return (
    <div className="space-y-3">
      <div className="flex items-center gap-3">
        <Text.span>{orderNumber}</Text.span>
        <Menu.Root>
          <Menu.Trigger render={<Button variant="ghost" size="icon" aria-label="Order actions" />}>
            <EllipsisVerticalIcon />
          </Menu.Trigger>
          <Menu.Content>
            <Menu.Item onClick={() => setLastAction(`Edit ${orderNumber}`)}>Edit</Menu.Item>
            <Menu.Item onClick={() => setLastAction(`Duplicate ${orderNumber}`)}>
              Duplicate
            </Menu.Item>
            <Menu.Separator />
            <Menu.Item onClick={() => setLastAction(`View history for ${orderNumber}`)}>
              View history
            </Menu.Item>
          </Menu.Content>
        </Menu.Root>
      </div>
      <Text.p role="status">Last action: {lastAction}</Text.p>
    </div>
  );
}

Accessibility ​

  • Menu items are keyboard navigable with arrow keys
  • Pressing Escape closes the menu
  • Sub-menus open on arrow-right and close on arrow-left
  • Menu.GroupLabel is automatically associated with its parent group
  • Dialog - For actions that require confirmation
  • Sheet - Slide-in panel for more complex workflows
  • Button - Common trigger element for menus