Dinachi

Menu

A popup menu for actions and options triggered by a button.

View Source

#Installation

npx @dinachi/cli@latest add menu

#Usage

tsx
import {
  Menu,
  MenuTrigger,
  MenuPortal,
  MenuPositioner,
  MenuContent,
  MenuItem,
  MenuCheckboxItem,
  MenuRadioGroup,
  MenuRadioItem,
  MenuLabel,
  MenuSeparator,
  MenuShortcut,
  MenuSub,
  MenuSubTrigger,
  MenuSubContent,
  MenuFilter,
  MenuInput,
  MenuClear,
  MenuEmpty,
  MenuList,
} from "@/components/ui/menu"

#Examples

#Filtering

Wrap the menu in MenuFilter, put MenuInput at the top of the popup, and the items inside MenuList. MenuEmpty shows when nothing matches. Filtering is a Base UI preview, so the API may change.

A filterable submenu needs its own MenuFilter around MenuSub. To separate groups, mark each group data-filter-section and start it with <MenuSeparator data-filter-separator className="hidden" />. MenuList shows the separator only between two visible groups.

#API Reference

PropTypeDefaultDescription
openboolean—The controlled open state of the menu.
defaultOpenbooleanfalseThe initial open state for uncontrolled usage.
onOpenChange(open: boolean) => void—Callback fired when the menu open state changes.
modalbooleantrueWhether the menu enters a modal state when open.
loopFocusbooleantrueWhether to loop keyboard focus back to the first item when the end is reached.
disabledbooleanfalseWhether the menu should ignore user interaction.
MenuItem.insetbooleanfalseAdds indentation for nested command-style layouts.
MenuCheckboxItem.checkedboolean—The controlled checked state of the checkbox item.
MenuCheckboxItem.onCheckedChange(checked: boolean) => void—Callback fired when the checkbox item is ticked or unticked.
MenuRadioGroup.valueany—The controlled value of the selected radio item.
MenuRadioGroup.onValueChange(value: any) => void—Callback fired when the selected radio value changes.
MenuRadioItem.valueany—Value of the radio item.
MenuLabel.insetbooleanfalseAdds indentation to section labels.
MenuSubTrigger.insetbooleanfalseAdds indentation to submenu triggers.
MenuFilter.valuestring—The controlled filter query.
MenuFilter.defaultValuestring—The uncontrolled filter query when the menu first renders.
MenuFilter.onValueChange(value: string) => void—Callback fired when the filter query changes.
MenuFilter.filter((text: string, query: string) => boolean) | null—Decides whether an item matches the query. Pass null to filter items yourself.
MenuFilter.autoHighlightboolean | 'always'falseHighlights the first matching item while the query is not empty, or always with 'always'.
MenuInput.childrenReact.ReactNode—Rendered after the input, for placing MenuClear beside it.