Skip to content
Klarhimmel UI

Context menu

Right-click here, or press Shift+F10.
npx shadcn add @klarhimmel/context-menu @klarhimmel/menu

Examples

  • Basic

  • Rows

  • Tiles

DetailsAbout, usage, props and more

The menu that opens where you right-click, and from the keyboard with the Menu key or Shift+F10.

When to use

  • Use for

    Row, tile and canvas actions for mouse and keyboard users.

  • Not for

    The only route to an action. Touch has no right-click: repeat the actions in a visible button.

  • Pairs with

    Menu, Icon button, tables and file grids.

Preview

Booking 4821

Right-click here, or focus it and press the Menu key or Shift+F10.

Nothing chosen yet.

context-menu.tsx
import { Theme } from '@/components/klarhimmel/theme/style';
import { ContextMenu } from '@/components/klarhimmel/ui/context-menu';
import { MenuItem } from '@/components/klarhimmel/ui/menu';

export default function Example() {
  return (
    <Theme theme="brand">
      <ContextMenu
        aria-label="Booking 4821"
        menu={<>
          <MenuItem>Open booking</MenuItem>
          <MenuItem danger>Cancel booking</MenuItem>
        </>}
      >
        Booking 4821
      </ContextMenu>
    </Theme>
  );
}

Import

Import

import { ContextMenu } from '@/components/klarhimmel/ui/context-menu';
Files
context-menu.tsx, menu.tsx, in components/klarhimmel/ui/. With it: 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.

Props

PropTypeDefaultDescription
aria-labelstringrequiredRequired: names the area. It is a tab stop, so keyboard users can reach the menu too.
childrenReactNoderequiredWhat the area shows.
menuReactNoderequiredThe menu: MenuItem, MenuLabel, MenuSeparator... from Menu.
classNamestring-Extra classes, merged after the component's own.

Accessibility

KeyDoes
Right-clickOpens the menu at the pointer
Menu key / Shift+F10Opens it at the focused element
Down / Up / Home / EndMove through the items
LettersJump to an item that starts with them
EscapeCloses and returns focus to the area

It is the same Menu as a button's menu. The area is a named tab stop so keyboard users can reach it.

Accessibility