Context Menu
A right-click menu that unfolds from the exact point you pressed, with the same gliding highlight as Menu.
See it as an AI agent does.See this component the way an AI agent does.
Installation
npx shadcn@latest add @keyframery/context-menuThis adds components/keyframery/context-menu.tsx and its primitive to your project, and installs UI SDK, along with menu, which it builds on. The motion tokens are added to your global CSS the first time you install a component.
Usage
import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuTrigger } from "@/components/keyframery/context-menu"
export default function Usage() {
return (
<ContextMenu>
<ContextMenuTrigger>Right-click here</ContextMenuTrigger>
<ContextMenuContent>
<ContextMenuItem value="copy">Copy</ContextMenuItem>
<ContextMenuItem value="paste">Paste</ContextMenuItem>
</ContextMenuContent>
</ContextMenu>
)
}Anatomy
How the parts fit together:
ContextMenu
├── ContextMenuTrigger
└── ContextMenuContent
└── ContextMenuItemExamples
Basic
Right-click the area, or long-press it on a touch screen. The menu opens at the pointer.
Submenu and checkable items
ContextMenuSub nests a menu. Checkbox and radio items stay open when chosen, so several can be set in one go.
Motion
| Move | What you see |
|---|---|
| Unfold | The menu grows from the exact point you pressed. |
| Cascade | Rows arrive one after another. |
| Glide | One highlight glides between items; submenus unfold sideways. |
Timing and springiness follow the motion style you set. To change how fast this context menu moves, pass speed:
<ContextMenu speed="fast">
…
</ContextMenu>"fast" is 0.6×, "slow" 1.4×, and a number sets the multiplier. With reduced motion turned on, nothing moves: changes happen at once or with a short fade.
Theming
Set these CSS variables on the component or a parent. Leave them unset to follow the light and dark theme. The open Customize panel below the preview lets you try these settings.
| Variable | What it changes | Default |
|---|---|---|
--context-menu-face | Menu sheet surface | --popover |
--context-menu-ink | Menu text | --popover-foreground |
--context-menu-accent | Row highlight | --accent |
--context-menu-danger | Destructive row text and highlight | --destructive |
--context-menu-radius | Sheet corners | 14px |
--context-menu-item-radius | Row corners | 8px |
--context-menu-row-height | Minimum row height | 2rem |
API reference
Every part takes className and children. Parts from UI SDK also take render, to draw your own element, and a function of their state for className and style. Props not listed here are in the UI SDK menu reference.
ContextMenu
Prop
Type
ContextMenuTrigger
Renders a <div>, and takes its props too.
Prop
Type
ContextMenuContent
Renders a <div>, and takes its props too.
Prop
Type
ContextMenuItem
Renders a <div>, and takes its props too.
Prop
Type
ContextMenuCheckboxItem
Renders a <div>, and takes its props too.
Prop
Type
ContextMenuItemIcon
Renders a <span>, and takes its props too.
Prop
Type
ContextMenuItemIndicator
Renders a <span>, and takes its props too.
Prop
Type
ContextMenuItems
Prop
Type
ContextMenuRadioGroup
Renders a <div>, and takes its props too.
Prop
Type
ContextMenuRadioItem
Renders a <div>, and takes its props too.
Prop
Type
ContextMenuSub
Prop
Type
ContextMenuSubContent
Renders a <div>, and takes its props too.
Prop
Type
ContextMenuSubTrigger
Renders a <div>, and takes its props too.
Prop
Type
MenuCheckboxItem
Renders a <div>, and takes its props too.
Prop
Type
MenuContent
Renders a <div>, and takes its props too.
Prop
Type
MenuItem
Renders a <div>, and takes its props too.
Prop
Type
MenuItemIndicator
Renders a <span>, and takes its props too.
Prop
Type
MenuRadioItem
Renders a <div>, and takes its props too.
Prop
Type
MenuSubContent
Renders a <div>, and takes its props too.
Prop
Type
MenuSubTrigger
Renders a <div>, and takes its props too.
Prop
Type
MenuTrigger
Renders a <button>, and takes its props too.
Prop
Type
Menu
Prop
Type
MenuContextTrigger
Renders a <div>, and takes its props too.
Prop
Type
MenuItemIcon
Renders a <span>, and takes its props too.
Prop
Type
MenuItems
Prop
Type
MenuRadioGroup
Renders a <div>, and takes its props too.
Prop
Type
MenuSub
Prop
Type
Other parts
These take the props of the element they render, and nothing else:
ContextMenuGroup: a<div>ContextMenuGroupLabel: a<div>ContextMenuSeparator: a<div>ContextMenuShortcut: a<span>MenuGroup: a<div>MenuGroupLabel: a<div>MenuSeparator: a<div>MenuShortcut: a<span>
Keyboard
| Key | What it does |
|---|---|
| Shift + F10 | Opens the menu on the focused area. |
| ↓ ↑ | Moves between items. |
| → | Opens a submenu. |
| ← | Closes a submenu. |
| Enter | Chooses the highlighted item. |
| Escape | Closes the menu. |
Accessibility
Keyboard, focus and screen-reader behaviour come from UI SDK and are not changed. More in Accessibility.
Swap the import
Already using UI SDK's menu with your own styles? Keep your markup and change one line. The primitive adds motion and nothing else.
// Before
import { … } from "@ui-sdk/react/menu"
// After: same parts, same props, now animated
import { … } from "@/components/keyframery/primitives/context-menu"Questions
How does the animated Context Menu for UI SDK move?
Unfold: The menu grows from the exact point you pressed. Cascade: Rows arrive one after another. Glide: One highlight glides between items; submenus unfold sideways.
Do I need Motion or Framer Motion for the animated Context Menu?
No. Every move is plain CSS, so there is nothing to install besides the component and UI SDK.
Can I keep my own styling and only take the motion?
Yes. Import from @/components/keyframery/primitives/context-menu instead. It has the same parts and props as @ui-sdk/react/menu and adds motion only.
What happens to the Context Menu when someone turns on reduced motion?
Nothing moves. State changes happen at once, or with a short fade.