Skip to content

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

Components

Free

Context Menu for UI SDK

Right-click or long-press an area to open its actions at the pointer. A context menu for React on UI SDK, with submenus, checkboxes and radio items.

On this page9 sections

A context menu opens at the pointer when someone right-clicks an area, or holds a finger on it on a touch screen, and lists the actions for whatever is under it: a file in a grid, a row in a table, a shape on a canvas. Inside that area it takes the place of the browser's own menu.

Nothing on screen says the menu is there, so put the same actions on a visible button too, usually a Dropdown Menu. An app's main commands belong in a Menubar.

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.

Anatomy

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

Usage

import {
  ContextMenu, ContextMenuContent, ContextMenuItem,
  ContextMenuSeparator, ContextMenuTrigger,
} from "@/components/ui/context-menu";
<ContextMenu>
  <ContextMenuTrigger className="flex h-32 w-full max-w-xs items-center justify-center rounded-xl border border-dashed text-sm">
    Right click here
  </ContextMenuTrigger>
  <ContextMenuContent className="w-48">
    <ContextMenuItem value="back">Back</ContextMenuItem>
    <ContextMenuItem value="reload">Reload</ContextMenuItem>
    <ContextMenuSeparator />
    <ContextMenuItem value="delete" variant="destructive">
      Delete
    </ContextMenuItem>
  </ContextMenuContent>
</ContextMenu>

Accessibility

The menu has role="menu", focus moves into it when it opens, and checkbox and radio rows report aria-checked. Focus moves onto each item in turn, disabled ones included, and typing a letter jumps to the next item that starts with it. The trigger is a div outside the tab order, so a keyboard user opens the menu only from a focusable element inside the area, with Shift + F10 or the Menu key, or from the area itself once it has a tabIndex of 0. Put the same actions on a visible button as well.

Shift+F10
When focus is on the trigger area or an element inside it, opens the menu on Windows and Linux, as the Menu key does, and moves focus to the first item.
Space
On an item, chooses it and closes the menu, while a checkbox or radio item toggles and the menu stays open. On a submenu trigger, opens the submenu.
Enter
On an item, chooses it and closes the menu, while a checkbox or radio item toggles and the menu stays open. On a submenu trigger, opens the submenu.
Arrow Down
Moves focus to the next item, and from the last one back to the first.
Arrow Up
Moves focus to the previous item, and from the first one to the last.
Arrow Right
On a submenu trigger, opens the submenu and moves focus into it. In a right-to-left menu, closes the submenu instead.
Arrow Left
In a submenu, closes it and moves focus back to its trigger. In a right-to-left menu, opens a submenu instead.
Home
Moves focus to the first item.
End
Moves focus to the last item.
Page Up
Moves focus to the first item, as Home does.
Page Down
Moves focus to the last item, as End does.
Tab
Closes the menu, submenus included.
Escape
Closes the menu, or only the submenu that has focus. A submenu returns focus to its trigger, and the whole menu to the trigger area when it can take focus, otherwise to where focus was before it opened.

Demos

Basic

Back, Forward and Reload in one short list, with disabled on Forward so it stays in view but can't be chosen. Start from this for a handful of actions on one object, such as a page or a file, where the whole list reads at a glance. Add groups and separators once it grows.

Preview width

File list

Four files, each row its own ContextMenu with the row inside ContextMenuTrigger, so Star and Delete act on the file that was right-clicked and nothing has to be read back from the click. Each row also has a tabIndex of 0, so Shift + F10 opens its menu from the keyboard. Reach for this shape in a file grid, a table or a list of messages.

Preview width

Copy and Cut sit at the top, and More Tools opens a second panel with Save Page, Create Shortcut and Name Window, then Developer Tools and a destructive Delete. Move the actions people reach for less often into a submenu so the first list stays short. Hovering More Tools opens it, and so do ArrowRight and Enter.

Preview width

Shortcuts

Back, Forward and Reload end in ⌘[, ⌘] and ⌘R, and Save and Save As below a separator end in ⌘S and ⇧⌘S. ContextMenuShortcut is a styled span that prints the hint and listens for nothing. Bind the keys yourself at the page level, where they work without opening the menu, and show a hint only for a shortcut that exists.

Preview width

Groups

File and Edit are labeled groups, Cut, Copy and Paste follow in a group with no label, and Delete sits alone at the end, each row with its shortcut. A ContextMenuGroupLabel names a section and can't be chosen, while a ContextMenuSeparator divides groups that need no name. Group a menu once it holds more than one kind of action.

Preview width

Icons

Copy, Cut and Paste each start with an icon, and Delete has a trash can below a separator. Every icon has aria-hidden, since the label already names the action. Icons pay off on familiar commands that people open the menu for again and again, and add little beside a label nobody would recognize from a picture.

Preview width

Checkboxes

Show Bookmarks Bar, Show Full URLs and Show Developer Tools are three ContextMenuCheckboxItem rows, each with checked and onCheckedChange held in state outside the menu, so the marks are still right the next time it opens. The menu stays open while people toggle them, so several settings can change in one visit.

Preview width

Radio

People offers Pedro Duarte and Colm Tuite, and Theme offers Light, Dark and System, each in its own ContextMenuRadioGroup with its value in state, so choosing a person leaves the theme alone. The menu stays open after a choice, so people can set both. Use radio rows for a mode with exactly one answer.

Preview width

Destructive

Edit and Share come first with their icons, then Delete below a separator with variant set to destructive, which colors the row as a warning. The variant changes the color and nothing else, so it asks for no confirmation. When the action can't be undone, open an Alert Dialog from the item, and keep the dangerous row last.

Preview width

Sides

Four dashed areas, labeled top, right, bottom and left, open the same Back, Forward and Reload list on that side of the pointer, through side on ContextMenuContent. Without it, the menu opens to the right of the pointer, and it flips to the other side when there's no room. Pin a side when the default would cover what people right-clicked.

Preview width

RTL

Arabic labels on two submenus, two view checkboxes and a people radio group, inside a right-to-left Direction provider, with dir set to rtl around the area and on each panel. UI SDK reads the direction each panel computes, so the menu and its submenus open to the left, ArrowLeft opens them, and the text and chevrons turn around. Use it on Arabic or Hebrew pages.

Preview width

FAQ

Should I use a Context Menu or a Dropdown Menu?

Use a Context Menu for actions on the thing under the pointer, such as a file in a grid, a row in a table or a shape on a canvas, where a button on every one would crowd the layout. Use a Dropdown Menu when the actions hang off a button people can see.

Nothing on screen tells people a right-click menu exists, so treat it as a shortcut rather than the only way in. Most apps offer the same list both ways: an ellipsis button on the row opens it as a dropdown, and a right-click anywhere on the row opens it at the pointer.

How do I run code when a Context Menu item is chosen?

Give each ContextMenuItem an onSelect, since an onClick runs for the pointer alone. UI SDK calls it for a pointer click and for Enter or Space, then closes the menu, unless the handler calls preventDefault on the event it receives, which keeps the menu open. To branch in one place instead, give each item a value and set onAction on ContextMenu, which receives it.

The handler acts on whatever was right-clicked, so it needs to know which row or file that was. Writing one menu per row, inside the row's own markup, puts that row's data in scope.

How do I know which row was right-clicked in a Context Menu?

Give each row its own ContextMenu, with the row inside ContextMenuTrigger, as the File list demo does. The item handlers are then written where that row's data is in scope, so Delete already knows which file to delete and nothing has to be read back from the click.

This doesn't make a long list heavy. Nothing inside a menu is rendered until it opens, so a table of a few hundred rows carries a few hundred triggers and one open menu at a time.

How do I keep the Context Menu open after toggling a checkbox item?

You don't need to do anything: UI SDK leaves the menu open when a ContextMenuCheckboxItem is toggled or a ContextMenuRadioItem is chosen, as the Checkboxes demo shows. Set closeOnSelect on the item when you'd rather it close after each change. Plain items close the menu unless their own closeOnSelect is false, or their onSelect calls preventDefault.

Does the Context Menu replace the browser's right-click menu?

Inside ContextMenuTrigger, yes. A right-click there cancels the browser's contextmenu event and opens your menu, so Inspect, Copy link and Open in new tab aren't offered in that area. Outside it, right-click works as usual.

Keep the trigger to the region that needs its own actions, such as a file grid or a canvas, and leave plain text, links and images out of it. People expect to copy a sentence or open a link in a new tab with a right-click, and inside the area they no longer can.

Does the Context Menu open with a long press on a phone?

Yes. UI SDK times the press itself and opens the menu where the finger is after 500 milliseconds, which also works in Safari on iOS, where no contextmenu event fires. Moving more than 10 pixels first cancels it, so a scroll that starts on the area doesn't open the menu.

A long press is even harder to discover than a right-click, so give touch users a visible way to the same actions. The demos swap their Right click here label for Long press here on touch screens.

Can keyboard users open a Context Menu?

Only from inside the area. ContextMenuTrigger renders a div outside the tab order, but Shift + F10 and the Menu key fire the browser's contextmenu event on whatever has focus, and that event bubbles up to the trigger. So the menu opens from a link or button inside the area, or from the area itself once you give it a tabIndex of 0.

Few people know these keys, so keep every action in the menu reachable from a visible control as well.

Why can't I scroll the page while a Context Menu is open?

Nothing locks it on UI SDK by default: modal on ContextMenu starts as "pointer", so the page keeps scrolling, and a click outside only closes the menu without reaching what it landed on. Set modal to true to also lock scroll, hold focus in the menu and make the rest of the page inert, or to false to let that click through. If scrolling stops anyway, something else has locked it, such as a modal dialog the menu sits in.

API Reference

ContextMenu

PropType
open?boolean

Whether the menu is open. Pass it to control the menu.

defaultOpen?boolean

Whether the menu starts open, when uncontrolled.

Default
false
onOpenChange?(open: boolean, details: ChangeDetails<MenuOpenChangeReason>) → void

Runs when the menu wants to open or close. details.reason says why, and details.cancel() stops it.

Type
(open: boolean, details: ChangeDetails<MenuOpenChangeReason>) → void
Parameters

open – boolean

details – ChangeDetails<MenuOpenChangeReason>

Returns
void
container?DocumentFragment | Element | null

Renders the popup into this element instead of in place, like a container inside a shadow root or an iframe. On web components, a CSS selector. Nested popups stay inside their parent.

Type
DocumentFragment | Element | null
controller?MenuController

Opens, closes and inspects the menu from anywhere, and connects triggers outside it. Create one with createMenuController().

debug?boolean

Logs every state change with its reason to the console, in development builds.

delay?number

Milliseconds the pointer rests on a submenu trigger before its submenu opens.

Default
100
dismissible?boolean

Whether Escape, an outside press, focus or the window leaving, Android's back gesture and a sheet's swipe can close it. Triggers, Close parts and the controller always can. Pass false while it holds unsaved work, and ask in onDismissAttempt.

Default
true
items?MenuData

The menu as data. Renders the content for you, unless you place a content part of your own, and runs the items' shortcuts.

itemShortcuts?boolean

Whether a data menu runs its items' shortcuts while closed.

Default
true
loop?boolean

Whether arrow keys wrap from the last item to the first.

Default
true
modal?"pointer" | boolean

"pointer": an outside press only closes the menu. true: also locks scroll, traps focus and makes the rest of the page inert. false: outside presses reach what they hit.

Type
"pointer" | boolean
Default
"pointer", or true while it presents as a sheet
onAction?(value: string, details: MenuActionDetails) → unknown

Runs for every plain item, including items in submenus, with the item's value. Return a Promise to mark the item pending until it settles: it gets data-pending, aria-busy and aria-disabled, the menu stays open, and choosing it again waits. It closes once the Promise resolves, and a rejection keeps it open with the reason in the item's error state until the next try.

Type
(value: string, details: MenuActionDetails) → unknown
Parameters

value – string

details – MenuActionDetails

Returns
unknown
onCheckedChange?(checked: boolean, details: MenuCheckedChangeDetails) → void

Runs when any checkbox item in the menu or its submenus toggles, with the item's value in details.value. Made for data menus.

Type
(checked: boolean, details: MenuCheckedChangeDetails) → void
Parameters

checked – boolean

details – MenuCheckedChangeDetails

Returns
void
onDismissAttempt?(details: DismissAttemptDetails<Extract<Reason, DismissAttemptReason>>) → void

Runs when dismissible refused a dismissal made on purpose: Escape, an outside press, back or a swipe. Focus or the window leaving is refused without it. Ask "Discard changes?" here.

Type
(details: DismissAttemptDetails<Extract<Reason, DismissAttemptReason>>) → void
Parameters

details – DismissAttemptDetails<Extract<Reason

DismissAttemptReason>>

Returns
void
onOpenChangeComplete?(open: boolean) → void

Runs once the menu has finished opening or closing, after any animation.

Parameters

open – boolean

Returns
void
onPayloadChange?(payload: unknown, details: ChangeDetails<MenuPayloadChangeReason>) → void

Runs when the payload the content shows changes: a trigger or context area with another payload opens the menu, or takes the open menu over, which fires no onOpenChange, and so does a controller's open({ payload }) on the open menu. details.cancel() keeps the previous payload.

Type
(payload: unknown, details: ChangeDetails<MenuPayloadChangeReason>) → void
Parameters

payload – unknown

details – ChangeDetails<MenuPayloadChangeReason>

Returns
void
onValueChange?(value: string, details: MenuValueChangeDetails) → void

Runs when any radio group in the menu or its submenus changes, with the group in details.group. Made for data menus.

Type
(value: string, details: MenuValueChangeDetails) → void
Parameters

value – string

details – MenuValueChangeDetails

Returns
void
pendingAnnouncement?string

What screen readers hear once an item has been pending for a second, so a slow action doesn't pass in silence. Set it in the page's language. An empty string says nothing.

Default
"Loading"
presentation?PresentationSetting<"popover">

How the menu presents. "sheet" slides it up from the bottom of the screen, where it can be swiped away and submenus open in its place, and "auto" does that on small touch screens. Decided each time it opens; the server renders "popover" for "auto". A context menu and a menu in a menubar are always popovers.

Type
PresentationSetting<"popover">
Default
"popover"

ContextMenuPortal

ContextMenuTrigger

<div> data-slot="menu-context-trigger"

PropType
controller?PopupController<any, MenuOpenChangeReason, MenuOpenOptions, string, MenuPayloadChangeReason>

Connects an area outside the menu to the menu with this controller.

Type
PopupController<any, MenuOpenChangeReason, MenuOpenOptions, string, MenuPayloadChangeReason>
disabled?boolean

Stops a right-click, a long press or Shift+F10 from opening the menu here. The browser's own menu shows instead.

Default
false
payload?unknown

Data for the content to render when this area opens the menu, like the row it belongs to.

render?ReactElement | ((props: object, state: object) => ReactElement)

Replace the host element or compose it with another component.

Type
ReactElement | ((props: object, state: object) => ReactElement)
className?string

Merged with the part's classes.

AttributeType
data-closed?string

Present on an area while the menu isn't open from it.

data-disabled?string

Present when the area is disabled.

data-open?string

Present on the area that opened the menu, while it's open.

ContextMenuContent

<div> data-slot="menu-content"

PropType
align?Align

How the popup lines up with the anchor along that side. start and end follow the reading direction. How the menu lines up with the trigger along that side.

Default
"start"
alignOffset?number

Shift along the anchor, in pixels. Shift along the trigger, in pixels. Submenus default to lining up their first item with the trigger.

Default
4
anchor?string | Anchor | null

Positions the popup against this instead of its trigger: an element, a CSS selector, a point like { x, y }, or anything with getBoundingClientRect(). It's read on every check, so it can move. A controller's open({ anchor }) wins for that open.

Type
string | Anchor | null
arrowPadding?number

Space to keep between the arrow and the popup's corners, in pixels.

Default
6
collisionPadding?number

Space to keep from the viewport edges, in pixels.

Default
8
container?DocumentFragment | Element | null

Renders the popup into this element instead of in place, like a container inside a shadow root or an iframe. On web components, a CSS selector. Nested popups stay inside their parent.

Type
DocumentFragment | Element | null
finalFocus?PopupFocusTarget

Where focus goes when the menu closes while focus is inside it. "trigger" returns it to the trigger and "none" leaves it. A CSS selector, an element or a function picks a specific element.

Default
"trigger"
keepMounted?boolean

Whether the menu stays in the page, hidden, while closed. Its content keeps its state between opens.

Default
false
side?ContextMenuSide

The side of the trigger it opens on. It flips when there's no room, unless avoidCollisions is off.

Default
"inline-end"
sideOffset?number

Gap between the anchor and the popup, in pixels. Gap between the trigger and the menu, in pixels. UI SDK's default: 4.

Default
0
render?ReactElement | ((props: object, state: object) => ReactElement)

Replace the host element or compose it with another component.

Type
ReactElement | ((props: object, state: object) => ReactElement)
className?string

Merged with the part's classes.

AttributeType
data-align"start" | "center" | "end"

How the menu lines up with its trigger.

Type
"start" | "center" | "end"
data-closed?string

Present while the menu is closed, including while it animates out.

data-ending-style?string

Present while the menu animates out. Style the state you animate to.

data-has-icons?string

Present while any item inside holds an icon part, so items without one can line up.

data-nested?string

Present on submenus.

data-open?string

Present while the menu is open. A submenu trigger has it while its submenu is open.

data-presentation"popover" | "sheet"

How the menu presents this time it's open. Submenus present like their root.

Type
"popover" | "sheet"
data-side"top" | "right" | "bottom" | "left"

Where the menu ended up, after flipping away from edges.

Type
"top" | "right" | "bottom" | "left"
data-starting-style?string

Present for the first frame. Style the state you animate from.

CSS variableType
--anchor-heightstring

Height of the anchor.

--anchor-widthstring

Width of the anchor, usually the trigger. Use it to match widths.

--arrow-offsetstring

Where the anchor's center falls along the popup's edge, kept arrowPadding from the corners. Position a ::before arrow with it.

--available-heightstring

Space between the anchor and the viewport edge. Use it for max-height. Not inherited, so a child that needs it copies it on the popup, like [--list-height:var(--available-height)], and reads max-h-(--list-height). The first popup registers both names for the whole page with CSS.registerProperty, so they don't inherit anywhere. A page that needs them to inherit calls it first, with inherits: true. An @property rule can't, since a registration in script wins.

--available-widthstring

Space beside the popup, up to the viewport edge. Not inherited either.

--drawer-dimstring

While it presents as a sheet: how dim the page behind is, from 0 to 1. The backdrop's opacity follows it.

--drawer-expandstring

While it presents as a sheet: 0 at the second-largest snap point and below, 1 at the largest. With one snap point, the whole travel.

--drawer-progressstring

While it presents as a sheet: how far open the sheet is, from 0 closed to 1 at its largest snap point. Never past 1.

--drawer-stackstring

While it presents as a sheet: how many sheets opened from inside this one are open above it, rising smoothly as each one opens. Push it back with it.

--sheet-backdropstring

Set it yourself: the color the page dims to while it presents as a sheet. Black at 0.2 by default.

--transform-originstring

The point on the anchor the popup opens from. Use it to scale from the right place.

ContextMenuGroup

<div>

PropType
render?ReactElement | ((props: object, state: object) => ReactElement)

Replace the host element or compose it with another component.

Type
ReactElement | ((props: object, state: object) => ReactElement)

ContextMenuGroupLabel

<div>

PropType
inset?boolean

Indents it to line up with items that have an icon or indicator.

render?ReactElement | ((props: object, state: object) => ReactElement)

Replace the host element or compose it with another component.

Type
ReactElement | ((props: object, state: object) => ReactElement)
className?string

Merged with the part's classes.

ContextMenuLabel

ContextMenuItem

<div> data-slot="menu-item"

PropType
closeOnSelect?boolean

Whether running the item closes the menu.

Default
true
destructive?boolean

Styles the item as dangerous, like Delete. Sets data-destructive.

disabled?boolean

Keeps the item focusable but stops it from running, as the menu pattern asks. Sets data-disabled and aria-disabled.

inset?boolean

Indents it to line up with items that have an icon or indicator.

label?string

The text typeahead matches, when the content isn't plain text. It isn't the accessible name: use aria-label for that.

onSelect?(event: Event) → unknown

Runs when the item is selected, by pointer or keyboard, with the event that selected it, or a new select Event when no DOM event did. Call event.preventDefault() to keep the menu open and skip onAction. Return a Promise to mark the item pending until it settles, like onAction.

Parameters

event – Event

Returns
unknown
shortcut?string

A keyboard shortcut like "mod+n". Shows ⌘N on Apple platforms and Ctrl+N elsewhere, and sets aria-keyshortcuts.

value?string

Passed to onAction when the item runs.

variant?"default" | "destructive"

The visual style.

Type
"default" | "destructive"
Default
"default"
render?ReactElement | ((props: object, state: object) => ReactElement)

Replace the host element or compose it with another component.

Type
ReactElement | ((props: object, state: object) => ReactElement)
className?string

Merged with the part's classes.

AttributeType
data-disabled?string

Present when the item can't be chosen.

data-has-icon?string

Present on an item while it holds an icon part.

data-highlighted?string

Present on the item with keyboard focus or under the pointer.

ContextMenuSub

ContextMenuSubTrigger

<div>

PropType
disabled?boolean

Keeps the submenu trigger focusable but stops it from opening its submenu, as the menu pattern asks. Sets data-disabled and aria-disabled.

inset?boolean

Indents it to line up with items that have an icon or indicator.

render?ReactElement | ((props: object, state: object) => ReactElement)

Replace the host element or compose it with another component.

Type
ReactElement | ((props: object, state: object) => ReactElement)
className?string

Merged with the part's classes.

ContextMenuSubContent

<div> data-slot="menu-content"

PropType
align?Align

How the popup lines up with the anchor along that side. start and end follow the reading direction. How the menu lines up with the trigger along that side.

Default
"start"
alignOffset?number

Shift along the anchor, in pixels. Shift along the trigger, in pixels. Submenus default to lining up their first item with the trigger.

Default
4
anchor?string | Anchor | null

Positions the popup against this instead of its trigger: an element, a CSS selector, a point like { x, y }, or anything with getBoundingClientRect(). It's read on every check, so it can move. A controller's open({ anchor }) wins for that open.

Type
string | Anchor | null
arrowPadding?number

Space to keep between the arrow and the popup's corners, in pixels.

Default
6
collisionPadding?number

Space to keep from the viewport edges, in pixels.

Default
8
container?DocumentFragment | Element | null

Renders the popup into this element instead of in place, like a container inside a shadow root or an iframe. On web components, a CSS selector. Nested popups stay inside their parent.

Type
DocumentFragment | Element | null
finalFocus?PopupFocusTarget

Where focus goes when the menu closes while focus is inside it. "trigger" returns it to the trigger and "none" leaves it. A CSS selector, an element or a function picks a specific element.

Default
"trigger"
keepMounted?boolean

Whether the menu stays in the page, hidden, while closed. Its content keeps its state between opens.

Default
false
side?ContextMenuSide

The side of the trigger it opens on. It flips when there's no room, unless avoidCollisions is off.

Default
"inline-end"
sideOffset?number

Gap between the anchor and the popup, in pixels. Gap between the trigger and the menu, in pixels. UI SDK's default: 4.

Default
0
render?ReactElement | ((props: object, state: object) => ReactElement)

Replace the host element or compose it with another component.

Type
ReactElement | ((props: object, state: object) => ReactElement)
className?string

Merged with the part's classes.

AttributeType
data-align"start" | "center" | "end"

How the menu lines up with its trigger.

Type
"start" | "center" | "end"
data-closed?string

Present while the menu is closed, including while it animates out.

data-ending-style?string

Present while the menu animates out. Style the state you animate to.

data-has-icons?string

Present while any item inside holds an icon part, so items without one can line up.

data-nested?string

Present on submenus.

data-open?string

Present while the menu is open. A submenu trigger has it while its submenu is open.

data-presentation"popover" | "sheet"

How the menu presents this time it's open. Submenus present like their root.

Type
"popover" | "sheet"
data-side"top" | "right" | "bottom" | "left"

Where the menu ended up, after flipping away from edges.

Type
"top" | "right" | "bottom" | "left"
data-starting-style?string

Present for the first frame. Style the state you animate from.

CSS variableType
--anchor-heightstring

Height of the anchor.

--anchor-widthstring

Width of the anchor, usually the trigger. Use it to match widths.

--arrow-offsetstring

Where the anchor's center falls along the popup's edge, kept arrowPadding from the corners. Position a ::before arrow with it.

--available-heightstring

Space between the anchor and the viewport edge. Use it for max-height. Not inherited, so a child that needs it copies it on the popup, like [--list-height:var(--available-height)], and reads max-h-(--list-height). The first popup registers both names for the whole page with CSS.registerProperty, so they don't inherit anywhere. A page that needs them to inherit calls it first, with inherits: true. An @property rule can't, since a registration in script wins.

--available-widthstring

Space beside the popup, up to the viewport edge. Not inherited either.

--drawer-dimstring

While it presents as a sheet: how dim the page behind is, from 0 to 1. The backdrop's opacity follows it.

--drawer-expandstring

While it presents as a sheet: 0 at the second-largest snap point and below, 1 at the largest. With one snap point, the whole travel.

--drawer-progressstring

While it presents as a sheet: how far open the sheet is, from 0 closed to 1 at its largest snap point. Never past 1.

--drawer-stackstring

While it presents as a sheet: how many sheets opened from inside this one are open above it, rising smoothly as each one opens. Push it back with it.

--sheet-backdropstring

Set it yourself: the color the page dims to while it presents as a sheet. Black at 0.2 by default.

--transform-originstring

The point on the anchor the popup opens from. Use it to scale from the right place.

ContextMenuCheckboxItem

<div> data-slot="menu-checkbox-item"

PropType
checked?boolean

Whether the item is checked. Pass it to control the item.

defaultChecked?boolean

Whether the item starts checked, when uncontrolled.

Default
false
onCheckedChange?(checked: boolean, details: ChangeDetails<MenuCheckedChangeReason>) → void

Runs when the item wants to toggle. details.reason says why, and details.cancel() stops it.

Type
(checked: boolean, details: ChangeDetails<MenuCheckedChangeReason>) → void
Parameters

checked – boolean

details – ChangeDetails<MenuCheckedChangeReason>

Returns
void
closeOnSelect?boolean

Whether toggling closes the menu.

Default
false
disabled?boolean

Keeps the item focusable but stops it from toggling, as the menu pattern asks.

inset?boolean

Indents it to line up with items that have an icon or indicator.

label?string

The text typeahead matches, when the content isn't plain text. It isn't the accessible name: use aria-label for that.

value?string

Names the item in the menu's onCheckedChange; a generated id without one.

Default
id
render?ReactElement | ((props: object, state: object) => ReactElement)

Replace the host element or compose it with another component.

Type
ReactElement | ((props: object, state: object) => ReactElement)
className?string

Merged with the part's classes.

AttributeType
data-checked?string

Present on checked checkbox items, and on the radio item that's its group's value.

data-highlighted?string

Present on the item with keyboard focus or under the pointer.

data-inset?string

Mirrors inset.

data-unchecked?string

Present on items that aren't checked.

ContextMenuRadioGroup

<div>

PropType
value?T | null

The selected value. Pass it to control the group. null selects nothing.

Type
T | null
defaultValue?T | null

The value selected at first, when uncontrolled.

Type
T | null
onValueChange?(value: T, details: ChangeDetails<MenuValueChangeReason>) → void

Runs when the selection wants to change. details.reason says why, and details.cancel() stops it.

Type
(value: T, details: ChangeDetails<MenuValueChangeReason>) → void
Parameters

value – T

details – ChangeDetails<MenuValueChangeReason>

Returns
void
name?string

Identifies the group in the menu's onValueChange. Defaults to a generated id, and the group then keeps its choice by its place among the menu's groups. Give a group that's shown only some of the time a name, so it keeps its own.

render?ReactElement | ((props: object, state: object) => ReactElement)

Replace the host element or compose it with another component.

Type
ReactElement | ((props: object, state: object) => ReactElement)

ContextMenuRadioItem

<div> data-slot="menu-radio-item"

PropType
valuestring

Selected in the group when the item is chosen.

closeOnSelect?boolean

Whether choosing the item closes the menu.

Default
false
disabled?boolean

Keeps the item focusable but stops it from being chosen, as the menu pattern asks.

inset?boolean

Indents it to line up with items that have an icon or indicator.

label?string

The text typeahead matches, when the content isn't plain text. It isn't the accessible name: use aria-label for that.

render?ReactElement | ((props: object, state: object) => ReactElement)

Replace the host element or compose it with another component.

Type
ReactElement | ((props: object, state: object) => ReactElement)
className?string

Merged with the part's classes.

AttributeType
data-checked?string

Present on checked checkbox items, and on the radio item that's its group's value.

data-highlighted?string

Present on the item with keyboard focus or under the pointer.

data-unchecked?string

Present on items that aren't checked.

ContextMenuSeparator

<div> data-slot="menu-separator"

PropType
render?ReactElement | ((props: object, state: object) => ReactElement)

Replace the host element or compose it with another component.

Type
ReactElement | ((props: object, state: object) => ReactElement)
className?string

Merged with the part's classes.

ContextMenuShortcut

<span> data-slot="context-menu-shortcut"

PropType
className?string

Merged with the part's classes.