Context menu
The actions for one thing, at the pointer, on right-click or a long press.
Installation
npm i @uisatin/uiimport { ContextMenu, ContextMenuItem, ContextMenuSeparator } from '@uisatin/ui/context-menu'About 46.1 kB of JavaScript, minified and gzipped, with what it imports (React aside). The stylesheet is one file for every component.
npx shadcn@latest add https://uisatin.dev/r/context-menu.jsonAdds context-menu.tsx, dropdown.tsx, kbd.tsx, labels.tsx and pointer-modality.tsx to components/ui and installs iconoir-react and radix-ui.
First time with Satin? Set it up once, styles and fonts included, with the installation guide.
API Reference
The ContextMenu component opens on right-click or a long press of its trigger, at the pointer. ContextMenuItem, ContextMenuSub and ContextMenuSeparator build the list.
| Prop | Type | Default |
|---|---|---|
trigger | ReactNode | — |
children | ReactNode | — |
onOpenChange | (open: boolean) => void | — |
modal | boolean | true |
ContextMenuItem.label | string | — |
ContextMenuItem.icon | ReactNode | — |
ContextMenuItem.shortcut | string | — |
ContextMenuItem.destructive | boolean | — |
ContextMenuSub.label | string | — |
className | string | — |
ref | Ref<HTMLElement> | — |
...props | ComponentProps<typeof Context.Content>Other attributes go to the Radix Context.Content part | — |
Accessibility
A Radix context menu on the trigger, opened by the contextmenu event: right-click, a long press, or Shift+F10 and the menu key when the trigger has focus, so make the trigger focusable. The panel is a menu of menuitem rows; a submenu row has aria-haspopup="menu". Shortcuts are only shown. Keyboard and screen-reader users can’t always reach a context menu, so put the same actions somewhere else too.
| Key | Action |
|---|---|
| Shift+F10 | On the focused trigger: opens the menu, where the browser fires contextmenu. |
| ↑or↓ | Moves between items. |
| HomeorEnd | Moves to the first or last item. |
| A–Z | Moves to the next item whose label starts with the typed letters. |
| EnterorSpace | Runs the focused item, or opens its submenu. |
| → | Opens the submenu of the focused row. |
| ← | Closes the submenu and goes back to its row. |
| Esc | Closes the menu. |
Something wrong or missing on this page?
Report a problemSuggest an improvement