Skip to content

shadcn.io is an independent project built on shadcn/ui

Free

Context Menu with Checkboxes for Solid

A right-click menu of view options. Show Bookmarks Bar and Show Sidebar start checked. Show Full URLs does not.

UI library: Ark UI

The dashed area reads Right click here. Show Bookmarks Bar starts checked, Show Full URLs does not, and a separator sets Show Sidebar apart. Show Sidebar starts checked.

Use checkbox items for view settings that are independent of each other. Repeat them in a Dropdown Menu so they are not only on right-click. In Solid, Ark UI does not decide the page layout.

Preview

Preview width

Installation

MCP · Pro
Make your AI a shadcn expert
Your agent installs components, builds pages and restyles your app from one prompt, in Claude Code, Cursor or VS Code.
Part of Pro

Anatomy

Context Menu anatomy: trigger, item, sub trigger, separator, item indicator, content

Usage

<ContextMenu>
      <ContextMenuTrigger class="flex h-[200px] w-full max-w-lg items-center justify-center rounded-md border border-dashed text-sm">
        <span class="pointer-fine:inline-block hidden">
          Right click here
        </span>
        <span class="pointer-coarse:inline-block hidden">
          Long press here
        </span>
      </ContextMenuTrigger>
      <ContextMenuContent class="w-56">
        <ContextMenuGroup>
          <ContextMenuCheckboxItem checked={showBookmarks()} onCheckedChange={setShowBookmarks} value="bookmarks-bar">
            Show Bookmarks Bar
          </ContextMenuCheckboxItem>
          <ContextMenuCheckboxItem checked={showFullUrls()} onCheckedChange={setShowFullUrls} value="full-urls">
            Show Full URLs
          </ContextMenuCheckboxItem>
        </ContextMenuGroup>
        <ContextMenuSeparator />
        <ContextMenuGroup>
          <ContextMenuCheckboxItem checked={showSidebar()} onCheckedChange={setShowSidebar} value="sidebar">
            Show Sidebar
          </ContextMenuCheckboxItem>
        </ContextMenuGroup>
      </ContextMenuContent>
    </ContextMenu>

FAQ

How are the checked states kept?

Each ContextMenuCheckboxItem is controlled: checked comes from state and onCheckedChange updates it, and each has a value.

Does the menu stay open after a toggle?

It closes; set closeOnSelect to false on the item to keep it open.

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.

API Reference

Context Menu

Sets checked={showBookmarks()}, onCheckedChange={setShowBookmarks}, value="bookmarks-bar", checked={showFullUrls()}, onCheckedChange={setShowFullUrls} and value="full-urls". The rest is on the Context Menu page.