Context Menu

Context Menu

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

Right click here

Usage

It's mandatory to wrap the whole component with the Tailwind tag.

const { Tailwind } = VM.require("uiisnear.near/widget/tailwind");
const {
  ContextMenu,
  ContextMenuTrigger,
  ContextMenuContent,
  ContextMenuItem,
  ContextMenuCheckboxItem,
  ContextMenuRadioItem,
  ContextMenuLabel,
  ContextMenuSeparator,
  ContextMenuShortcut,
  ContextMenuGroup,
  ContextMenuSub,
  ContextMenuSubContent,
  ContextMenuSubTrigger,
  ContextMenuRadioGroup,
  contextMenuContentClassname,
  contextMenuSubContentClassname,
} = VM.require("uiisnear.near/widget/contextMenu");
 
if (Tailwind == undefined) return "";
<Tailwind>
  <ContextMenu>
    <ContextMenuTrigger>Right click</ContextMenuTrigger>
    <ContextMenuContent>
      <ContextMenuItem>Profile</ContextMenuItem>
      <ContextMenuItem>Billing</ContextMenuItem>
      <ContextMenuItem>Team</ContextMenuItem>
      <ContextMenuItem>Subscription</ContextMenuItem>
    </ContextMenuContent>
  </ContextMenu>
</Tailwind>

API Reference

ContextMenu

Contains all the parts of a context menu.

PropTypeDefault
dir
enum
---
onOpenChange
function
---
modal
boolean
true

ContextMenuTrigger

The area that opens the context menu. Wrap it around the target you want the context menu to open from when right-clicking (or using the relevant keyboard shortcuts).

PropTypeDefault
disabled
boolean
false
Data attributeValues
[data-state]"open" | "closed"

ContextMenuContent

The component that pops out in an open context menu.

PropTypeDefault
loop
boolean
false
onCloseAutoFocus
function
---
onEscapeKeyDown
function
---
onPointerDownOutside
function
---
onFocusOutside
function
---
onInteractOutside
function
---
forceMount
boolean
---
alignOffset
number
0
avoidCollisions
boolean
true
collisionBoundary
Boundary
[]
collisionPadding
number | Padding
0
sticky
enum
"partial"
hideWhenDetached
boolean
false
Data attributeValues
[data-state]"open" | "closed"
[data-side]"left" | "right" | "bottom" | "top"
[data-align]"start" | "end" | "center"

ContextMenuItem

The component that contains the context menu items.

PropTypeDefault
disabled
boolean
---
onSelect
function
---
textValue
string
---
inset
boolean
---
Data attributeValues
[data-highlighted]Present when highlighted
[data-disabled]Present when disabled

ContextMenuGroup

Used to group multiple ContextMenuItems.

ContextMenuLabel

Used to render a label. It won't be focusable using arrow keys.

PropTypeDefault
inset
boolean
---

ContextMenuCheckboxItem

An item that can be controlled and rendered like a checkbox.

PropTypeDefault
checked
boolean | 'indeterminate'
---
onCheckedChange
function
---
disabled
boolean
---
onSelect
function
---
textValue
string
---
Data attributeValues
[data-state]"checked" | "unchecked" | "indeterminate"
[data-highlighted]Present when highlighted
[data-disabled]Present when disabled

ContextMenuRadioGroup

Used to group multiple ContextMenuRadioItems.

PropTypeDefault
value
string
---
onValueChange
function
---

ContextMenuRadioItem

An item that can be controlled and rendered like a radio.

PropTypeDefault
value*
string
---
disabled
boolean
---
onSelect
function
---
textValue
string
---
Data attributeValues
[data-state]"checked" | "unchecked" | "indeterminate"
[data-highlighted]Present when highlighted
[data-disabled]Present when disabled

ContextMenuSeparator

Used to visually separate items in the context menu.

ContextMenuSub

Contains all the parts of a submenu.

PropTypeDefault
defaultOpen
boolean
---
open
boolean
---
onOpenChange
function
---

ContextMenuSubTrigger

An item that opens a submenu. Must be rendered inside ContextMenuSub.

PropTypeDefault
disabled
boolean
---
textValue
string
---
inset
boolean
---
Data attributeValues
[data-state]"open" | "closed"
[data-highlighted]Present when highlighted
[data-disabled]Present when disabled

ContextMenuSubContent

The component that pops out when a submenu is open. Must be rendered inside ContextMenuSub.

PropTypeDefault
loop
boolean
false
onEscapeKeyDown
function
---
onPointerDownOutside
function
---
onFocusOutside
function
---
onInteractOutside
function
---
forceMount
boolean
---
sideOffset
number
0
alignOffset
number
0
avoidCollisions
boolean
true
collisionBoundary
Boundary
[]
collisionPadding
number | Padding
0
arrowPadding
number
0
sticky
enum
"partial"
hideWhenDetached
boolean
false
Data attributeValues
[data-state]"open" | "closed"
[data-side]"left" | "right" | "bottom" | "top"
[data-align]"start" | "end" | "center"

Classnames

Classnames available to customize the component.

FunctionClassname
ContextMenuSubTriggercontextMenuSubTriggerClassname
ContextMenuSubContentcontextMenuSubContentClassname
ContextMenuContentcontextMenuContentClassname
ContextMenuItemcontextMenuItemClassname
ContextMenuCheckboxItemcontextMenuCheckboxItemClassname
ContextMenuRadioItemcontextMenuRadioItemClassname
ContextMenuLabelcontextMenuLabelClassname
ContextMenuSeparatorcontextMenuSeparatorClassname
ContextMenuShortcutcontextMenuShortcutClassname