Skip to content
Panels and menusInteractive playground

ContextMenu

Contextual actions on right-click.

Preparing the playground…
Text and Markdown example
ContextMenu · Example
1<ContextMenu><ContextMenuTrigger style={{display:"block",padding:36,border:"1px dashed var(--color-border)",borderRadius:12}}>Right-click here</ContextMenuTrigger><ContextMenuContent><ContextMenuItem onSelect={() => window.alert("New demo project")}>New project</ContextMenuItem><ContextMenuSeparator /><ContextMenuItem disabled>Export (unavailable)</ContextMenuItem></ContextMenuContent></ContextMenu>
Read documentation in Markdown

How to use it

Connect onSelect on action items. Combine separators, groups, checkbox options and submenus.

Import

React / Next.js
1import { ContextMenu, ContextMenuTrigger, ContextMenuContent, ContextMenuItem, ContextMenuGroup, ContextMenuLabel, ContextMenuSeparator, ContextMenuCheckboxItem, ContextMenuRadioGroup, ContextMenuRadioItem, ContextMenuSub, ContextMenuSubTrigger, ContextMenuSubContent, ContextMenuShortcut, ContextMenuPortal } from "@kivora/nextjs";

Interactive examples run inside a component with "use client". The playground's Copy button includes the imports needed for the current example.

API reference 0.2.0

Types from the installed published version, including component properties and common HTML attributes. “Optional” does not imply a default value; omitting a property lets the component decide.

PropertyTypeDescription
childrenReactNodeContent or child elements of the component.
dir"ltr" | "rtl"Interface reading direction.
modalbooleanConfigures modal. The type describes the supported values and structure.
onOpenChange((open: boolean) => void)Receives the new open state.
openbooleanControlled open state.

Subcomponents and composition

Review each component's properties and published declaration. Native and accessibility attributes are inherited from the element specified by its type.

ContextMenu5 properties
ContextMenu · TypeScript
1ContextMenu: React.FC<ContextMenuPrimitive.ContextMenuProps>
ContextMenuTrigger15 properties
PropertyTypeDescription
aria-labelstringAccessible name of the control.
asChildbooleanApply props and behavior to a single compatible child element.
childrenReactNodeContent or child elements of the component.
classNamestringAdditional CSS classes to customize the element.
defaultCheckedbooleanInitial selection of the control.
defaultValuestring | number | readonly string[]Initial value when the component manages its own state.
disabledbooleanDisable interaction with the control.
idstringElement identifier; associates labels and descriptions.
onChangeChangeEventHandler<HTMLSpanElement, Element>Change event. Check the type: some controls return an object, others a DOM event.
onClickMouseEventHandler<HTMLSpanElement>Action performed when the element is activated.
onSubmitSubmitEventHandler<HTMLSpanElement>Form submission event.
roleAriaRoleSemantic role of the element. Keep the default role unless a change is justified.
styleCSSPropertiesReact inline styles.
tabIndexnumberKeyboard focus order and availability.
titlestringTitle or supplementary information.
ContextMenuTrigger · TypeScript
1ContextMenuTrigger: React.ForwardRefExoticComponent<ContextMenuPrimitive.ContextMenuTriggerProps & React.RefAttributes<HTMLSpanElement>>
ContextMenuContent29 properties
PropertyTypeDescription
alignOffsetnumberOffset from the chosen alignment.
aria-labelstringAccessible name of the control.
arrowPaddingnumberConfigures arrowPadding. The type describes the supported values and structure.
asChildbooleanApply props and behavior to a single compatible child element.
avoidCollisionsbooleanConfigures avoidCollisions. The type describes the supported values and structure.
childrenReactNodeContent or child elements of the component.
classNamestringAdditional CSS classes to customize the element.
collisionBoundaryBoundary | Boundary[]Configures collisionBoundary. The type describes the supported values and structure.
collisionPaddingnumber | Partial<Record<"left" | "right" | "top" | "bottom", number>>Configures collisionPadding. The type describes the supported values and structure.
defaultCheckedbooleanInitial selection of the control.
defaultValuestring | number | readonly string[]Initial value when the component manages its own state.
forceMounttrueUsed to force mounting when more control is needed. Useful when controlling animation with React animation libraries.
hideWhenDetachedbooleanConfigures hideWhenDetached. The type describes the supported values and structure.
idstringElement identifier; associates labels and descriptions.
loopbooleanWhether keyboard navigation should loop around
onChangeChangeEventHandler<HTMLDivElement, Element>Change event. Check the type: some controls return an object, others a DOM event.
onClickMouseEventHandler<HTMLDivElement>Action performed when the element is activated.
onCloseAutoFocus((event: Event) => void)Event handler called when auto-focusing on close. Can be prevented.
onEscapeKeyDown((event: KeyboardEvent) => void)Callback for this event. The signature describes its arguments.
onFocusOutside((event: FocusOutsideEvent) => void)Callback for this event. The signature describes its arguments.
onInteractOutside((event: PointerDownOutsideEvent | FocusOutsideEvent) => void)Callback for this event. The signature describes its arguments.
onPointerDownOutside((event: PointerDownOutsideEvent) => void)Callback for this event. The signature describes its arguments.
onSubmitSubmitEventHandler<HTMLDivElement>Form submission event.
roleAriaRoleSemantic role of the element. Keep the default role unless a change is justified.
sticky"partial" | "always"Configures sticky. The type describes the supported values and structure.
styleCSSPropertiesReact inline styles.
tabIndexnumberKeyboard focus order and availability.
titlestringTitle or supplementary information.
updatePositionStrategy"always" | "optimized"Configures updatePositionStrategy. The type describes the supported values and structure.
ContextMenuContent · TypeScript
1ContextMenuContent: React.ForwardRefExoticComponent<ContextMenuContentProps & React.RefAttributes<HTMLDivElement>>
ContextMenuItem18 properties
PropertyTypeDescription
aria-labelstringAccessible name of the control.
asChildbooleanApply props and behavior to a single compatible child element.
childrenReactNodeContent or child elements of the component.
classNamestringAdditional CSS classes to customize the element.
defaultCheckedbooleanInitial selection of the control.
defaultValuestring | number | readonly string[]Initial value when the component manages its own state.
disabledbooleanDisable interaction with the control.
idstringElement identifier; associates labels and descriptions.
insetbooleanConfigures inset. The type describes the supported values and structure.
onChangeChangeEventHandler<HTMLDivElement, Element>Change event. Check the type: some controls return an object, others a DOM event.
onClickMouseEventHandler<HTMLDivElement>Action performed when the element is activated.
onSelect((event: Event) => void)Action or selection made by the user.
onSubmitSubmitEventHandler<HTMLDivElement>Form submission event.
roleAriaRoleSemantic role of the element. Keep the default role unless a change is justified.
styleCSSPropertiesReact inline styles.
tabIndexnumberKeyboard focus order and availability.
textValuestringConfigures textValue. The type describes the supported values and structure.
titlestringTitle or supplementary information.
ContextMenuItem · TypeScript
1ContextMenuItem: React.ForwardRefExoticComponent<ContextMenuItemProps & React.RefAttributes<HTMLDivElement>>
ContextMenuGroup14 properties
PropertyTypeDescription
aria-labelstringAccessible name of the control.
asChildbooleanApply props and behavior to a single compatible child element.
childrenReactNodeContent or child elements of the component.
classNamestringAdditional CSS classes to customize the element.
defaultCheckedbooleanInitial selection of the control.
defaultValuestring | number | readonly string[]Initial value when the component manages its own state.
idstringElement identifier; associates labels and descriptions.
onChangeChangeEventHandler<HTMLDivElement, Element>Change event. Check the type: some controls return an object, others a DOM event.
onClickMouseEventHandler<HTMLDivElement>Action performed when the element is activated.
onSubmitSubmitEventHandler<HTMLDivElement>Form submission event.
roleAriaRoleSemantic role of the element. Keep the default role unless a change is justified.
styleCSSPropertiesReact inline styles.
tabIndexnumberKeyboard focus order and availability.
titlestringTitle or supplementary information.
ContextMenuGroup · TypeScript
1ContextMenuGroup: React.ForwardRefExoticComponent<ContextMenuPrimitive.ContextMenuGroupProps & React.RefAttributes<HTMLDivElement>>
ContextMenuLabel15 properties
PropertyTypeDescription
aria-labelstringAccessible name of the control.
asChildbooleanApply props and behavior to a single compatible child element.
childrenReactNodeContent or child elements of the component.
classNamestringAdditional CSS classes to customize the element.
defaultCheckedbooleanInitial selection of the control.
defaultValuestring | number | readonly string[]Initial value when the component manages its own state.
idstringElement identifier; associates labels and descriptions.
insetbooleanConfigures inset. The type describes the supported values and structure.
onChangeChangeEventHandler<HTMLDivElement, Element>Change event. Check the type: some controls return an object, others a DOM event.
onClickMouseEventHandler<HTMLDivElement>Action performed when the element is activated.
onSubmitSubmitEventHandler<HTMLDivElement>Form submission event.
roleAriaRoleSemantic role of the element. Keep the default role unless a change is justified.
styleCSSPropertiesReact inline styles.
tabIndexnumberKeyboard focus order and availability.
titlestringTitle or supplementary information.
ContextMenuLabel · TypeScript
1ContextMenuLabel: React.ForwardRefExoticComponent<ContextMenuLabelProps & React.RefAttributes<HTMLDivElement>>
ContextMenuSeparator14 properties
PropertyTypeDescription
aria-labelstringAccessible name of the control.
asChildbooleanApply props and behavior to a single compatible child element.
childrenReactNodeContent or child elements of the component.
classNamestringAdditional CSS classes to customize the element.
defaultCheckedbooleanInitial selection of the control.
defaultValuestring | number | readonly string[]Initial value when the component manages its own state.
idstringElement identifier; associates labels and descriptions.
onChangeChangeEventHandler<HTMLDivElement, Element>Change event. Check the type: some controls return an object, others a DOM event.
onClickMouseEventHandler<HTMLDivElement>Action performed when the element is activated.
onSubmitSubmitEventHandler<HTMLDivElement>Form submission event.
roleAriaRoleSemantic role of the element. Keep the default role unless a change is justified.
styleCSSPropertiesReact inline styles.
tabIndexnumberKeyboard focus order and availability.
titlestringTitle or supplementary information.
ContextMenuSeparator · TypeScript
1ContextMenuSeparator: React.ForwardRefExoticComponent<ContextMenuSeparatorProps & React.RefAttributes<HTMLDivElement>>
ContextMenuCheckboxItem19 properties
PropertyTypeDescription
aria-labelstringAccessible name of the control.
asChildbooleanApply props and behavior to a single compatible child element.
checkedCheckedStateControlled selection state.
childrenReactNodeContent or child elements of the component.
classNamestringAdditional CSS classes to customize the element.
defaultCheckedbooleanInitial selection of the control.
defaultValuestring | number | readonly string[]Initial value when the component manages its own state.
disabledbooleanDisable interaction with the control.
idstringElement identifier; associates labels and descriptions.
onChangeChangeEventHandler<HTMLDivElement, Element>Change event. Check the type: some controls return an object, others a DOM event.
onCheckedChange((checked: boolean) => void)Receives the new selection state.
onClickMouseEventHandler<HTMLDivElement>Action performed when the element is activated.
onSelect((event: Event) => void)Action or selection made by the user.
onSubmitSubmitEventHandler<HTMLDivElement>Form submission event.
roleAriaRoleSemantic role of the element. Keep the default role unless a change is justified.
styleCSSPropertiesReact inline styles.
tabIndexnumberKeyboard focus order and availability.
textValuestringConfigures textValue. The type describes the supported values and structure.
titlestringTitle or supplementary information.
ContextMenuCheckboxItem · TypeScript
1ContextMenuCheckboxItem: React.ForwardRefExoticComponent<ContextMenuCheckboxItemProps & React.RefAttributes<HTMLDivElement>>
ContextMenuRadioGroup16 properties
PropertyTypeDescription
aria-labelstringAccessible name of the control.
asChildbooleanApply props and behavior to a single compatible child element.
childrenReactNodeContent or child elements of the component.
classNamestringAdditional CSS classes to customize the element.
defaultCheckedbooleanInitial selection of the control.
defaultValuestring | number | readonly string[]Initial value when the component manages its own state.
idstringElement identifier; associates labels and descriptions.
onChangeChangeEventHandler<HTMLDivElement, Element>Change event. Check the type: some controls return an object, others a DOM event.
onClickMouseEventHandler<HTMLDivElement>Action performed when the element is activated.
onSubmitSubmitEventHandler<HTMLDivElement>Form submission event.
onValueChange((value: string) => void)Receives the value after an interaction.
roleAriaRoleSemantic role of the element. Keep the default role unless a change is justified.
styleCSSPropertiesReact inline styles.
tabIndexnumberKeyboard focus order and availability.
titlestringTitle or supplementary information.
valuestringControlled value. Update it from the change callback.
ContextMenuRadioGroup · TypeScript
1ContextMenuRadioGroup: React.ForwardRefExoticComponent<ContextMenuPrimitive.ContextMenuRadioGroupProps & React.RefAttributes<HTMLDivElement>>
ContextMenuRadioItem18 properties
PropertyTypeDescription
valueRequiredstringControlled value. Update it from the change callback.
aria-labelstringAccessible name of the control.
asChildbooleanApply props and behavior to a single compatible child element.
childrenReactNodeContent or child elements of the component.
classNamestringAdditional CSS classes to customize the element.
defaultCheckedbooleanInitial selection of the control.
defaultValuestring | number | readonly string[]Initial value when the component manages its own state.
disabledbooleanDisable interaction with the control.
idstringElement identifier; associates labels and descriptions.
onChangeChangeEventHandler<HTMLDivElement, Element>Change event. Check the type: some controls return an object, others a DOM event.
onClickMouseEventHandler<HTMLDivElement>Action performed when the element is activated.
onSelect((event: Event) => void)Action or selection made by the user.
onSubmitSubmitEventHandler<HTMLDivElement>Form submission event.
roleAriaRoleSemantic role of the element. Keep the default role unless a change is justified.
styleCSSPropertiesReact inline styles.
tabIndexnumberKeyboard focus order and availability.
textValuestringConfigures textValue. The type describes the supported values and structure.
titlestringTitle or supplementary information.
ContextMenuRadioItem · TypeScript
1ContextMenuRadioItem: React.ForwardRefExoticComponent<ContextMenuRadioItemProps & React.RefAttributes<HTMLDivElement>>
ContextMenuSub4 properties
PropertyTypeDescription
childrenReactNodeContent or child elements of the component.
defaultOpenbooleanWhether it starts open in uncontrolled mode.
onOpenChange((open: boolean) => void)Receives the new open state.
openbooleanControlled open state.
ContextMenuSub · TypeScript
1ContextMenuSub: React.FC<ContextMenuPrimitive.ContextMenuSubProps>
ContextMenuSubTrigger17 properties
PropertyTypeDescription
aria-labelstringAccessible name of the control.
asChildbooleanApply props and behavior to a single compatible child element.
childrenReactNodeContent or child elements of the component.
classNamestringAdditional CSS classes to customize the element.
defaultCheckedbooleanInitial selection of the control.
defaultValuestring | number | readonly string[]Initial value when the component manages its own state.
disabledbooleanDisable interaction with the control.
idstringElement identifier; associates labels and descriptions.
insetbooleanConfigures inset. The type describes the supported values and structure.
onChangeChangeEventHandler<HTMLDivElement, Element>Change event. Check the type: some controls return an object, others a DOM event.
onClickMouseEventHandler<HTMLDivElement>Action performed when the element is activated.
onSubmitSubmitEventHandler<HTMLDivElement>Form submission event.
roleAriaRoleSemantic role of the element. Keep the default role unless a change is justified.
styleCSSPropertiesReact inline styles.
tabIndexnumberKeyboard focus order and availability.
textValuestringConfigures textValue. The type describes the supported values and structure.
titlestringTitle or supplementary information.
ContextMenuSubTrigger · TypeScript
1ContextMenuSubTrigger: React.ForwardRefExoticComponent<ContextMenuSubTriggerProps & React.RefAttributes<HTMLDivElement>>
ContextMenuSubContent30 properties
PropertyTypeDescription
align"start" | "end"Content alignment.
alignOffsetnumberOffset from the chosen alignment.
aria-labelstringAccessible name of the control.
arrowPaddingnumberConfigures arrowPadding. The type describes the supported values and structure.
asChildbooleanApply props and behavior to a single compatible child element.
avoidCollisionsbooleanConfigures avoidCollisions. The type describes the supported values and structure.
childrenReactNodeContent or child elements of the component.
classNamestringAdditional CSS classes to customize the element.
collisionBoundaryBoundary | Boundary[]Configures collisionBoundary. The type describes the supported values and structure.
collisionPaddingnumber | Partial<Record<"left" | "right" | "top" | "bottom", number>>Configures collisionPadding. The type describes the supported values and structure.
defaultCheckedbooleanInitial selection of the control.
defaultValuestring | number | readonly string[]Initial value when the component manages its own state.
forceMounttrueUsed to force mounting when more control is needed. Useful when controlling animation with React animation libraries.
hideWhenDetachedbooleanConfigures hideWhenDetached. The type describes the supported values and structure.
idstringElement identifier; associates labels and descriptions.
loopbooleanWhether keyboard navigation should loop around
onChangeChangeEventHandler<HTMLDivElement, Element>Change event. Check the type: some controls return an object, others a DOM event.
onClickMouseEventHandler<HTMLDivElement>Action performed when the element is activated.
onEscapeKeyDown((event: KeyboardEvent) => void)Callback for this event. The signature describes its arguments.
onFocusOutside((event: FocusOutsideEvent) => void)Callback for this event. The signature describes its arguments.
onInteractOutside((event: PointerDownOutsideEvent | FocusOutsideEvent) => void)Callback for this event. The signature describes its arguments.
onPointerDownOutside((event: PointerDownOutsideEvent) => void)Callback for this event. The signature describes its arguments.
onSubmitSubmitEventHandler<HTMLDivElement>Form submission event.
roleAriaRoleSemantic role of the element. Keep the default role unless a change is justified.
sideOffsetnumberDistance between the trigger and content.
sticky"partial" | "always"Configures sticky. The type describes the supported values and structure.
styleCSSPropertiesReact inline styles.
tabIndexnumberKeyboard focus order and availability.
titlestringTitle or supplementary information.
updatePositionStrategy"always" | "optimized"Configures updatePositionStrategy. The type describes the supported values and structure.
ContextMenuSubContent · TypeScript
1ContextMenuSubContent: React.ForwardRefExoticComponent<ContextMenuSubContentProps & React.RefAttributes<HTMLDivElement>>
ContextMenuShortcut13 properties
PropertyTypeDescription
aria-labelstringAccessible name of the control.
childrenReactNodeContent or child elements of the component.
classNamestringAdditional CSS classes to customize the element.
defaultCheckedbooleanInitial selection of the control.
defaultValuestring | number | readonly string[]Initial value when the component manages its own state.
idstringElement identifier; associates labels and descriptions.
onChangeChangeEventHandler<HTMLSpanElement, Element>Change event. Check the type: some controls return an object, others a DOM event.
onClickMouseEventHandler<HTMLSpanElement>Action performed when the element is activated.
onSubmitSubmitEventHandler<HTMLSpanElement>Form submission event.
roleAriaRoleSemantic role of the element. Keep the default role unless a change is justified.
styleCSSPropertiesReact inline styles.
tabIndexnumberKeyboard focus order and availability.
titlestringTitle or supplementary information.
ContextMenuShortcut · TypeScript
1ContextMenuShortcut: { 2 ({ className, ...props }: React.HTMLAttributes<HTMLSpanElement>): React.JSX.Element; 3 displayName: string; 4}
ContextMenuPortal3 properties
PropertyTypeDescription
childrenReactNodeContent or child elements of the component.
containerElement | DocumentFragment | nullSpecify a container element to portal the content into.
forceMounttrueUsed to force mounting when more control is needed. Useful when controlling animation with React animation libraries.
ContextMenuPortal · TypeScript
1ContextMenuPortal: React.FC<ContextMenuPrimitive.ContextMenuPortalProps>
API generated from @kivora/nextjs 0.2.0View package