Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Context Menu examples · Standard

Context Menu with Labels for React

A context menu with My Account and Support sections under labels, and a destructive Log Out.

Framework
UI library

Two labeled sections, My Account with Profile and Settings and Support with Help Center, then Log Out at the end. Labels name each part of a longer menu so people scan sections instead of items.

Preview

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

FAQ

How are the section labels added?

Each label is a ContextMenuGroupLabel at the top of a ContextMenuGroup with the items it names. The label isn't selectable; screen readers announce it as the group's name.

Where do the separators go?

Between the sections and before Log Out, each a ContextMenuSeparator outside the groups.

How is the destructive item styled?

variant="destructive" on ContextMenuItem colors it with the destructive token, icon included. Keep it last, after a separator, and confirm with an Alert Dialog when it can't be undone.

How are the icons added?

A Lucide icon as the first child of each item, hidden from assistive tech since the label names the action. The menu styles size and space it.

How do I run an action when an item is chosen?

Pass onClick to each ContextMenuItem.

The menu closes after the action runs.

What opens the menu?

A right-click inside the dashed area, which reads Right click here on a mouse and Long press here on a touch screen. The area is ContextMenuTrigger; a long press on it opens the menu too. Wrap your own row, file or canvas in the trigger instead.