Introducing PrimeReact v11-alpha 🎉Discover Now

ContextMenu

An unstyled, accessible context menu component with compound composition for right-click actions.

Build fully custom right-click menus with complete control over layout and styling.

basic-demo

Pre-styled Versions

Choose a pre-styled library to use ContextMenu with ready-made designs.
For hook-based usage without components, see the Headless API.

Features#

  • Compound component API with sub-components: Root, Trigger, Portal, Positioner, Popup, Arrow, List, Item, Sub, SubTrigger, SubPortal, SubPositioner, SubPopup, Indicator, Label, Separator, RadioGroup
  • Right-click activation with automatic cursor-based popup positioning
  • Global mode to attach context menu to the entire document
  • Nested submenus with open/close coordination
  • Checkbox and radio item types with indicator matching
  • Built-in character search to jump to items by typing

Usage#

import { ContextMenu } from 'primereact/contextmenu';
<ContextMenu.Root>
    <ContextMenu.Trigger></ContextMenu.Trigger>
    <ContextMenu.Portal>
        <ContextMenu.Positioner>
            <ContextMenu.Popup>
                <ContextMenu.Arrow />
                <ContextMenu.List>
                    <ContextMenu.Label></ContextMenu.Label>
                    <ContextMenu.Item></ContextMenu.Item>
                    <ContextMenu.Separator />
                    <ContextMenu.Submenu>
                        <ContextMenu.SubmenuTrigger>
                            <ContextMenu.Indicator />
                        </ContextMenu.SubmenuTrigger>
                        <ContextMenu.SubmenuPortal>
                            <ContextMenu.SubmenuPositioner>
                                <ContextMenu.SubmenuPopup>
                                    <ContextMenu.List>
                                        <ContextMenu.Item></ContextMenu.Item>
                                    </ContextMenu.List>
                                </ContextMenu.SubmenuPopup>
                            </ContextMenu.SubmenuPositioner>
                        </ContextMenu.SubmenuPortal>
                    </ContextMenu.Submenu>
                </ContextMenu.List>
            </ContextMenu.Popup>
        </ContextMenu.Positioner>
    </ContextMenu.Portal>
</ContextMenu.Root>

Behavior#

Checkbox Items#

Set type="checkbox" on ContextMenu.Item to create a toggleable item. Use ContextMenu.Indicator with match="checked" to display a checkmark when the item is active.

<ContextMenu.Item type="checkbox" defaultChecked={true}>
    <ContextMenu.Indicator match="checked">
        <Check />
    </ContextMenu.Indicator>
    Enable Notifications
</ContextMenu.Item>

Radio Items#

Wrap ContextMenu.Item elements with type="radio" inside a ContextMenu.RadioGroup. Use ContextMenu.Indicator with match="checked" to display a dot or icon for the selected option.

<ContextMenu.RadioGroup defaultValue="light">
    <ContextMenu.Item type="radio" value="light">
        <ContextMenu.Indicator match="checked">
            <Dot />
        </ContextMenu.Indicator>
        Light Mode
    </ContextMenu.Item>
    <ContextMenu.Item type="radio" value="dark">
        <ContextMenu.Indicator match="checked">
            <Dot />
        </ContextMenu.Indicator>
        Dark Mode
    </ContextMenu.Item>
</ContextMenu.RadioGroup>

Motion Animation#

<ContextMenu.Popup motionProps={{ name: 'p-anchored-overlay' }}></ContextMenu.Popup>

See Motion for animation phases, CSS variables, and hide strategies.

Polymorphic Rendering#

Use as on any sub-component to change the rendered HTML element.

<ContextMenu.Item as="a" href="/dashboard">
    Dashboard
</ContextMenu.Item>

Default elements: Root=div, Trigger=div, List=ul, Item=li, Sub=li, SubTrigger=div, SubPositioner=div, SubPopup=div, Label=li, Separator=li, Indicator=span, Popup=div, Positioner=div, Arrow=div, RadioGroup=div, Portal=portal, SubPortal=portal.

Render Function Children#

Item and SubTrigger accept a render function as children, providing access to the component instance.

<ContextMenu.Item>{(instance) => <span>{instance.focused ? 'Focused' : 'Idle'}</span>}</ContextMenu.Item>

Pass Through#

Some parts may not be visible in the preview depending on the component's current state.

Loading...
/* Select a part to see its CSS selector for custom styling */

API#

ContextMenuRoot#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: ContextMenuRootInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: ContextMenuRootInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceContextMenuRootInstance—
The instance to pass to the component.
ptSafeRecord<ContextMenuRootPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: ContextMenuRootInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
globalbooleanfalse
Attaches the menu to document instead of a particular element.
openboolean—
Controlled open state of the menu.
defaultOpenbooleanfalse
Default open state for uncontrolled mode.
appendTo"body" | HTMLElement | "self"'body'
The element to which the overlay is appended.
baseZIndexnumber0
Base zIndex value to use in layering.
autoZIndexbooleantrue
Whether to automatically manage layering.
tabIndexnumber0
Index of the element in tabbing order.
openDelaynumber100
The delay in milliseconds before opening the menu when hovering the trigger. Only applies when `openOnHover` is true.
closeDelaynumber0
The delay in milliseconds before closing the menu when the pointer leaves the trigger. Only applies when `openOnHover` is true.
openOnHoverbooleanfalse
When true, the menu opens on pointer hover over the trigger (in addition to click).
contextuseMenuSubmenuExposes—
Optional parent submenu context whose popover state should drive this menu. When provided, useMenu reuses the parent submenu's popover (anchor, open state, positioner) instead of creating its own. Forwarded by Menu.Root automatically when nested inside a Menu.Submenu.
navigationmenuuseNavigationMenuExposes—
Optional parent NavigationMenu context. When provided, ArrowRight / ArrowLeft pressed on a list item that is not a submenu trigger will move focus to the next / previous sibling navigationmenu trigger (WAI-ARIA NavigationMenu pattern). Forwarded by Menu.Root when nested inside a `NavigationMenu` .
navigationmenuMenuIdstring—
The id this menu is registered under in the parent NavigationMenu's trigger registry. Required for `navigationmenu` sibling navigation to know which trigger is "current".
onOpenChange(event: ContextMenuRootChangeEvent) => void—
Callback function that is called when the trigger is clicked.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"contextmenu"
data-part"root"

Defines passthrough(pt) options of ContextMenu component.

labeltypedescription
rootMenuRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.
listMenuRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the list's DOM element.
itemMenuRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the item's DOM element.
labelMenuRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the label's DOM element.
subMenuRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the submenu's DOM element.
triggerMenuRootPassThroughType<HTMLAttributes<HTMLButtonElement>>Used to pass attributes to the trigger's DOM element.
subtriggerMenuRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the subtrigger's DOM element.
checkboxItemIndicatorMenuRootPassThroughType<HTMLAttributes<HTMLSpanElement>>Used to pass attributes to the checkbox item indicator's DOM element.
radioItemIndicatorMenuRootPassThroughType<HTMLAttributes<HTMLSpanElement>>Used to pass attributes to the radio item indicator's DOM element.
submenuIndicatorMenuRootPassThroughType<HTMLAttributes<HTMLSpanElement>>Used to pass attributes to the submenu indicator's DOM element.
separatorMenuRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the separator's DOM element.
popupMenuRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the popup's DOM element.
arrowMenuRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the arrow's DOM element.
positionerMenuRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the positioner's DOM element.
subpositionerMenuRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the subpositioner's DOM element.
subpopupMenuRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the subpopup's DOM element.
subportalMenuRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the subportal's DOM element.

ContextMenuTrigger#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: ContextMenuTriggerInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: ContextMenuTriggerInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceContextMenuTriggerInstance—
The instance to pass to the component.
ptSafeRecord<ContextMenuTriggerPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: ContextMenuTriggerInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"contextmenu"
data-part"trigger"

Defines passthrough(pt) options of ContextMenuTrigger component.

labeltypedescription
rootContextMenuTriggerPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

ContextMenuList#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: ContextMenuListInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: ContextMenuListInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceContextMenuListInstance—
The instance to pass to the component.
ptSafeRecord<ContextMenuListPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: ContextMenuListInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"contextmenu"
data-part"list"

Defines passthrough(pt) options of ContextMenuList component.

labeltypedescription
rootMenuListPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.
contentMenuListPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the content's DOM element.

ContextMenuItem#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: ContextMenuItemInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: ContextMenuItemInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceContextMenuItemInstance—
The instance to pass to the component.
ptSafeRecord<ContextMenuItemPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: ContextMenuItemInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
disabledboolean—
When present, it specifies that the item should be disabled.
valuestring—
Semantic value that uniquely identifies this item within the menu. Used to generate a deterministic DOM id. When not provided, auto-generated.
closeOnSelectbooleantrue
Whether the menu should close when this item is activated. Overrides the `closeOnSelect` setting on `ContextMenu.Root` for this item only.
onSelect(event: MenuItemSelectEvent) => void—
Callback fired when the item is activated (click or keyboard). Calling `event.preventDefault()` keeps the menu open regardless of `closeOnSelect` .
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"contextmenu"
data-part"item"
data-valueThe item value
data-focusedPresent when item is focused
data-disabledPresent when item is disabled
data-checkedPresent when item is checked

Defines passthrough(pt) options of ContextMenuItem component.

labeltypedescription
rootContextMenuItemPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

ContextMenuSubmenu#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: ContextMenuSubmenuInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: ContextMenuSubmenuInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceContextMenuSubmenuInstance—
The instance to pass to the component.
ptSafeRecord<ContextMenuSubmenuPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: ContextMenuSubmenuInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
valuestring—
Semantic value identifying this submenu.
disabledbooleanfalse
Whether the submenu is disabled.
onOpenChange(event: ContextMenuSubmenuOpenChangeEvent) => void—
Callback fired when the submenu's open state changes.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"contextmenu"
data-part"sub"
data-openPresent when submenu is open

Defines passthrough(pt) options of ContextMenuSubmenu component.

labeltypedescription
rootMenuSubmenuPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

ContextMenuSubmenuTrigger#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: ContextMenuSubmenuTriggerInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: ContextMenuSubmenuTriggerInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceContextMenuSubmenuTriggerInstance—
The instance to pass to the component.
ptSafeRecord<ContextMenuSubmenuTriggerPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: ContextMenuSubmenuTriggerInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"contextmenu"
data-part"subtrigger"
data-valueThe subtrigger value
data-focusedPresent when subtrigger is focused
data-disabledPresent when subtrigger is disabled
data-openPresent when submenu is open

Defines passthrough(pt) options of ContextMenuSubmenuTrigger component.

labeltypedescription
rootMenuSubmenuTriggerPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

ContextMenuSubmenuPositioner#

AttributeValue
data-scope"contextmenu"
data-part"subpositioner"

CSS Custom Properties

The positioner element exposes CSS custom properties for layout and transform control.

CSS VariableDescription
--available-heightAvailable vertical space in pixels
--available-widthAvailable horizontal space in pixels
--transform-originComputed transform origin for animations
--positioner-anchor-widthWidth of the anchor/trigger element

ContextMenuSubmenuPortal#

ContextMenuSubmenuPopup#

AttributeValue
data-scope"contextmenu"
data-part"subpopup"

ContextMenuIndicator#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: ContextMenuIndicatorInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: ContextMenuIndicatorInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceContextMenuIndicatorInstance—
The instance to pass to the component.
ptSafeRecord<ContextMenuIndicatorPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: ContextMenuIndicatorInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
match"checked" | "unchecked" | "open" | "closed"—
Determines which state the indicator should match to render its content.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"contextmenu"
data-part"indicator"
data-openPresent when submenu is open
data-closedPresent when submenu is closed
data-checkedPresent when item is checked
data-uncheckedPresent when item is unchecked

Defines passthrough(pt) options of ContextMenuIndicator component.

labeltypedescription
rootMenuIndicatorPassThroughType<HTMLAttributes<HTMLSpanElement>>Used to pass attributes to the root's DOM element.

ContextMenuLabel#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: ContextMenuLabelInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: ContextMenuLabelInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceContextMenuLabelInstance—
The instance to pass to the component.
ptSafeRecord<ContextMenuLabelPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: ContextMenuLabelInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"contextmenu"
data-part"label"

Defines passthrough(pt) options of ContextMenuLabel component.

labeltypedescription
rootMenuLabelPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

ContextMenuSeparator#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: ContextMenuSeparatorInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: ContextMenuSeparatorInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceContextMenuSeparatorInstance—
The instance to pass to the component.
ptSafeRecord<ContextMenuSeparatorPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: ContextMenuSeparatorInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"contextmenu"
data-part"separator"

Defines passthrough(pt) options of ContextMenuSeparator component.

labeltypedescription
rootMenuSeparatorPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

ContextMenuRadioGroup#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: ContextMenuRadioGroupInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: ContextMenuRadioGroupInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceContextMenuRadioGroupInstance—
The instance to pass to the component.
ptSafeRecord<ContextMenuRadioGroupPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: ContextMenuRadioGroupInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
valueunknown—
Value of the selected radio item.
defaultValueunknown—
Default value of the selected radio item.
namestring—
Name for the radio group.
onValueChange(event: ContextMenuRadioGroupValueChangeEvent) => void—
Callback to invoke when value changes.
[key: string]any—
AttributeValue
data-scope"contextmenu"
data-part"radiogroup"

ContextMenuPopup#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: ContextMenuPopupInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: ContextMenuPopupInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceContextMenuPopupInstance—
The instance to pass to the component.
ptSafeRecord<ContextMenuPopupPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: ContextMenuPopupInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
motionPropsuseMotionProps—
Motion properties for the popup animation.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"contextmenu"
data-part"popup"

Defines passthrough(pt) options of ContextMenuPopup component.

labeltypedescription
rootMenuPopupPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

ContextMenuPositioner#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: ContextMenuPositionerInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: ContextMenuPositionerInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceContextMenuPositionerInstance—
The instance to pass to the component.
ptSafeRecord<ContextMenuPositionerPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: ContextMenuPositionerInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
sideSideType—
The side of the positioner.
alignAlignType—
The align of the positioner.
sideOffsetnumber—
The side offset of the positioner.
alignOffsetnumber—
The align offset of the positioner.
flipboolean—
Whether to flip the positioner.
shiftboolean—
Whether to shift the positioner.
hideWhenDetachedboolean—
Whether to hide the positioner when detached.
strategy"fixed" | "absolute"'fixed'
The positioning strategy.
boundaryHTMLElement—
The boundary element that constrains the positioner placement. Used in JS fallback mode only; CSS Anchor mode uses the containing block.
anchorHTMLElement—
The anchor element.
contentHTMLDivElement—
The content element.
arrowHTMLDivElement—
The arrow element.
autoZIndexbooleantrue
Whether to automatically manage layering.
baseZIndexnumber0
Base zIndex value to use in layering.
onPlacementChange(placement: { side: SideType; align: AlignType }) => void—
Callback invoked when the actual placement changes due to flip or shift.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"contextmenu"
data-part"positioner"

CSS Custom Properties

The positioner element exposes CSS custom properties for layout and transform control.

CSS VariableDescription
--available-heightAvailable vertical space in pixels
--available-widthAvailable horizontal space in pixels
--transform-originComputed transform origin for animations
--positioner-anchor-widthWidth of the anchor/trigger element

Defines passthrough(pt) options of ContextMenuPositioner component.

labeltypedescription
rootMenuPositionerPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

ContextMenuArrow#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: ContextMenuArrowInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: ContextMenuArrowInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceContextMenuArrowInstance—
The instance to pass to the component.
ptSafeRecord<ContextMenuArrowPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: ContextMenuArrowInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-scope"contextmenu"
data-part"arrow"

CSS Custom Properties

The arrow element exposes CSS custom properties for dynamic positioning:

CSS VariableDescription
--placer-arrow-xHorizontal offset of arrow
--placer-arrow-yVertical offset of arrow
--placer-arrow-leftLeft position of arrow element
--placer-arrow-topTop position of arrow element

Defines passthrough(pt) options of ContextMenuArrow component.

labeltypedescription
rootMenuArrowPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

ContextMenuPortal#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
style(CSSProperties | ((instance?: PortalInstance) => CSSProperties)) & (CSSProperties | ((instance?: ContextMenuPortalInstance) => CSSProperties))—
The style to apply to the component.
className(string | ((instance?: PortalInstance) => string)) & (string | ((instance?: ContextMenuPortalInstance) => string))—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceBaseInstance<SafeRecord<PortalProps>, unknown, HTMLElement> & { props: SafeRecord<SafeRecord<PortalProps>>; attrs: Omit<SafeRecord<SafeRecord<PortalProps>>, string | number | symbol> & Record<PropertyKey, unknown> } & { state: SafeRecord; $computedSetup: SafeRecord } & PortalExposes & Record<PropertyKey, unknown> & useComponentPTReturnType & useComponentStyleReturnType & BaseInstance<SafeRecord<ContextMenuPortalProps>, unknown, HTMLElement> & { props: SafeRecord<SafeRecord<ContextMenuPortalProps>>; attrs: Omit<SafeRecord<SafeRecord<ContextMenuPortalProps>>, string | number | symbol> & Record<PropertyKey, unknown> } & { state: SafeRecord; $computedSetup: SafeRecord } & ContextMenuPortalExposes—
The instance to pass to the component.
ptPortalPassThrough & Record<PropertyKey, unknown> & ContextMenuPortalPassThrough—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: PortalInstance) => ReactNode & (instance: ContextMenuPortalInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
onMounted() => void—
Callback function to invoke when the portal is mounted.
onUnmounted() => void—
Callback function to invoke when the portal is unmounted.
elementHTMLElement | ReactNode—
The element to be rendered as the portal.
elementRefRefObject<HTMLElement>—
The element reference to be rendered as the portal.
appendTostring | HTMLElement | ((instance: PortalInstance) => HTMLElement)'body'
The DOM element where the portal should be appended to.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.

Defines passthrough(pt) options of ContextMenuPortal component.

labeltypedescription
rootMenuPortalPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

ContextMenuCheckboxItem#

Defines passthrough(pt) options of ContextMenuCheckboxItem component.

labeltypedescription
rootContextMenuCheckboxItemPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

ContextMenuRadioItem#

Defines passthrough(pt) options of ContextMenuRadioItem component.

labeltypedescription
rootContextMenuRadioItemPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

ContextMenuIcon#

ContextMenuCheckboxIcon#

ContextMenuRadioIcon#

Accessibility#

Screen Reader#

ContextMenu component uses the menu role and the value to describe the menu can either be provided with aria-labelledby or aria-label props. Each list item has a menuitem role with aria-label referring to the label of the item and aria-disabled defined if the item is disabled. Checkbox items use menuitemcheckbox and radio items use menuitemradio roles with aria-checked to indicate selection state.

The component implicitly manages the aria-expanded, aria-haspopup and aria-controls attributes of the trigger element to define the relation between the trigger and the popup.

Keyboard Support#

KeyFunction
tabAdd focus to the first item if focus moves in to the menu. If the focus is already within the menu, focus moves to the next focusable item in the page tab sequence.
shift + tabAdd focus to the first item if focus moves in to the menu. If the focus is already within the menu, focus moves to the previous focusable item in the page tab sequence.
enterActivates the focused menuitem. Popup closes and focus moves to target.
spaceActivates the focused menuitem. Popup closes and focus moves to target.
escapeCloses the popup and focus moves to target.
down arrowMoves focus to the next menuitem.
up arrowMoves focus to the previous menuitem.
right arrowOpens submenu if focused item has one. Moves focus to the first item of the submenu.
left arrowCloses current submenu and moves focus to parent submenu trigger.
alt + up arrowCloses the popup and focus moves to the target.
homeMoves focus to the first menuitem.
endMoves focus to the last menuitem.