Skip to content
Klarhimmel UI

Menu

npx shadcn add @klarhimmel/menu @klarhimmel/button

Examples

  • 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

menu.tsx
import { Theme } from '@/components/klarhimmel/theme/style';
import { Button } from '@/components/klarhimmel/ui/button';
import { Menu, MenuTrigger, MenuContent, MenuItem, MenuSeparator } from '@/components/klarhimmel/ui/menu';

export default function Example() {
  return (
    <Theme theme="brand">
      <Menu>
        <MenuTrigger asChild><Button variant="secondary">Actions</Button></MenuTrigger>
        <MenuContent>
          <MenuItem onSelect={() => console.log('rename')}>Rename</MenuItem>
          <MenuSeparator />
          <MenuItem danger onSelect={() => console.log('delete')}>Delete</MenuItem>
        </MenuContent>
      </Menu>
    </Theme>
  );
}

Import

Import

import { Menu, MenuTrigger, MenuContent, MenuItem, MenuCheckItem, MenuRadioGroup, MenuRadioItem, MenuLabel, MenuSeparator } from '@/components/klarhimmel/ui/menu';
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.

Menu
├─ MenuTrigger (asChild)
└─ MenuContent
   ├─ MenuLabel
   ├─ MenuItem / MenuCheckItem
   └─ MenuSeparator
  • 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

PropTypeDefaultDescription
MenuContent.childrenReactNoderequired
MenuContent.align'start' | 'center' | 'end''start'
MenuContent.side'top' | 'right' | 'bottom' | 'left''bottom'Where it opens; it flips to stay on screen.
MenuContent.classNamestring-
MenuContent.onCloseAutoFocus(e: Event) => void-
MenuItem.iconReactNode-
MenuItem.shortcutstring-A leading icon and a trailing shortcut hint.
MenuItem.dangerboolean-
MenuItem.childrenReactNoderequired
MenuItem.onSelect() => void-
MenuItem.disabledboolean-Destructive tint; disabled items are skipped by the arrow keys.
MenuCheckItem.checkedbooleanrequired
MenuCheckItem.onCheckedChange(checked: boolean) => voidrequiredAn item that toggles. The menu stays open, so several can be changed in one visit.
MenuCheckItem.childrenReactNoderequired
MenuRadioGroup.valuestringrequired
MenuRadioGroup.onValueChange(value: string) => voidrequired
MenuRadioGroup.childrenReactNoderequired
MenuRadioItem.valuestringrequired
MenuRadioItem.childrenReactNoderequired
MenuRadioItem.descriptionReactNode-A second, quieter line under the name (what a model is for).
MenuRadioItem.badgeReactNode-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.closesboolean-Picking closes the menu (a picker), instead of keeping it open.
MenuLabel.childrenReactNoderequired

Accessibility

KeyDoes
Enter / Space / DownOpens the menu on the trigger
Up / DownMoves between items
Home / EndFirst and last item
A letterJumps to the item that starts with it
Enter / SpaceChooses the item and closes
TabCloses the menu
EscapeCloses 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