Menu
npx shadcn add @klarhimmel/menu @klarhimmel/buttonCopy for AIExamples
Basic
Options
Row actions
DetailsAbout, usage, props and more
A list of actions behind a button. Arrow keys move, type-ahead jumps. Built on Radix Dropdown Menu.
When to use
Use for
Three or more actions on one thing: rename, duplicate, delete.
Not for
Navigation between pages, or picking a value. Use links or a select.
Pairs with
Button or Icon button as the trigger, Kbd hints.
Preview
Import
Import
- Files
- menu.tsx, button.tsx, in components/klarhimmel/ui/. With it: editing, theme, utils. npm: lucide-react, radix-ui.
- Render in
- Render it inside <Theme>, once near the root of your app. Tokens and fonts are scoped to it, so outside it the component is unstyled.
- Limit
- Overlays render into the Theme root with position: fixed. A transform on an ancestor re-parents fixed (a dialog centres in the wrapper) and overflow: hidden clips menus. Render <Theme> at the app root, outside any transformed wrapper.
Anatomy
The parts and how they nest.
MenuHolds the open state.MenuTriggerWrap your Button with asChild.MenuContentThe floating list. Portals into the theme root so it keeps the tokens.MenuItemAn action. Takes icon, shortcut, danger and onSelect.MenuCheckItemA toggle that stays in the menu.MenuLabel, MenuSeparatorA group heading and a divider.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
MenuContent.children | ReactNode | required | |
MenuContent.align | 'start' | 'center' | 'end' | 'start' | |
MenuContent.side | 'top' | 'right' | 'bottom' | 'left' | 'bottom' | Where it opens; it flips to stay on screen. |
MenuContent.className | string | - | |
MenuContent.onCloseAutoFocus | (e: Event) => void | - | |
MenuItem.icon | ReactNode | - | |
MenuItem.shortcut | string | - | A leading icon and a trailing shortcut hint. |
MenuItem.danger | boolean | - | |
MenuItem.children | ReactNode | required | |
MenuItem.onSelect | () => void | - | |
MenuItem.disabled | boolean | - | Destructive tint; disabled items are skipped by the arrow keys. |
MenuCheckItem.checked | boolean | required | |
MenuCheckItem.onCheckedChange | (checked: boolean) => void | required | An item that toggles. The menu stays open, so several can be changed in one visit. |
MenuCheckItem.children | ReactNode | required | |
MenuRadioGroup.value | string | required | |
MenuRadioGroup.onValueChange | (value: string) => void | required | |
MenuRadioGroup.children | ReactNode | required | |
MenuRadioItem.value | string | required | |
MenuRadioItem.children | ReactNode | required | |
MenuRadioItem.description | ReactNode | - | A second, quieter line under the name (what a model is for). |
MenuRadioItem.badge | ReactNode | - | A small tag at the end ("New"). |
MenuRadioItem.checkAt | 'start' | 'end' | 'end' | Where the check sits: at the end, or at the start in its own column (a picker of models). |
MenuRadioItem.closes | boolean | - | Picking closes the menu (a picker), instead of keeping it open. |
MenuLabel.children | ReactNode | required |
Accessibility
| Key | Does |
|---|---|
Enter / Space / Down | Opens the menu on the trigger |
Up / Down | Moves between items |
Home / End | First and last item |
A letter | Jumps to the item that starts with it |
Enter / Space | Chooses the item and closes |
Tab | Closes the menu |
Escape | Closes and returns focus to the trigger |
Disabled items are skipped by the arrow keys. Tab closes the menu and returns focus to the trigger. Check and radio items keep it open.
Accessibility