Keyframery

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.

Resize preview. Focus the handle and use the left or right arrow keys. Hold Shift for larger steps.— px
Customize1 controls
Animation speed1×

Installation

npx shadcn@latest add @keyframery/context-menu

This 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
    └── ContextMenuItem

Examples

Basic

Right-click the area, or long-press it on a touch screen. The menu opens at the pointer.

ContextMenuSub nests a menu. Checkbox and radio items stay open when chosen, so several can be set in one go.

Motion

MoveWhat you see
UnfoldThe menu grows from the exact point you pressed.
CascadeRows arrive one after another.
GlideOne 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.

VariableWhat it changesDefault
--context-menu-faceMenu sheet surface--popover
--context-menu-inkMenu text--popover-foreground
--context-menu-accentRow highlight--accent
--context-menu-dangerDestructive row text and highlight--destructive
--context-menu-radiusSheet corners14px
--context-menu-item-radiusRow corners8px
--context-menu-row-heightMinimum row height2rem

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

Renders a <div>, and takes its props too.

Prop

Type

Renders a <div>, and takes its props too.

Prop

Type

Renders a <div>, and takes its props too.

Prop

Type

Renders a <span>, and takes its props too.

Prop

Type

Renders a <div>, and takes its props too.

Prop

Type

Renders a <div>, and takes its props too.

Prop

Type

Renders a <div>, and takes its props too.

Prop

Type

Renders a <button>, and takes its props too.

Prop

Type

Prop

Type

Renders a <div>, and takes its props too.

Prop

Type

Renders a <span>, and takes its props too.

Prop

Type

Prop

Type

Renders a <div>, and takes its props too.

Prop

Type

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

KeyWhat it does
Shift + F10Opens the menu on the focused area.
↓ ↑Moves between items.
→Opens a submenu.
←Closes a submenu.
EnterChooses the highlighted item.
EscapeCloses 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.

All components

On this page