Skip to content

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

Free

Context Menu with Radio Items for Svelte

A right-click menu labeled Panel Position, with Top, Bottom, Right, and Left, and Bottom selected.

UI library: Ark UI

The dashed area reads Right click here. A Panel Position label sits over Top, Bottom, Right, and Left. Bottom starts selected.

Use radio items when exactly one option applies. A Radio Group on the page is better if the choice should stay visible. In Svelte, Ark UI keeps a single position selected.

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><ContextMenuGroupLabel>Panel Position</ContextMenuGroupLabel><ContextMenuRadioGroup onValueChange={handlePositionChange} value={position}><ContextMenuRadioItem value="top">Top</ContextMenuRadioItem><ContextMenuRadioItem value="bottom">Bottom</ContextMenuRadioItem><ContextMenuRadioItem value="right">Right</ContextMenuRadioItem><ContextMenuRadioItem value="left">Left</ContextMenuRadioItem></ContextMenuRadioGroup></ContextMenuGroup></ContextMenuContent></ContextMenu>

FAQ

How is the selection kept?

ContextMenuRadioGroup is controlled: value comes from state and onValueChange receives { value }.

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.

How is the choice announced?

Each option is a menu item radio, so screen readers say which one is checked; the 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.

How wide is the menu?

w-56 on the popup, enough for the label and the options.

API Reference

Context Menu

Sets onValueChange={handlePositionChange}, value={position}, value="top", value="bottom", value="right" and value="left". The rest is on the Context Menu page.