Skip to content

Context Menu

Displays a menu to the user — such as a set of actions or functions — triggered by a button.

Right click here

Installation

npm i @huin-core/react-context-menu

API Reference

ContextMenu

PropTypeDescription
dir"ltr" | "rtl"The reading direction. If omitted, inherits globally from DirectionProvider or assumes LTR (left-to-right) reading mode.
onOpenChangefunctionEvent handler called when the open state of the component changes.
modalbooleanThe modality of the dialog. When set to true, interaction with outside elements will be disabled and only dialog content will be visible to screen readers.

ContextMenuTrigger

PropTypeDescription
asChildbooleanWhen set to true, renders the component as its child element, inheriting the child's styles and behavior.
disabledbooleanWhen set to true, disables the component, preventing user interaction or triggering of associated actions.

ContextMenuPortal

PropTypeDescription
forceMountbooleanUsed to force mounting when more control is needed. Useful when controlling animation with React animation libraries. It inherits from.

ContextMenuContent

PropTypeDescription
sticky"partial" | "always"The sticky behavior on the align axis. 'partial' will keep the content in the boundary as long as the trigger is at least partially in the boundary whilst 'always' will keep the content in the boundary regardless.
asChildbooleanWhen set to true, renders the component as its child element, inheriting the child's styles and behavior.
loopbooleanWhen true, keyboard navigation will loop from last item to first, and vice versa.
forceMountbooleanUsed to force mounting when more control is needed. Useful when controlling animation with React animation libraries. It inherits from.
avoidCollisionsbooleanWhen true, overrides the side andalign preferences to prevent collisions with boundary edges.
hideWhenDetachedbooleanWhether to hide the content when the trigger becomes fully occluded.
sideOffsetnumberThe distance in pixels from the anchor.
alignOffsetnumberAn offset in pixels from the 'start' or 'end' alignment options.
collisionPaddingnumberThe distance in pixels from the boundary edges where collision detection should occur. Accepts a number (same for all sides), or a partial padding object, for example: { top: 20, left: 20 }.
arrowPaddingnumberThe padding between the arrow and the edges of the content. If your content has border-radius, this will prevent it from overflowing the corners.
onOpenAutoFocusfunctionEvent handler called when focus moves into the component after opening. It can be prevented by calling event.preventDefault.
onCloseAutoFocusfunctionEvent handler called when focus moves to the trigger after closing. It can be prevented by calling event.preventDefault.
onEscapeKeyDownfunctionEvent handler called when the escape key is down. It can be prevented by calling event.preventDefault.
onPointerDownOutsidefunctionEvent handler called when a pointer event occurs outside the bounds of the component. It can be prevented by calling event.preventDefault
onFocusOutsidefunctionEvent handler called when focus moves outside the bounds of the component. It can be prevented by calling event.preventDefault.
onInteractOutsidefunctionEvent handler called when an interaction (pointer or focus event) happens outside the bounds of the component. It can be prevented by calling event.preventDefault.

ContextMenuArrow

PropTypeDescription
widthnumberThe width of the piece in pixels.
heightnumberThe width of the height in pixels.
asChildbooleanWhen set to true, renders the component as its child element, inheriting the child's styles and behavior.

ContextMenuItem

PropTypeDescription
asChildbooleanWhen set to true, renders the component as its child element, inheriting the child's styles and behavior.
disabledbooleanWhen set to true, disables the component, preventing user interaction or triggering of associated actions.
onSelectfunctionEvent handler called when the user selects an item (via mouse or keyboard). Calling event.preventDefault in this handler will prevent the menubar from closing when selecting that item.
textValuestringOptional text used for typeahead purposes. By default the typeahead behavior will use the .textContent of the item. Use this when the content is complex, or you have non-textual content inside.

ContextMenuGroup

PropTypeDescription
asChildbooleanWhen set to true, renders the component as its child element, inheriting the child's styles and behavior.

ContextMenuLabel

PropTypeDescription
asChildbooleanWhen set to true, renders the component as its child element, inheriting the child's styles and behavior.

ContextMenuCheckboxItem

PropTypeDescription
asChildbooleanWhen set to true, renders the component as its child element, inheriting the child's styles and behavior.
checkedbooleanRepresents the current state of the component, indicating whether it is enabled or selected.
disabledbooleanWhen set to true, disables the component, preventing user interaction or triggering of associated actions.
textValuestringOptional text used for typeahead purposes. By default the typeahead behavior will use the .textContent of the item. Use this when the content is complex, or you have non-textual content inside.
onSelectfunctionEvent handler called when the user selects an item (via mouse or keyboard). Calling event.preventDefault in this handler will prevent the menubar from closing when selecting that item.

ContextMenuRadioGroup

PropTypeDescription
asChildbooleanWhen set to true, renders the component as its child element, inheriting the child's styles and behavior.
valuestringRepresents the current value or state of the component, which can be used to bind or track its data over time.
onValueChangefunctionEvent handler called when the value changes.

ContextMenuRadioItem

PropTypeDescription
asChildbooleanWhen set to true, renders the component as its child element, inheriting the child's styles and behavior.
valuestringRepresents the current value or state of the component, which can be used to bind or track its data over time.
disabledbooleanWhen set to true, disables the component, preventing user interaction or triggering of associated actions.
textValuestringOptional text used for typeahead purposes. By default the typeahead behavior will use the .textContent of the item. Use this when the content is complex, or you have non-textual content inside.
onSelectfunctionEvent handler called when the user selects an item (via mouse or keyboard). Calling event.preventDefault in this handler will prevent the menubar from closing when selecting that item.

ContextMenuItemIndicator

PropTypeDescription
asChildbooleanWhen set to true, renders the component as its child element, inheriting the child's styles and behavior.
forceMountbooleanUsed to force mounting when more control is needed. Useful when controlling animation with React animation libraries. It inherits from.

ContextMenuSeparator

PropTypeDescription
asChildbooleanWhen set to true, renders the component as its child element, inheriting the child's styles and behavior.

ContextMenuSub

PropTypeDescription
defaultOpenbooleanDetermines whether the component should be open by default when it is initially rendered.
openbooleanControls the open state of the component. When set to true, the component is displayed; when false, it is hidden.
onOpenChangefunctionEvent handler called when the open state of the component changes.

ContextMenuSubTrigger

PropTypeDescription
asChildbooleanWhen set to true, renders the component as its child element, inheriting the child's styles and behavior.
disabledbooleanWhen set to true, disables the component, preventing user interaction or triggering of associated actions.
textValuestringOptional text used for typeahead purposes. By default the typeahead behavior will use the .textContent of the item. Use this when the content is complex, or you have non-textual content inside.

ContextMenuSubContent

PropTypeDescription
sticky"partial" | "always"The sticky behavior on the align axis. 'partial' will keep the content in the boundary as long as the trigger is at least partially in the boundary whilst 'always' will keep the content in the boundary regardless.
asChildbooleanWhen set to true, renders the component as its child element, inheriting the child's styles and behavior.
loopbooleanWhen true, keyboard navigation will loop from last item to first, and vice versa.
forceMountbooleanUsed to force mounting when more control is needed. Useful when controlling animation with React animation libraries. It inherits from.
avoidCollisionsbooleanWhen true, overrides the side andalign preferences to prevent collisions with boundary edges.
hideWhenDetachedbooleanWhether to hide the content when the trigger becomes fully occluded.
sideOffsetnumberThe distance in pixels from the anchor.
alignOffsetnumberAn offset in pixels from the 'start' or 'end' alignment options.
collisionPaddingnumberThe distance in pixels from the boundary edges where collision detection should occur. Accepts a number (same for all sides), or a partial padding object, for example: { top: 20, left: 20 }.
arrowPaddingnumberThe padding between the arrow and the edges of the content. If your content has border-radius, this will prevent it from overflowing the corners.
onOpenAutoFocusfunctionEvent handler called when focus moves into the component after opening. It can be prevented by calling event.preventDefault.
onCloseAutoFocusfunctionEvent handler called when focus moves to the trigger after closing. It can be prevented by calling event.preventDefault.
onEscapeKeyDownfunctionEvent handler called when the escape key is down. It can be prevented by calling event.preventDefault.
onPointerDownOutsidefunctionEvent handler called when a pointer event occurs outside the bounds of the component. It can be prevented by calling event.preventDefault
onFocusOutsidefunctionEvent handler called when focus moves outside the bounds of the component. It can be prevented by calling event.preventDefault.
onInteractOutsidefunctionEvent handler called when an interaction (pointer or focus event) happens outside the bounds of the component. It can be prevented by calling event.preventDefault.

Keyboard Interactions

KeyDescription
Space
Enter
Activates the focused item.
ArrowDown
Moves focus to the next item.
ArrowUp
Moves focus to the previous item.
Esc
Closes the menu.