# Menu
A list of actions behind a button, for people and agents.
Source page: https://dinachi.dev/docs/components/menu

## Installation
```bash
npx @dinachi/cli@latest add menu
```
Adds to your project:
- `components/ui/menu/menu.tsx`
- `components/ui/menu/index.ts`
Installs:
- `@base-ui/react` ^1.9.0
- `lucide-react` ^0.552.0

## Usage
```tsx
import { Menu, MenuContent, MenuItem, MenuTrigger } from "@/components/ui/menu"

export function ProjectActions() {
  return (
    <Menu>
      <MenuTrigger>Actions</MenuTrigger>
      <MenuContent>
        <MenuItem onClick={() => rename()}>Rename</MenuItem>
        <MenuItem onClick={() => duplicate()}>Duplicate</MenuItem>
      </MenuContent>
    </Menu>
  )
}
```

## Anatomy
```tsx
<Menu>
  <MenuTrigger />
  <MenuContent>
    <MenuGroup>
      <MenuLabel />
      <MenuItem>
        <MenuShortcut />
      </MenuItem>
      <MenuLinkItem />
    </MenuGroup>
    <MenuSeparator />
    <MenuCheckboxItem />
    <MenuRadioGroup>
      <MenuRadioItem />
    </MenuRadioGroup>
    <MenuSub>
      <MenuSubTrigger />
      <MenuSubContent />
    </MenuSub>
  </MenuContent>
</Menu>
```
- `Menu`: Holds the open state.
- `MenuTrigger`: The button that opens the menu.
- `MenuContent`: The popup, portalled, 6px from the trigger.
- `MenuItem`: One action.
- `MenuLinkItem`: A navigating item, rendered as an anchor.
- `MenuCheckboxItem`: A toggle item, checked when on.
- `MenuRadioGroup`: Holds the value of its radio items.
- `MenuRadioItem`: One radio choice, dotted when chosen.
- `MenuGroup`: Groups items under a `MenuLabel`.
- `MenuLabel`: The heading of a group.
- `MenuSeparator`: A line between items or groups.
- `MenuShortcut`: A display-only key hint; binds no key.
- `MenuSub`: Holds a nested menu.
- `MenuSubTrigger`: Opens a submenu; shows a chevron.
- `MenuSubContent`: The submenu popup, with its own portal and positioner.
- `MenuFilter`: Makes the Menu or `MenuSub` inside it filterable.
- `MenuInput`: Search field, with icon, atop a filterable popup.
- `MenuClear`: A button that empties the query.
- `MenuEmpty`: Shown when no item matches the query.
- `MenuList`: Scrolling item list in a filterable popup.
- `MenuPortal`: Portals children to the body. `MenuContent` includes one.
- `MenuPositioner`: Places the popup. `MenuContent` includes one.

## Examples

### Default
Items, shortcuts and separators.
```tsx
import {
  Menu,
  MenuTrigger,
  MenuContent,
  MenuItem,
  MenuSeparator,
  MenuShortcut,
  MenuGroup,
  MenuLabel,
} from '@/components/ui/menu';

export function Example() {
  return (
    <Menu>
      <MenuTrigger>Open Menu</MenuTrigger>
      <MenuContent>
        <MenuGroup>
          <MenuLabel>My Account</MenuLabel>
          <MenuItem>
            Profile
            <MenuShortcut>⌘P</MenuShortcut>
          </MenuItem>
          <MenuItem>
            Settings
            <MenuShortcut>⌘S</MenuShortcut>
          </MenuItem>
          <MenuItem>
            Keyboard Shortcuts
            <MenuShortcut>⌘K</MenuShortcut>
          </MenuItem>
        </MenuGroup>
        <MenuSeparator />
        <MenuItem>Log out</MenuItem>
      </MenuContent>
    </Menu>
  );
}
```

### Checkbox items
Items that toggle on and off.
```tsx
import React from 'react';
import {
  Menu,
  MenuTrigger,
  MenuContent,
  MenuGroup,
  MenuLabel,
  MenuCheckboxItem,
} from '@/components/ui/menu';

export function Example() {
  const [showStatus, setShowStatus] = React.useState(true);
  const [showActivity, setShowActivity] = React.useState(false);

  return (
    <Menu>
      <MenuTrigger>View Options</MenuTrigger>
      <MenuContent>
        <MenuGroup>
          <MenuLabel>Appearance</MenuLabel>
          <MenuCheckboxItem checked={showStatus} onCheckedChange={setShowStatus}>
            Show Status Bar
          </MenuCheckboxItem>
          <MenuCheckboxItem checked={showActivity} onCheckedChange={setShowActivity}>
            Show Activity Panel
          </MenuCheckboxItem>
        </MenuGroup>
      </MenuContent>
    </Menu>
  );
}
```

### Radio items
One choice from a group.
```tsx
import React from 'react';
import {
  Menu,
  MenuTrigger,
  MenuContent,
  MenuGroup,
  MenuLabel,
  MenuRadioGroup,
  MenuRadioItem,
} from '@/components/ui/menu';

export function Example() {
  const [theme, setTheme] = React.useState('system');

  return (
    <Menu>
      <MenuTrigger>Theme</MenuTrigger>
      <MenuContent>
        <MenuGroup>
          <MenuLabel>Select Theme</MenuLabel>
          <MenuRadioGroup value={theme} onValueChange={setTheme}>
            <MenuRadioItem value="light">Light</MenuRadioItem>
            <MenuRadioItem value="dark">Dark</MenuRadioItem>
            <MenuRadioItem value="system">System</MenuRadioItem>
          </MenuRadioGroup>
        </MenuGroup>
      </MenuContent>
    </Menu>
  );
}
```

### Submenu
A nested menu of related actions.
```tsx
import {
  Menu,
  MenuTrigger,
  MenuContent,
  MenuItem,
  MenuSeparator,
  MenuSub,
  MenuSubTrigger,
  MenuSubContent,
} from '@/components/ui/menu';

export function Example() {
  return (
    <Menu>
      <MenuTrigger>Actions</MenuTrigger>
      <MenuContent>
        <MenuItem>New File</MenuItem>
        <MenuItem>New Window</MenuItem>
        <MenuSeparator />
        <MenuSub>
          <MenuSubTrigger>Share</MenuSubTrigger>
          <MenuSubContent>
            <MenuItem>Email</MenuItem>
            <MenuItem>Messages</MenuItem>
            <MenuItem>Copy Link</MenuItem>
          </MenuSubContent>
        </MenuSub>
        <MenuSeparator />
        <MenuItem>Print</MenuItem>
      </MenuContent>
    </Menu>
  );
}
```

### Filter
A search input, an empty state and separated groups.
```tsx
import {
  Menu,
  MenuTrigger,
  MenuContent,
  MenuItem,
  MenuSeparator,
  MenuShortcut,
  MenuGroup,
  MenuLabel,
  MenuFilter,
  MenuInput,
  MenuClear,
  MenuEmpty,
  MenuList,
} from '@/components/ui/menu';

export function Example() {
  return (
    <MenuFilter>
      <Menu>
        <MenuTrigger>Actions</MenuTrigger>
        <MenuContent className="w-56">
          <MenuInput aria-label="Filter actions" placeholder="Filter actions">
            <MenuClear />
          </MenuInput>
          <MenuEmpty>No actions found.</MenuEmpty>
          <MenuList>
            <MenuGroup data-filter-section>
              <MenuLabel>File</MenuLabel>
              <MenuItem>
                New File
                <MenuShortcut>⌘N</MenuShortcut>
              </MenuItem>
              <MenuItem>
                Open File
                <MenuShortcut>⌘O</MenuShortcut>
              </MenuItem>
              <MenuItem>
                Save
                <MenuShortcut>⌘S</MenuShortcut>
              </MenuItem>
            </MenuGroup>
            <MenuGroup data-filter-section>
              <MenuSeparator data-filter-separator className="hidden" />
              <MenuLabel>Edit</MenuLabel>
              <MenuItem>Rename</MenuItem>
              <MenuItem>Duplicate</MenuItem>
              <MenuItem>Delete</MenuItem>
            </MenuGroup>
          </MenuList>
        </MenuContent>
      </Menu>
    </MenuFilter>
  );
}
```

### Filterable submenu
A submenu with its own search input.
```tsx
import {
  Menu,
  MenuTrigger,
  MenuContent,
  MenuItem,
  MenuSeparator,
  MenuSub,
  MenuSubTrigger,
  MenuSubContent,
  MenuFilter,
  MenuInput,
  MenuClear,
  MenuEmpty,
  MenuList,
} from '@/components/ui/menu';

export function Example() {
  return (
    <Menu>
      <MenuTrigger>Actions</MenuTrigger>
      <MenuContent>
        <MenuItem>New File</MenuItem>
        <MenuFilter>
          <MenuSub>
            <MenuSubTrigger>Move to</MenuSubTrigger>
            <MenuSubContent className="w-56">
              <MenuInput aria-label="Filter folders" placeholder="Filter folders">
                <MenuClear />
              </MenuInput>
              <MenuEmpty>No folders found.</MenuEmpty>
              <MenuList>
                <MenuItem>Desktop</MenuItem>
                <MenuItem>Documents</MenuItem>
                <MenuItem>Downloads</MenuItem>
                <MenuItem>Projects</MenuItem>
                <MenuItem>Archive</MenuItem>
              </MenuList>
            </MenuSubContent>
          </MenuSub>
        </MenuFilter>
        <MenuSeparator />
        <MenuItem>Delete</MenuItem>
      </MenuContent>
    </Menu>
  );
}
```

## Notes

### Positioning
`MenuContent` includes its portal and positioner and passes `side`, `align`, `sideOffset` and `alignOffset` to the positioner. For anything else the positioner takes, compose `MenuPortal` and `MenuPositioner` around a popup.

### Filtering
- Wrap the menu in `MenuFilter`, put `MenuInput` at the top of the popup and the items inside `MenuList`. `MenuEmpty` shows when nothing matches.
- A filterable submenu needs its own `MenuFilter` around `MenuSub`.
- To separate groups, mark each `data-filter-section` and start it with `<MenuSeparator data-filter-separator className="hidden" />`. `MenuList` shows it only between two visible groups.
- Filtering is a Base UI preview; its API may change.

## API reference
Props marked **agent** change what an agent reads or may do.

### Menu
Holds the open state.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `open` | `boolean` | - | Controlled open state. |
| `defaultOpen` | `boolean` | `false` | Starting open state when uncontrolled. |
| `onOpenChange` **agent** | `(open, details) => void` | - | Runs on open and close, for people and agents. `details.cancel()` refuses. |
| `modal` | `boolean` | `true` | Locks page scroll and outside clicks while open. |
| `loopFocus` | `boolean` | `true` | Wraps keyboard focus from the last item to the first. |
| `disabled` | `boolean` | `false` | Ignores interaction. |
| `orientation` | `"vertical" \| "horizontal"` | `"vertical"` | Which arrow keys move between items. |

### MenuTrigger
The button that opens the menu.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` **agent** | `ReactNode` | - | The label. Also the name the agent reads. |
| `openOnHover` | `boolean` | `false` | Opens on hover as well as on press. |
| `delay` | `number` | `100` | Milliseconds before a hover opens it. |
| `disabled` | `boolean` | `false` | Blocks the trigger. |
| `render` | `ReactElement` | - | Swap the element, keep the behaviour. |

### MenuContent
The popup, portalled, 6px from the trigger.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `side` | `"top" \| "bottom" \| "left" \| "right"` | `"bottom"` | Which side of the trigger the popup opens on. |
| `align` | `"start" \| "center" \| "end"` | `"center"` | How the popup lines up along that side. Use `end` for a trigger at the right edge. |
| `sideOffset` | `number` | `6` | Gap to the trigger, in pixels. |
| `alignOffset` | `number` | `0` | Shift along the side, in pixels. |
| `className` | `string` | - | Merged with the popup styles. |

### MenuItem
One action.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `onClick` **agent** | `(event) => void` | - | Runs the action. An agent's press triggers it too. |
| `closeOnClick` | `boolean` | `true` | Closes the menu once clicked. |
| `disabled` **agent** | `boolean` | `false` | Skipped by the keyboard, refused for agents. |
| `inset` | `boolean` | `false` | Indents the item to line up with checkbox and radio items. |

### MenuLinkItem
A navigating item, rendered as an anchor.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `href` | `string` | - | Where the item goes. |
| `closeOnClick` | `boolean` | `false` | Closes the menu once clicked. |
| `render` | `ReactElement` | - | Swap in a router's link. |

### MenuCheckboxItem
A toggle item, checked when on.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `checked` **agent** | `boolean` | - | Controlled checked state. |
| `defaultChecked` | `boolean` | `false` | Starting state when uncontrolled. |
| `onCheckedChange` | `(checked, details) => void` | - | Runs when ticked or unticked. |
| `closeOnClick` | `boolean` | `false` | Closes the menu once clicked. |
| `disabled` **agent** | `boolean` | `false` | Skipped by the keyboard, refused for agents. |

### MenuRadioGroup
Holds the value of its radio items.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `value` | `any` | - | Controlled value. |
| `defaultValue` | `any` | - | Starting value when uncontrolled. |
| `onValueChange` | `(value, details) => void` | - | Runs when another radio item is chosen. |
| `disabled` | `boolean` | `false` | Blocks every item in the group. |

### MenuRadioItem
One radio choice, dotted when chosen.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `value` | `any` | - | What the group's `onValueChange` receives. |
| `closeOnClick` | `boolean` | `false` | Closes the menu once clicked. |
| `disabled` **agent** | `boolean` | `false` | Skipped by the keyboard, refused for agents. |

### MenuGroup
Groups items under a `MenuLabel`.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `ReactNode` | - | A `MenuLabel`, then items. |

### MenuLabel
The heading of a group.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `inset` | `boolean` | `false` | Indents the label to line up with inset items. |

### MenuSeparator
A line between items or groups.

Takes the props of the element it renders.

### MenuShortcut
A display-only key hint; binds no key.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `ReactNode` | - | The shortcut text, such as `⌘S`. |

### MenuSub
Holds a nested menu.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `open` | `boolean` | - | Controlled open state. |
| `onOpenChange` | `(open, details) => void` | - | Runs when the submenu opens or closes. |
| `closeParentOnEsc` | `boolean` | `false` | Escape also closes the parent menu. |

### MenuSubTrigger
Opens a submenu; shows a chevron.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `openOnHover` | `boolean` | `true` | Opens the submenu on hover. |
| `delay` | `number` | `100` | Milliseconds before a hover opens it. |
| `disabled` | `boolean` | `false` | Blocks the submenu. |
| `inset` | `boolean` | `false` | Indents it to line up with inset items. |

### MenuSubContent
The submenu popup, with its own portal and positioner.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` | - | Merged with the popup styles. |

### MenuFilter
Makes the Menu or `MenuSub` inside it filterable.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `value` | `string` | - | Controlled filter query. |
| `defaultValue` | `string` | - | Starting query when uncontrolled. |
| `onValueChange` | `(value, details) => void` | - | Runs when the query changes. |
| `filter` | `((text, query) => boolean) \| null` | - | Decides whether an item matches. `null` leaves filtering to you. |
| `autoHighlight` | `boolean \| "always"` | `false` | Highlights the first match while there is a query, or always. |

### MenuInput
Search field, with icon, atop a filterable popup.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `placeholder` | `string` | - | Shown while the query is empty. |
| `children` | `ReactNode` | - | Rendered after the input, for a `MenuClear`. |

### MenuClear
A button that empties the query.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `ReactNode` | `<X />` | Replaces the icon. |

### MenuEmpty
Shown when no item matches the query.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `ReactNode` | - | The empty message. |

### MenuList
Scrolling item list in a filterable popup.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `ReactNode` | - | Items and groups. |

### MenuPortal
Portals children to the body. `MenuContent` includes one.

Takes the props of the element it renders.

### MenuPositioner
Places the popup. `MenuContent` includes one.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `side` | `"top" \| "bottom" \| "left" \| "right" \| "inline-start" \| "inline-end"` | `"bottom"` | Which side of the trigger the popup goes on. |
| `align` | `"start" \| "center" \| "end"` | `"center"` | How the popup lines up along that side. |
| `sideOffset` | `number` | `6` | Gap to the trigger, in pixels. |

## Agent
Inside an `AgentProvider`, Menu appears in `agent.snapshot()` as `menu`.
Reads:
- `label`: The trigger's text, or the popup's own name if set.
- `open`: Whether the popup is showing. Closed, the agent sees the trigger; open, the popup.
Actions:
- `open() / close()`: Whichever fits the current state.
- `press() on an item`: Items are listed inside the open menu as `menuitem`. Runs the item as a click.
- `setChecked(true) on a checkbox item`: Ticks or unticks it. Radio items take only press.
Opening and closing run through `onOpenChange`. `isAgentChange(details)` is true for an agent's change, and `details.cancel()` refuses it; the agent is told the app refused. An item press is a click, so `onClick` and `onCheckedChange` get an ordinary event. Disabled items refuse on their own.
```ts
await agent.act({
  steps: [
    { ref: "Open Menu", action: "open" },
    { ref: "Profile", action: "press" },
  ],
})
```

## Accessibility
- The trigger is a button; items are menuitem, menuitemcheckbox or menuitemradio, with checked state.
- Give an icon-only trigger an aria-label. The agent uses the same name.
- Disabled items stay announced but are skipped by the keyboard.
- Focus returns to the trigger when the menu closes.
- Reduced motion drops the popup's scale and keeps the fade.
### Keyboard
| Keys | Does |
| --- | --- |
| `Enter` / `Space` | Opens the menu from the trigger, or runs the highlighted item |
| `↑` / `↓` | Moves the highlight |
| `→` | Opens the highlighted submenu |
| `←` | Closes the submenu and returns to its trigger |
| `Home` / `End` | Jumps to the first or last item |
| `A` to `Z` | Jumps to the next item starting with that letter |
| `Esc` | Closes and returns focus to the trigger |

## Source
`components/ui/menu/menu.tsx`
```tsx
"use client"

import * as React from "react"
import { Menu as MenuPrimitive } from "@base-ui/react/menu"
import { Check, ChevronRight, Circle, Search, X } from "lucide-react"
import { cn } from "@/lib/utils"
import { type AgentOpenParts, useAgentOpen, useHasAgent, useMergedRef } from "@/components/ui/agent"

const MenuAgentContext = React.createContext<AgentOpenParts | null>(null)

/**
 * Base UI's root, holding its own open state so an agent can open and close it. Closed,
 * the agent sees the trigger; open, the popup, with its items listed as menu items.
 */
const Menu: React.FC<React.ComponentProps<typeof MenuPrimitive.Root>> = ({
  open,
  defaultOpen,
  onOpenChange,
  ...props
}) => {
  const [state, change, parts] = useAgentOpen("menu", open, defaultOpen, onOpenChange)
  return (
    <MenuAgentContext.Provider value={useHasAgent() ? parts : null}>
      <MenuPrimitive.Root {...props} open={state} onOpenChange={change} />
    </MenuAgentContext.Provider>
  )
}
Menu.displayName = "Menu"

const MenuTrigger = React.forwardRef<
  HTMLButtonElement,
  React.ComponentProps<typeof MenuPrimitive.Trigger>
>(({ className, ...props }, ref) => (
  <MenuPrimitive.Trigger
    ref={useMergedRef(ref, React.useContext(MenuAgentContext)?.trigger)}
    className={cn(
      "inline-flex h-10 items-center justify-center rounded-md border border-input bg-background px-4 py-2 text-sm font-medium",
      "hover:bg-accent hover:text-accent-foreground",
      "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
      "data-[popup-open]:bg-accent data-[popup-open]:text-accent-foreground",
      "data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
      className
    )}
    data-slot="menu-trigger"
    {...props}
  />
))
MenuTrigger.displayName = "MenuTrigger"

const MenuPortal: React.FC<
  React.ComponentProps<typeof MenuPrimitive.Portal>
> = (props) => <MenuPrimitive.Portal data-slot="menu-portal" {...props} />
MenuPortal.displayName = "MenuPortal"

const MenuPositioner = React.forwardRef<
  React.ComponentRef<typeof MenuPrimitive.Positioner>,
  React.ComponentProps<typeof MenuPrimitive.Positioner>
>(({ className, ...props }, ref) => (
  <MenuPrimitive.Positioner
    ref={ref}
    className={cn("z-50 outline-none", className)}
    sideOffset={6}
    data-slot="menu-positioner"
    {...props}
  />
))
MenuPositioner.displayName = "MenuPositioner"

type MenuPlacement = Pick<
  React.ComponentProps<typeof MenuPrimitive.Positioner>,
  "side" | "align" | "sideOffset" | "alignOffset"
>

const MenuContent = React.forwardRef<
  React.ComponentRef<typeof MenuPrimitive.Popup>,
  React.ComponentProps<typeof MenuPrimitive.Popup> & MenuPlacement
>(({ className, side, align, sideOffset, alignOffset, ...props }, ref) => (
  <MenuPortal>
    <MenuPositioner side={side} align={align} sideOffset={sideOffset ?? 6} alignOffset={alignOffset}>
      <MenuPrimitive.Popup
        ref={useMergedRef(ref, React.useContext(MenuAgentContext)?.popup)}
        className={cn(
          "min-w-40 overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md",
          "origin-[var(--transform-origin)] outline-none",
          "transition-[transform,scale,opacity] duration-[var(--motion-duration-fast,150ms)] ease-[var(--motion-ease-out,cubic-bezier(0.23,1,0.32,1))]",
          "data-[starting-style]:scale-95 data-[starting-style]:opacity-0",
          "data-[ending-style]:scale-95 data-[ending-style]:opacity-0",
          "motion-reduce:data-[starting-style]:scale-100 motion-reduce:data-[ending-style]:scale-100",
          className
        )}
        data-slot="menu-content"
        {...props}
      />
    </MenuPositioner>
  </MenuPortal>
))
MenuContent.displayName = "MenuContent"

const MenuItem = React.forwardRef<
  React.ComponentRef<typeof MenuPrimitive.Item>,
  React.ComponentProps<typeof MenuPrimitive.Item> & {
    inset?: boolean
  }
>(({ className, inset, ...props }, ref) => (
  <MenuPrimitive.Item
    ref={ref}
    className={cn(
      "relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none",
      "focus:bg-accent focus:text-accent-foreground",
      "data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
      "data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground",
      inset && "pl-8",
      className
    )}
    data-slot="menu-item"
    {...props}
  />
))
MenuItem.displayName = "MenuItem"

const MenuLinkItem = React.forwardRef<
  React.ComponentRef<typeof MenuPrimitive.LinkItem>,
  React.ComponentProps<typeof MenuPrimitive.LinkItem>
>(({ className, ...props }, ref) => (
  <MenuPrimitive.LinkItem
    ref={ref}
    className={cn(
      "relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none",
      "focus:bg-accent focus:text-accent-foreground",
      "data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground",
      className
    )}
    data-slot="menu-link-item"
    {...props}
  />
))
MenuLinkItem.displayName = "MenuLinkItem"

const MenuCheckboxItem = React.forwardRef<
  React.ComponentRef<typeof MenuPrimitive.CheckboxItem>,
  React.ComponentProps<typeof MenuPrimitive.CheckboxItem>
>(({ className, children, ...props }, ref) => (
  <MenuPrimitive.CheckboxItem
    ref={ref}
    className={cn(
      "relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none",
      "focus:bg-accent focus:text-accent-foreground",
      "data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
      "data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground",
      className
    )}
    data-slot="menu-checkbox-item"
    {...props}
  >
    <MenuPrimitive.CheckboxItemIndicator className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
      <Check className="h-4 w-4" />
    </MenuPrimitive.CheckboxItemIndicator>
    {children}
  </MenuPrimitive.CheckboxItem>
))
MenuCheckboxItem.displayName = "MenuCheckboxItem"

const MenuRadioGroup = React.forwardRef<
  React.ComponentRef<typeof MenuPrimitive.RadioGroup>,
  React.ComponentProps<typeof MenuPrimitive.RadioGroup>
>(({ className, ...props }, ref) => (
  <MenuPrimitive.RadioGroup ref={ref} className={className} data-slot="menu-radio-group" {...props} />
))
MenuRadioGroup.displayName = "MenuRadioGroup"

const MenuRadioItem = React.forwardRef<
  React.ComponentRef<typeof MenuPrimitive.RadioItem>,
  React.ComponentProps<typeof MenuPrimitive.RadioItem>
>(({ className, children, ...props }, ref) => (
  <MenuPrimitive.RadioItem
    ref={ref}
    className={cn(
      "relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none",
      "focus:bg-accent focus:text-accent-foreground",
      "data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
      "data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground",
      className
    )}
    data-slot="menu-radio-item"
    {...props}
  >
    <MenuPrimitive.RadioItemIndicator className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
      <Circle className="h-2 w-2 fill-current" />
    </MenuPrimitive.RadioItemIndicator>
    {children}
  </MenuPrimitive.RadioItem>
))
MenuRadioItem.displayName = "MenuRadioItem"

const MenuGroup = React.forwardRef<
  React.ComponentRef<typeof MenuPrimitive.Group>,
  React.ComponentProps<typeof MenuPrimitive.Group>
>(({ className, ...props }, ref) => (
  <MenuPrimitive.Group ref={ref} className={className} data-slot="menu-group" {...props} />
))
MenuGroup.displayName = "MenuGroup"

const MenuLabel = React.forwardRef<
  React.ComponentRef<typeof MenuPrimitive.GroupLabel>,
  React.ComponentProps<typeof MenuPrimitive.GroupLabel> & {
    inset?: boolean
  }
>(({ className, inset, ...props }, ref) => (
  <MenuPrimitive.GroupLabel
    ref={ref}
    className={cn("px-2 py-1.5 text-sm font-medium", inset && "pl-8", className)}
    data-slot="menu-label"
    {...props}
  />
))
MenuLabel.displayName = "MenuLabel"

const MenuSeparator = React.forwardRef<
  React.ComponentRef<typeof MenuPrimitive.Separator>,
  React.ComponentProps<typeof MenuPrimitive.Separator>
>(({ className, ...props }, ref) => (
  <MenuPrimitive.Separator
    ref={ref}
    className={cn("-mx-1 my-1 h-px bg-border", className)}
    data-slot="menu-separator"
    {...props}
  />
))
MenuSeparator.displayName = "MenuSeparator"

const MenuShortcut = ({
  className,
  ...props
}: React.HTMLAttributes<HTMLSpanElement>) => (
  <span
    className={cn("ml-auto text-xs tracking-widest text-muted-foreground", className)}
    data-slot="menu-shortcut"
    {...props}
  />
)
MenuShortcut.displayName = "MenuShortcut"

const MenuSub: React.FC<React.ComponentProps<typeof MenuPrimitive.SubmenuRoot>> = (props) => (
  <MenuPrimitive.SubmenuRoot {...props} />
)
MenuSub.displayName = "MenuSub"

const MenuSubTrigger = React.forwardRef<
  React.ComponentRef<typeof MenuPrimitive.SubmenuTrigger>,
  React.ComponentProps<typeof MenuPrimitive.SubmenuTrigger> & {
    inset?: boolean
  }
>(({ className, inset, children, ...props }, ref) => (
  <MenuPrimitive.SubmenuTrigger
    ref={ref}
    className={cn(
      "flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none",
      "focus:bg-accent focus:text-accent-foreground",
      "data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground",
      "data-[popup-open]:bg-accent data-[popup-open]:text-accent-foreground",
      "data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
      inset && "pl-8",
      className
    )}
    data-slot="menu-sub-trigger"
    {...props}
  >
    {children}
    <ChevronRight className="ml-auto h-4 w-4" />
  </MenuPrimitive.SubmenuTrigger>
))
MenuSubTrigger.displayName = "MenuSubTrigger"

const MenuSubContent = React.forwardRef<
  React.ComponentRef<typeof MenuPrimitive.Popup>,
  React.ComponentProps<typeof MenuPrimitive.Popup>
>(({ className, ...props }, ref) => (
  <MenuPrimitive.Portal>
    <MenuPrimitive.Positioner className="z-50 outline-none" alignOffset={-4} sideOffset={8}>
      <MenuPrimitive.Popup
        ref={ref}
        className={cn(
          "min-w-32 overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md",
          "origin-[var(--transform-origin)] outline-none",
          "transition-[transform,scale,opacity] duration-[var(--motion-duration-fast,150ms)] ease-[var(--motion-ease-out,cubic-bezier(0.23,1,0.32,1))]",
          "data-[starting-style]:scale-95 data-[starting-style]:opacity-0",
          "data-[ending-style]:scale-95 data-[ending-style]:opacity-0",
          "motion-reduce:data-[starting-style]:scale-100 motion-reduce:data-[ending-style]:scale-100",
          className
        )}
        data-slot="menu-sub-content"
        {...props}
      />
    </MenuPrimitive.Positioner>
  </MenuPrimitive.Portal>
))
MenuSubContent.displayName = "MenuSubContent"

const MenuFilter: React.FC<React.ComponentProps<typeof MenuPrimitive.FilterProvider>> = (props) => (
  <MenuPrimitive.FilterProvider {...props} />
)
MenuFilter.displayName = "MenuFilter"

const MenuInput = React.forwardRef<
  React.ComponentRef<typeof MenuPrimitive.Input>,
  React.ComponentProps<typeof MenuPrimitive.Input>
>(({ className, children, ...props }, ref) => (
  <div className="-mx-1 -mt-1 mb-1 flex items-center gap-2 border-b px-2">
    <Search className="h-4 w-4 shrink-0 text-muted-foreground" />
    <MenuPrimitive.Input
      ref={ref}
      className={cn(
        "flex h-9 w-full bg-transparent py-2 text-sm outline-none",
        "placeholder:text-muted-foreground",
        "disabled:cursor-not-allowed disabled:opacity-50",
        className
      )}
      data-slot="menu-input"
      {...props}
    />
    {children}
  </div>
))
MenuInput.displayName = "MenuInput"

const MenuClear = React.forwardRef<
  React.ComponentRef<typeof MenuPrimitive.Clear>,
  React.ComponentProps<typeof MenuPrimitive.Clear>
>(({ className, children, ...props }, ref) => (
  <MenuPrimitive.Clear
    ref={ref}
    className={cn(
      "inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-sm text-muted-foreground",
      "hover:text-foreground",
      "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
      className
    )}
    data-slot="menu-clear"
    {...props}
  >
    {children ?? <X className="h-4 w-4" />}
  </MenuPrimitive.Clear>
))
MenuClear.displayName = "MenuClear"

const MenuEmpty = React.forwardRef<
  React.ComponentRef<typeof MenuPrimitive.Empty>,
  React.ComponentProps<typeof MenuPrimitive.Empty>
>(({ className, ...props }, ref) => (
  <MenuPrimitive.Empty
    ref={ref}
    className={cn("py-6 text-center text-sm text-muted-foreground", className)}
    data-slot="menu-empty"
    {...props}
  />
))
MenuEmpty.displayName = "MenuEmpty"

const MenuList = React.forwardRef<
  React.ComponentRef<typeof MenuPrimitive.List>,
  React.ComponentProps<typeof MenuPrimitive.List>
>(({ className, ...props }, ref) => (
  <MenuPrimitive.List
    ref={ref}
    className={cn(
      "max-h-[min(22rem,var(--available-height))] overflow-y-auto scroll-py-1 outline-none",
      "[&>[data-filter-section]:not([hidden])~[data-filter-section]:not([hidden])>[data-filter-separator]]:block",
      className
    )}
    data-slot="menu-list"
    {...props}
  />
))
MenuList.displayName = "MenuList"

export {
  Menu,
  MenuTrigger,
  MenuPortal,
  MenuPositioner,
  MenuContent,
  MenuItem,
  MenuLinkItem,
  MenuCheckboxItem,
  MenuRadioGroup,
  MenuRadioItem,
  MenuGroup,
  MenuLabel,
  MenuSeparator,
  MenuShortcut,
  MenuSub,
  MenuSubTrigger,
  MenuSubContent,
  MenuFilter,
  MenuInput,
  MenuClear,
  MenuEmpty,
  MenuList,
}
```
