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>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.
| Property | Type | Description |
|---|---|---|
children | ReactNode | Content or child elements of the component. |
dir | "ltr" | "rtl" | Interface reading direction. |
modal | boolean | Configures modal. The type describes the supported values and structure. |
onOpenChange | ((open: boolean) => void) | Receives the new open state. |
open | boolean | Controlled 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
| Property | Type | Description |
|---|---|---|
aria-label | string | Accessible name of the control. |
asChild | boolean | Apply props and behavior to a single compatible child element. |
children | ReactNode | Content or child elements of the component. |
className | string | Additional CSS classes to customize the element. |
defaultChecked | boolean | Initial selection of the control. |
defaultValue | string | number | readonly string[] | Initial value when the component manages its own state. |
disabled | boolean | Disable interaction with the control. |
id | string | Element identifier; associates labels and descriptions. |
onChange | ChangeEventHandler<HTMLSpanElement, Element> | Change event. Check the type: some controls return an object, others a DOM event. |
onClick | MouseEventHandler<HTMLSpanElement> | Action performed when the element is activated. |
onSubmit | SubmitEventHandler<HTMLSpanElement> | Form submission event. |
role | AriaRole | Semantic role of the element. Keep the default role unless a change is justified. |
style | CSSProperties | React inline styles. |
tabIndex | number | Keyboard focus order and availability. |
title | string | Title or supplementary information. |
ContextMenuTrigger · TypeScript
1ContextMenuTrigger: React.ForwardRefExoticComponent<ContextMenuPrimitive.ContextMenuTriggerProps & React.RefAttributes<HTMLSpanElement>>ContextMenuContent29 properties
| Property | Type | Description |
|---|---|---|
alignOffset | number | Offset from the chosen alignment. |
aria-label | string | Accessible name of the control. |
arrowPadding | number | Configures arrowPadding. The type describes the supported values and structure. |
asChild | boolean | Apply props and behavior to a single compatible child element. |
avoidCollisions | boolean | Configures avoidCollisions. The type describes the supported values and structure. |
children | ReactNode | Content or child elements of the component. |
className | string | Additional CSS classes to customize the element. |
collisionBoundary | Boundary | Boundary[] | Configures collisionBoundary. The type describes the supported values and structure. |
collisionPadding | number | Partial<Record<"left" | "right" | "top" | "bottom", number>> | Configures collisionPadding. The type describes the supported values and structure. |
defaultChecked | boolean | Initial selection of the control. |
defaultValue | string | number | readonly string[] | Initial value when the component manages its own state. |
forceMount | true | Used to force mounting when more control is needed. Useful when controlling animation with React animation libraries. |
hideWhenDetached | boolean | Configures hideWhenDetached. The type describes the supported values and structure. |
id | string | Element identifier; associates labels and descriptions. |
loop | boolean | Whether keyboard navigation should loop around |
onChange | ChangeEventHandler<HTMLDivElement, Element> | Change event. Check the type: some controls return an object, others a DOM event. |
onClick | MouseEventHandler<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. |
onSubmit | SubmitEventHandler<HTMLDivElement> | Form submission event. |
role | AriaRole | Semantic 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. |
style | CSSProperties | React inline styles. |
tabIndex | number | Keyboard focus order and availability. |
title | string | Title 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
| Property | Type | Description |
|---|---|---|
aria-label | string | Accessible name of the control. |
asChild | boolean | Apply props and behavior to a single compatible child element. |
children | ReactNode | Content or child elements of the component. |
className | string | Additional CSS classes to customize the element. |
defaultChecked | boolean | Initial selection of the control. |
defaultValue | string | number | readonly string[] | Initial value when the component manages its own state. |
disabled | boolean | Disable interaction with the control. |
id | string | Element identifier; associates labels and descriptions. |
inset | boolean | Configures inset. The type describes the supported values and structure. |
onChange | ChangeEventHandler<HTMLDivElement, Element> | Change event. Check the type: some controls return an object, others a DOM event. |
onClick | MouseEventHandler<HTMLDivElement> | Action performed when the element is activated. |
onSelect | ((event: Event) => void) | Action or selection made by the user. |
onSubmit | SubmitEventHandler<HTMLDivElement> | Form submission event. |
role | AriaRole | Semantic role of the element. Keep the default role unless a change is justified. |
style | CSSProperties | React inline styles. |
tabIndex | number | Keyboard focus order and availability. |
textValue | string | Configures textValue. The type describes the supported values and structure. |
title | string | Title or supplementary information. |
ContextMenuItem · TypeScript
1ContextMenuItem: React.ForwardRefExoticComponent<ContextMenuItemProps & React.RefAttributes<HTMLDivElement>>ContextMenuGroup14 properties
| Property | Type | Description |
|---|---|---|
aria-label | string | Accessible name of the control. |
asChild | boolean | Apply props and behavior to a single compatible child element. |
children | ReactNode | Content or child elements of the component. |
className | string | Additional CSS classes to customize the element. |
defaultChecked | boolean | Initial selection of the control. |
defaultValue | string | number | readonly string[] | Initial value when the component manages its own state. |
id | string | Element identifier; associates labels and descriptions. |
onChange | ChangeEventHandler<HTMLDivElement, Element> | Change event. Check the type: some controls return an object, others a DOM event. |
onClick | MouseEventHandler<HTMLDivElement> | Action performed when the element is activated. |
onSubmit | SubmitEventHandler<HTMLDivElement> | Form submission event. |
role | AriaRole | Semantic role of the element. Keep the default role unless a change is justified. |
style | CSSProperties | React inline styles. |
tabIndex | number | Keyboard focus order and availability. |
title | string | Title or supplementary information. |
ContextMenuGroup · TypeScript
1ContextMenuGroup: React.ForwardRefExoticComponent<ContextMenuPrimitive.ContextMenuGroupProps & React.RefAttributes<HTMLDivElement>>ContextMenuLabel15 properties
| Property | Type | Description |
|---|---|---|
aria-label | string | Accessible name of the control. |
asChild | boolean | Apply props and behavior to a single compatible child element. |
children | ReactNode | Content or child elements of the component. |
className | string | Additional CSS classes to customize the element. |
defaultChecked | boolean | Initial selection of the control. |
defaultValue | string | number | readonly string[] | Initial value when the component manages its own state. |
id | string | Element identifier; associates labels and descriptions. |
inset | boolean | Configures inset. The type describes the supported values and structure. |
onChange | ChangeEventHandler<HTMLDivElement, Element> | Change event. Check the type: some controls return an object, others a DOM event. |
onClick | MouseEventHandler<HTMLDivElement> | Action performed when the element is activated. |
onSubmit | SubmitEventHandler<HTMLDivElement> | Form submission event. |
role | AriaRole | Semantic role of the element. Keep the default role unless a change is justified. |
style | CSSProperties | React inline styles. |
tabIndex | number | Keyboard focus order and availability. |
title | string | Title or supplementary information. |
ContextMenuLabel · TypeScript
1ContextMenuLabel: React.ForwardRefExoticComponent<ContextMenuLabelProps & React.RefAttributes<HTMLDivElement>>ContextMenuSeparator14 properties
| Property | Type | Description |
|---|---|---|
aria-label | string | Accessible name of the control. |
asChild | boolean | Apply props and behavior to a single compatible child element. |
children | ReactNode | Content or child elements of the component. |
className | string | Additional CSS classes to customize the element. |
defaultChecked | boolean | Initial selection of the control. |
defaultValue | string | number | readonly string[] | Initial value when the component manages its own state. |
id | string | Element identifier; associates labels and descriptions. |
onChange | ChangeEventHandler<HTMLDivElement, Element> | Change event. Check the type: some controls return an object, others a DOM event. |
onClick | MouseEventHandler<HTMLDivElement> | Action performed when the element is activated. |
onSubmit | SubmitEventHandler<HTMLDivElement> | Form submission event. |
role | AriaRole | Semantic role of the element. Keep the default role unless a change is justified. |
style | CSSProperties | React inline styles. |
tabIndex | number | Keyboard focus order and availability. |
title | string | Title or supplementary information. |
ContextMenuSeparator · TypeScript
1ContextMenuSeparator: React.ForwardRefExoticComponent<ContextMenuSeparatorProps & React.RefAttributes<HTMLDivElement>>ContextMenuCheckboxItem19 properties
| Property | Type | Description |
|---|---|---|
aria-label | string | Accessible name of the control. |
asChild | boolean | Apply props and behavior to a single compatible child element. |
checked | CheckedState | Controlled selection state. |
children | ReactNode | Content or child elements of the component. |
className | string | Additional CSS classes to customize the element. |
defaultChecked | boolean | Initial selection of the control. |
defaultValue | string | number | readonly string[] | Initial value when the component manages its own state. |
disabled | boolean | Disable interaction with the control. |
id | string | Element identifier; associates labels and descriptions. |
onChange | ChangeEventHandler<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. |
onClick | MouseEventHandler<HTMLDivElement> | Action performed when the element is activated. |
onSelect | ((event: Event) => void) | Action or selection made by the user. |
onSubmit | SubmitEventHandler<HTMLDivElement> | Form submission event. |
role | AriaRole | Semantic role of the element. Keep the default role unless a change is justified. |
style | CSSProperties | React inline styles. |
tabIndex | number | Keyboard focus order and availability. |
textValue | string | Configures textValue. The type describes the supported values and structure. |
title | string | Title or supplementary information. |
ContextMenuCheckboxItem · TypeScript
1ContextMenuCheckboxItem: React.ForwardRefExoticComponent<ContextMenuCheckboxItemProps & React.RefAttributes<HTMLDivElement>>ContextMenuRadioGroup16 properties
| Property | Type | Description |
|---|---|---|
aria-label | string | Accessible name of the control. |
asChild | boolean | Apply props and behavior to a single compatible child element. |
children | ReactNode | Content or child elements of the component. |
className | string | Additional CSS classes to customize the element. |
defaultChecked | boolean | Initial selection of the control. |
defaultValue | string | number | readonly string[] | Initial value when the component manages its own state. |
id | string | Element identifier; associates labels and descriptions. |
onChange | ChangeEventHandler<HTMLDivElement, Element> | Change event. Check the type: some controls return an object, others a DOM event. |
onClick | MouseEventHandler<HTMLDivElement> | Action performed when the element is activated. |
onSubmit | SubmitEventHandler<HTMLDivElement> | Form submission event. |
onValueChange | ((value: string) => void) | Receives the value after an interaction. |
role | AriaRole | Semantic role of the element. Keep the default role unless a change is justified. |
style | CSSProperties | React inline styles. |
tabIndex | number | Keyboard focus order and availability. |
title | string | Title or supplementary information. |
value | string | Controlled value. Update it from the change callback. |
ContextMenuRadioGroup · TypeScript
1ContextMenuRadioGroup: React.ForwardRefExoticComponent<ContextMenuPrimitive.ContextMenuRadioGroupProps & React.RefAttributes<HTMLDivElement>>ContextMenuRadioItem18 properties
| Property | Type | Description |
|---|---|---|
valueRequired | string | Controlled value. Update it from the change callback. |
aria-label | string | Accessible name of the control. |
asChild | boolean | Apply props and behavior to a single compatible child element. |
children | ReactNode | Content or child elements of the component. |
className | string | Additional CSS classes to customize the element. |
defaultChecked | boolean | Initial selection of the control. |
defaultValue | string | number | readonly string[] | Initial value when the component manages its own state. |
disabled | boolean | Disable interaction with the control. |
id | string | Element identifier; associates labels and descriptions. |
onChange | ChangeEventHandler<HTMLDivElement, Element> | Change event. Check the type: some controls return an object, others a DOM event. |
onClick | MouseEventHandler<HTMLDivElement> | Action performed when the element is activated. |
onSelect | ((event: Event) => void) | Action or selection made by the user. |
onSubmit | SubmitEventHandler<HTMLDivElement> | Form submission event. |
role | AriaRole | Semantic role of the element. Keep the default role unless a change is justified. |
style | CSSProperties | React inline styles. |
tabIndex | number | Keyboard focus order and availability. |
textValue | string | Configures textValue. The type describes the supported values and structure. |
title | string | Title or supplementary information. |
ContextMenuRadioItem · TypeScript
1ContextMenuRadioItem: React.ForwardRefExoticComponent<ContextMenuRadioItemProps & React.RefAttributes<HTMLDivElement>>ContextMenuSub4 properties
| Property | Type | Description |
|---|---|---|
children | ReactNode | Content or child elements of the component. |
defaultOpen | boolean | Whether it starts open in uncontrolled mode. |
onOpenChange | ((open: boolean) => void) | Receives the new open state. |
open | boolean | Controlled open state. |
ContextMenuSub · TypeScript
1ContextMenuSub: React.FC<ContextMenuPrimitive.ContextMenuSubProps>ContextMenuSubTrigger17 properties
| Property | Type | Description |
|---|---|---|
aria-label | string | Accessible name of the control. |
asChild | boolean | Apply props and behavior to a single compatible child element. |
children | ReactNode | Content or child elements of the component. |
className | string | Additional CSS classes to customize the element. |
defaultChecked | boolean | Initial selection of the control. |
defaultValue | string | number | readonly string[] | Initial value when the component manages its own state. |
disabled | boolean | Disable interaction with the control. |
id | string | Element identifier; associates labels and descriptions. |
inset | boolean | Configures inset. The type describes the supported values and structure. |
onChange | ChangeEventHandler<HTMLDivElement, Element> | Change event. Check the type: some controls return an object, others a DOM event. |
onClick | MouseEventHandler<HTMLDivElement> | Action performed when the element is activated. |
onSubmit | SubmitEventHandler<HTMLDivElement> | Form submission event. |
role | AriaRole | Semantic role of the element. Keep the default role unless a change is justified. |
style | CSSProperties | React inline styles. |
tabIndex | number | Keyboard focus order and availability. |
textValue | string | Configures textValue. The type describes the supported values and structure. |
title | string | Title or supplementary information. |
ContextMenuSubTrigger · TypeScript
1ContextMenuSubTrigger: React.ForwardRefExoticComponent<ContextMenuSubTriggerProps & React.RefAttributes<HTMLDivElement>>ContextMenuSubContent30 properties
| Property | Type | Description |
|---|---|---|
align | "start" | "end" | Content alignment. |
alignOffset | number | Offset from the chosen alignment. |
aria-label | string | Accessible name of the control. |
arrowPadding | number | Configures arrowPadding. The type describes the supported values and structure. |
asChild | boolean | Apply props and behavior to a single compatible child element. |
avoidCollisions | boolean | Configures avoidCollisions. The type describes the supported values and structure. |
children | ReactNode | Content or child elements of the component. |
className | string | Additional CSS classes to customize the element. |
collisionBoundary | Boundary | Boundary[] | Configures collisionBoundary. The type describes the supported values and structure. |
collisionPadding | number | Partial<Record<"left" | "right" | "top" | "bottom", number>> | Configures collisionPadding. The type describes the supported values and structure. |
defaultChecked | boolean | Initial selection of the control. |
defaultValue | string | number | readonly string[] | Initial value when the component manages its own state. |
forceMount | true | Used to force mounting when more control is needed. Useful when controlling animation with React animation libraries. |
hideWhenDetached | boolean | Configures hideWhenDetached. The type describes the supported values and structure. |
id | string | Element identifier; associates labels and descriptions. |
loop | boolean | Whether keyboard navigation should loop around |
onChange | ChangeEventHandler<HTMLDivElement, Element> | Change event. Check the type: some controls return an object, others a DOM event. |
onClick | MouseEventHandler<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. |
onSubmit | SubmitEventHandler<HTMLDivElement> | Form submission event. |
role | AriaRole | Semantic role of the element. Keep the default role unless a change is justified. |
sideOffset | number | Distance between the trigger and content. |
sticky | "partial" | "always" | Configures sticky. The type describes the supported values and structure. |
style | CSSProperties | React inline styles. |
tabIndex | number | Keyboard focus order and availability. |
title | string | Title 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
| Property | Type | Description |
|---|---|---|
aria-label | string | Accessible name of the control. |
children | ReactNode | Content or child elements of the component. |
className | string | Additional CSS classes to customize the element. |
defaultChecked | boolean | Initial selection of the control. |
defaultValue | string | number | readonly string[] | Initial value when the component manages its own state. |
id | string | Element identifier; associates labels and descriptions. |
onChange | ChangeEventHandler<HTMLSpanElement, Element> | Change event. Check the type: some controls return an object, others a DOM event. |
onClick | MouseEventHandler<HTMLSpanElement> | Action performed when the element is activated. |
onSubmit | SubmitEventHandler<HTMLSpanElement> | Form submission event. |
role | AriaRole | Semantic role of the element. Keep the default role unless a change is justified. |
style | CSSProperties | React inline styles. |
tabIndex | number | Keyboard focus order and availability. |
title | string | Title or supplementary information. |
ContextMenuShortcut · TypeScript
1ContextMenuShortcut: {
2 ({ className, ...props }: React.HTMLAttributes<HTMLSpanElement>): React.JSX.Element;
3 displayName: string;
4}ContextMenuPortal3 properties
| Property | Type | Description |
|---|---|---|
children | ReactNode | Content or child elements of the component. |
container | Element | DocumentFragment | null | Specify a container element to portal the content into. |
forceMount | true | Used 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