Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Context Menu examples · Standard

Context Menu with Checkboxes for React

A context menu of view options that toggle on and off, such as Show Bookmarks Bar.

Framework
UI library

Three view options, Show Bookmarks Bar, Show Full URLs and Show Sidebar, each with a check mark when it is on. Use checkbox items for settings that are independent of each other.

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 checked states kept?

Each ContextMenuCheckboxItem is uncontrolled, with defaultChecked on Show Bookmarks Bar and Show Sidebar. Pass checked and onCheckedChange to control them.

Does the menu stay open after a toggle?

Checkbox items keep the menu open by default.

How is the state announced?

Each item is a menu item checkbox, so screen readers say whether it is checked; the check mark is only visual.

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.

How do keyboard and touch users find these actions?

The arrow keys move through an open menu, Enter runs an item and Escape closes it. A right-click is easy to miss, so also offer the same actions from a visible button, such as a Dropdown Menu.

Why is Show Sidebar apart?

A ContextMenuSeparator sets it off from the two address bar options, in a group of its own.