# Context Menu
Actions for one element, opened by right click, long press or agent.
Source page: https://dinachi.dev/docs/components/context-menu

## Installation
```bash
npx @dinachi/cli@latest add context-menu
```
Adds to your project:
- `components/ui/context-menu/context-menu.tsx`
- `components/ui/context-menu/index.ts`
Installs:
- `@base-ui/react` ^1.9.0
- `lucide-react` ^0.552.0

## Usage
```tsx
import {
  ContextMenu,
  ContextMenuContent,
  ContextMenuItem,
  ContextMenuTrigger,
} from "@/components/ui/context-menu"

export function FileMenu() {
  return (
    <ContextMenu>
      <ContextMenuTrigger className="rounded-md border border-dashed p-8 text-sm">
        Report.pdf
      </ContextMenuTrigger>
      <ContextMenuContent>
        <ContextMenuItem>Open</ContextMenuItem>
        <ContextMenuItem>Rename</ContextMenuItem>
        <ContextMenuItem>Delete</ContextMenuItem>
      </ContextMenuContent>
    </ContextMenu>
  )
}
```

## Anatomy
```tsx
<ContextMenu>
  <ContextMenuTrigger />
  <ContextMenuContent>
    <ContextMenuItem>
      <ContextMenuShortcut />
    </ContextMenuItem>
    <ContextMenuLinkItem />
    <ContextMenuCheckboxItem />
    <ContextMenuGroup>
      <ContextMenuLabel />
      <ContextMenuRadioGroup>
        <ContextMenuRadioItem />
      </ContextMenuRadioGroup>
    </ContextMenuGroup>
    <ContextMenuSeparator />
    <ContextMenuSub>
      <ContextMenuSubTrigger />
      <ContextMenuSubContent />
    </ContextMenuSub>
  </ContextMenuContent>
</ContextMenu>
```
- `ContextMenu`: Holds the open state.
- `ContextMenuTrigger`: The area that opens the menu.
- `ContextMenuContent`: The popup, portalled and positioned at the pointer.
- `ContextMenuItem`: One action.
- `ContextMenuLinkItem`: An item that navigates.
- `ContextMenuCheckboxItem`: An item that toggles, with a check when on.
- `ContextMenuRadioGroup`: Holds the value of a set of radio items.
- `ContextMenuRadioItem`: One radio choice, dotted when chosen.
- `ContextMenuGroup`: Groups items under a `ContextMenuLabel`.
- `ContextMenuLabel`: The heading of a group.
- `ContextMenuSeparator`: A line between groups.
- `ContextMenuShortcut`: A display-only key hint.
- `ContextMenuSub`: Holds the open state of a submenu.
- `ContextMenuSubTrigger`: Opens a submenu; shows a chevron.
- `ContextMenuSubContent`: The submenu popup, portalled beside its trigger.
- `ContextMenuPortal`: Portals children to the body. `ContextMenuContent` includes it.
- `ContextMenuPositioner`: Positions the popup. `ContextMenuContent` includes it.

## Examples

### Default
Items with shortcuts and a disabled item.
```tsx
import {
  ContextMenu,
  ContextMenuContent,
  ContextMenuItem,
  ContextMenuTrigger,
  ContextMenuShortcut,
  ContextMenuSeparator,
} from '@/components/ui/context-menu';

export function Example() {
  return (
    <ContextMenu>
      <ContextMenuTrigger className="flex h-[150px] w-[300px] items-center justify-center rounded-md border border-dashed text-sm bg-card hover:bg-accent/50 transition-colors">
        Right click here
      </ContextMenuTrigger>
      <ContextMenuContent className="w-64">
        <ContextMenuItem>
          Back
          <ContextMenuShortcut>⌘[</ContextMenuShortcut>
        </ContextMenuItem>
        <ContextMenuItem disabled>
          Forward
          <ContextMenuShortcut>⌘]</ContextMenuShortcut>
        </ContextMenuItem>
        <ContextMenuItem>
          Reload
          <ContextMenuShortcut>⌘R</ContextMenuShortcut>
        </ContextMenuItem>
        <ContextMenuSeparator />
        <ContextMenuItem>
          Developer Tools
          <ContextMenuShortcut>F12</ContextMenuShortcut>
        </ContextMenuItem>
      </ContextMenuContent>
    </ContextMenu>
  );
}
```

### Checkbox items
Toggle options without closing the menu.
```tsx
import React from 'react';
import {
  ContextMenu,
  ContextMenuContent,
  ContextMenuItem,
  ContextMenuCheckboxItem,
  ContextMenuTrigger,
  ContextMenuShortcut,
  ContextMenuSeparator,
} from '@/components/ui/context-menu';

export function Example() {
  const [bookmarksBar, setBookmarksBar] = React.useState(true);
  const [showFullUrls, setShowFullUrls] = React.useState(false);

  return (
    <ContextMenu>
      <ContextMenuTrigger className="flex h-[150px] w-[300px] items-center justify-center rounded-md border border-dashed text-sm bg-card hover:bg-accent/50 transition-colors">
        Right click for checkbox menu
      </ContextMenuTrigger>
      <ContextMenuContent>
        <ContextMenuCheckboxItem
          checked={bookmarksBar}
          onCheckedChange={setBookmarksBar}
        >
          Show Bookmarks Bar
        </ContextMenuCheckboxItem>
        <ContextMenuCheckboxItem
          checked={showFullUrls}
          onCheckedChange={setShowFullUrls}
        >
          Show Full URLs
        </ContextMenuCheckboxItem>
        <ContextMenuSeparator />
        <ContextMenuItem>
          Reload
          <ContextMenuShortcut>⌘R</ContextMenuShortcut>
        </ContextMenuItem>
      </ContextMenuContent>
    </ContextMenu>
  );
}
```

### Radio group
Pick one option from a set.
```tsx
import React from 'react';
import {
  ContextMenu,
  ContextMenuContent,
  ContextMenuRadioGroup,
  ContextMenuRadioItem,
  ContextMenuTrigger,
  ContextMenuGroup,
  ContextMenuLabel,
  ContextMenuSeparator,
} from '@/components/ui/context-menu';

export function Example() {
  const [person, setPerson] = React.useState('pedro');

  return (
    <ContextMenu>
      <ContextMenuTrigger className="flex h-[150px] w-[300px] items-center justify-center rounded-md border border-dashed text-sm bg-card hover:bg-accent/50 transition-colors">
        Right click for radio menu
        <br />
        <span className="text-xs text-muted-foreground mt-1">
          Current: {person}
        </span>
      </ContextMenuTrigger>
      <ContextMenuContent>
        <ContextMenuGroup>
          <ContextMenuLabel>People</ContextMenuLabel>
          <ContextMenuSeparator />
          <ContextMenuRadioGroup value={person} onValueChange={setPerson}>
            <ContextMenuRadioItem value="pedro">Pedro</ContextMenuRadioItem>
            <ContextMenuRadioItem value="colm">Colm</ContextMenuRadioItem>
            <ContextMenuRadioItem value="sarah">Sarah</ContextMenuRadioItem>
          </ContextMenuRadioGroup>
        </ContextMenuGroup>
      </ContextMenuContent>
    </ContextMenu>
  );
}
```

### Submenu
Nest options under a trigger item.
```tsx
import {
  ContextMenu,
  ContextMenuContent,
  ContextMenuItem,
  ContextMenuTrigger,
  ContextMenuShortcut,
  ContextMenuSeparator,
  ContextMenuSub,
  ContextMenuSubContent,
  ContextMenuSubTrigger,
} from '@/components/ui/context-menu';

export function Example() {
  return (
    <ContextMenu>
      <ContextMenuTrigger className="flex h-[150px] w-[300px] items-center justify-center rounded-md border border-dashed text-sm bg-card hover:bg-accent/50 transition-colors">
        Right click for submenu
      </ContextMenuTrigger>
      <ContextMenuContent>
        <ContextMenuItem>
          Back
          <ContextMenuShortcut>⌘[</ContextMenuShortcut>
        </ContextMenuItem>
        <ContextMenuItem>
          Forward
          <ContextMenuShortcut>⌘]</ContextMenuShortcut>
        </ContextMenuItem>
        <ContextMenuSeparator />
        <ContextMenuSub>
          <ContextMenuSubTrigger>More Tools</ContextMenuSubTrigger>
          <ContextMenuSubContent>
            <ContextMenuItem>Save Page As...</ContextMenuItem>
            <ContextMenuItem>Create Shortcut...</ContextMenuItem>
            <ContextMenuItem>Developer Tools</ContextMenuItem>
          </ContextMenuSubContent>
        </ContextMenuSub>
        <ContextMenuSeparator />
        <ContextMenuItem>
          Inspect Element
          <ContextMenuShortcut>⌘⇧C</ContextMenuShortcut>
        </ContextMenuItem>
      </ContextMenuContent>
    </ContextMenu>
  );
}
```

## Notes

### Checkbox and radio items
`ContextMenuCheckboxItem` and `ContextMenuRadioItem` keep the menu open when chosen. Pass `closeOnClick` to close on choice.

## API reference
Props marked **agent** change what an agent reads or may do.

### ContextMenu
Holds the open state.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `open` | `boolean` | - | Controlled open state. |
| `defaultOpen` | `boolean` | `false` | Starting open state when uncontrolled. |
| `onOpenChange` **agent** | `(open, details) => void` | - | Runs on open and close, from either side. `details.cancel()` refuses it. |
| `disabled` **agent** | `boolean` | `false` | Ignores right clicks and long presses, and blocks agents. |
| `loopFocus` | `boolean` | `true` | Wraps the keyboard highlight from the last item to the first. |
| `highlightItemOnHover` | `boolean` | `true` | Moves the highlight with the pointer. |

### ContextMenuTrigger
The area that opens the menu.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` **agent** | `ReactNode` | - | The area's content. Its text, or an aria-label, is the agent's name for it. |
| `render` | `ReactElement` | - | Swap the element, keep the behaviour. |

### ContextMenuContent
The popup, portalled and positioned at the pointer.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` | - | Classes for the popup, such as a width. |

### ContextMenuItem
One action.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `onClick` | `(event) => void` | - | Runs when the item is chosen. |
| `inset` | `boolean` | `false` | Indents the item to line up with checkbox and radio items. |
| `closeOnClick` | `boolean` | `true` | Closes the menu once chosen. |
| `disabled` **agent** | `boolean` | `false` | Skipped by the keyboard, refused for agents. |

### ContextMenuLinkItem
An item that navigates.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `href` | `string` | - | Where the item goes. |
| `closeOnClick` | `boolean` | `false` | Closes the menu once followed. |

### ContextMenuCheckboxItem
An item that toggles, with a check when on.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `checked` **agent** | `boolean` | - | Controlled checked state. |
| `defaultChecked` | `boolean` | `false` | Starting state when uncontrolled. |
| `onCheckedChange` | `(checked, details) => void` | - | Runs on toggle. |
| `closeOnClick` | `boolean` | `false` | Closes the menu on toggle. |
| `disabled` **agent** | `boolean` | `false` | Skipped by the keyboard, refused for agents. |

### ContextMenuRadioGroup
Holds the value of a set of radio items.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `value` | `any` | - | Controlled value. |
| `defaultValue` | `any` | - | Starting value when uncontrolled. |
| `onValueChange` | `(value, details) => void` | - | Runs when a radio item is chosen. |

### ContextMenuRadioItem
One radio choice, dotted when chosen.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `value` | `any` | - | What `onValueChange` receives. |
| `closeOnClick` | `boolean` | `false` | Closes the menu on choice. |
| `disabled` **agent** | `boolean` | `false` | Skipped by the keyboard, refused for agents. |

### ContextMenuGroup
Groups items under a `ContextMenuLabel`.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `ReactNode` | - | A `ContextMenuLabel`, then items. |

### ContextMenuLabel
The heading of a group.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `inset` | `boolean` | `false` | Indents the label to line up with checkbox and radio items. |

### ContextMenuSeparator
A line between groups.

Takes the props of the element it renders.

### ContextMenuShortcut
A display-only key hint.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `ReactNode` | - | The shortcut text, for example ⌘R. |

### ContextMenuSub
Holds the open state of a submenu.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `open` | `boolean` | - | Controlled open state. |
| `onOpenChange` | `(open, details) => void` | - | Runs when the submenu opens or closes. |

### ContextMenuSubTrigger
Opens a submenu; shows a chevron.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `inset` | `boolean` | `false` | Indents the item to line up with checkbox and radio items. |
| `disabled` | `boolean` | `false` | Keeps the submenu shut. |

### ContextMenuSubContent
The submenu popup, portalled beside its trigger.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` | - | Classes for the popup. |

### ContextMenuPortal
Portals children to the body. `ContextMenuContent` includes it.

Takes the props of the element it renders.

### ContextMenuPositioner
Positions the popup. `ContextMenuContent` includes it.

Takes the props of the element it renders.

## Agent
Inside an `AgentProvider`, Context Menu appears in `agent.snapshot()` as `menu`.
Reads:
- `label`: The trigger's aria-label or text while closed.
- `open`: Whether the menu is showing.
- `disabled`: True when the whole menu is disabled.
Actions:
- `open() / close()`: Whichever fits the current state. Needs no pointer.
- `press()`: On an item, once the menu is open. Items are listed as `menuitem`.
- `setChecked(true)`: On a checkbox item. Presses it only if the state differs.
Opening and closing run through `onOpenChange`. `isAgentChange(details)` is true for an agent's change, and `details.cancel()` refuses it; the agent is told the app refused. Item presses arrive as ordinary clicks; refuse those in the item's handler. A disabled menu and disabled items refuse on their own.
```ts
await agent.act({
  steps: [{ ref: "Right click here", action: "open" }],
})
```

## Accessibility
- The popup is a menu; items are menuitem, menuitemcheckbox or menuitemradio, with checked state.
- On touch, a 500ms long press opens the menu.
- Right click is hard to discover and absent on many devices. Offer the actions elsewhere too.
- Disabled items stay announced but are skipped by the keyboard.
### Keyboard
| Keys | Does |
| --- | --- |
| `↑` / `↓` | Moves the highlight |
| `Home` / `End` | Jumps to the first or last item |
| `Enter` / `Space` | Chooses the highlighted item |
| `→` | Opens the highlighted submenu |
| `←` | Closes the current submenu |
| `A` to `Z` | Jumps to the next item starting with that letter |
| `Esc` | Closes the menu |

## Source
`components/ui/context-menu/context-menu.tsx`
```tsx
"use client"

import * as React from "react"
import { ContextMenu as BaseContextMenu } from "@base-ui/react/context-menu"
import { cn } from "@/lib/utils"
import { Check, ChevronRight, Circle } from "lucide-react"
import { type AgentOpenParts, useAgentOpen, useHasAgent, useMergedRef } from "@/components/ui/agent"

const ContextMenuAgentContext = React.createContext<(AgentOpenParts & { disabled?: boolean }) | null>(null)

/**
 * Base UI places the popup at the point a right-click or long press set. Opened any other
 * way, by an agent or a controlled `open`, there is no such point and it lands in the top
 * left corner, so the positioner anchors on the middle of the trigger area instead.
 */
const ContextMenuAnchorContext = React.createContext<{
  pointed: React.RefObject<boolean>
  trigger: React.RefObject<HTMLElement | null>
} | null>(null)

/**
 * Base UI's root, holding its own open state so an agent can open and close it. Closed,
 * the agent sees the trigger area, named by its `aria-label` or text; open, the popup.
 * The trigger area carries the root's `disabled`, which Base UI does not mark on it.
 */
const ContextMenu: React.FC<React.ComponentProps<typeof BaseContextMenu.Root>> = ({
  open,
  defaultOpen,
  onOpenChange,
  ...props
}) => {
  const [state, change, parts] = useAgentOpen("menu", open, defaultOpen, onOpenChange)
  const pointed = React.useRef(false)
  const trigger = React.useRef<HTMLElement | null>(null)
  const anchor = React.useMemo(() => ({ pointed, trigger }), [])
  if (!state) pointed.current = false
  const onChange: typeof change = (next, details) => {
    if (next) pointed.current = details.reason === "trigger-press"
    change(next, details)
  }
  return (
    <ContextMenuAnchorContext.Provider value={anchor}>
      <ContextMenuAgentContext.Provider value={useHasAgent() ? { ...parts, disabled: props.disabled } : null}>
        <BaseContextMenu.Root {...props} open={state} onOpenChange={onChange} />
      </ContextMenuAgentContext.Provider>
    </ContextMenuAnchorContext.Provider>
  )
}
ContextMenu.displayName = "ContextMenu"

const ContextMenuTrigger = React.forwardRef<
  React.ComponentRef<typeof BaseContextMenu.Trigger>,
  React.ComponentProps<typeof BaseContextMenu.Trigger>
>(({ className, ...props }, ref) => {
  const agent = React.useContext(ContextMenuAgentContext)
  const anchor = React.useContext(ContextMenuAnchorContext)
  return (
    <BaseContextMenu.Trigger
      ref={useMergedRef(ref, agent?.trigger, anchor?.trigger)}
      data-disabled={agent?.disabled ? "" : undefined}
      className={cn("select-none", className)}
      data-slot="context-menu-trigger"
      {...props}
    />
  )
})
ContextMenuTrigger.displayName = "ContextMenuTrigger"

const ContextMenuPortal: React.FC<
  React.ComponentProps<typeof BaseContextMenu.Portal>
> = (props) => <BaseContextMenu.Portal data-slot="context-menu-portal" {...props} />
ContextMenuPortal.displayName = "ContextMenuPortal"

const ContextMenuPositioner = React.forwardRef<
  React.ComponentRef<typeof BaseContextMenu.Positioner>,
  React.ComponentProps<typeof BaseContextMenu.Positioner>
>(({ className, anchor, ...props }, ref) => {
  const ctx = React.useContext(ContextMenuAnchorContext)
  const middle = React.useMemo(
    () =>
      ctx && {
        getBoundingClientRect() {
          const r = ctx.trigger.current?.getBoundingClientRect()
          return r ? DOMRect.fromRect({ x: r.x + r.width / 2, y: r.y + r.height / 2, width: 0, height: 0 }) : new DOMRect()
        },
      },
    [ctx]
  )
  return (
    <BaseContextMenu.Positioner
      ref={ref}
      anchor={anchor ?? (ctx && !ctx.pointed.current ? middle : undefined)}
      className={cn("z-50 outline-none", className)}
      data-slot="context-menu-positioner"
      {...props}
    />
  )
})
ContextMenuPositioner.displayName = "ContextMenuPositioner"

const ContextMenuContent = React.forwardRef<
  React.ComponentRef<typeof BaseContextMenu.Popup>,
  React.ComponentProps<typeof BaseContextMenu.Popup>
>(({ className, ...props }, ref) => (
  <ContextMenuPortal>
    <ContextMenuPositioner>
      <BaseContextMenu.Popup
        ref={useMergedRef(ref, React.useContext(ContextMenuAgentContext)?.popup)}
        className={cn(
          "min-w-48 overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg",
          "origin-[var(--transform-origin)]",
          "outline-none focus:outline-none focus-visible:outline-none",
          "transition-[transform,scale,opacity] duration-[var(--motion-duration-fast,150ms)] ease-[var(--motion-ease-out,cubic-bezier(0.23,1,0.32,1))]",
          "data-[starting-style]:scale-95 data-[starting-style]:opacity-0",
          "data-[ending-style]:scale-95 data-[ending-style]:opacity-0",
          "motion-reduce:data-[starting-style]:scale-100 motion-reduce:data-[ending-style]:scale-100",
          className
        )}
        data-slot="context-menu-content"
        {...props}
      />
    </ContextMenuPositioner>
  </ContextMenuPortal>
))
ContextMenuContent.displayName = "ContextMenuContent"

const ContextMenuItem = React.forwardRef<
  React.ComponentRef<typeof BaseContextMenu.Item>,
  React.ComponentProps<typeof BaseContextMenu.Item> & {
    inset?: boolean
  }
>(({ className, inset, ...props }, ref) => (
  <BaseContextMenu.Item
    ref={ref}
    className={cn(
      "relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none",
      "focus:bg-accent focus:text-accent-foreground",
      "data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
      "data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground",
      inset && "pl-8",
      className
    )}
    data-slot="context-menu-item"
    {...props}
  />
))
ContextMenuItem.displayName = "ContextMenuItem"

const ContextMenuLinkItem = React.forwardRef<
  React.ComponentRef<typeof BaseContextMenu.LinkItem>,
  React.ComponentProps<typeof BaseContextMenu.LinkItem>
>(({ className, ...props }, ref) => (
  <BaseContextMenu.LinkItem
    ref={ref}
    className={cn(
      "relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none",
      "focus:bg-accent focus:text-accent-foreground",
      "data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground",
      className
    )}
    data-slot="context-menu-link-item"
    {...props}
  />
))
ContextMenuLinkItem.displayName = "ContextMenuLinkItem"

const ContextMenuCheckboxItem = React.forwardRef<
  React.ComponentRef<typeof BaseContextMenu.CheckboxItem>,
  React.ComponentProps<typeof BaseContextMenu.CheckboxItem>
>(({ className, children, ...props }, ref) => (
  <BaseContextMenu.CheckboxItem
    ref={ref}
    className={cn(
      "relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none",
      "focus:bg-accent focus:text-accent-foreground",
      "data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
      "data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground",
      className
    )}
    data-slot="context-menu-checkbox-item"
    {...props}
  >
    <BaseContextMenu.CheckboxItemIndicator className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
      <Check className="h-4 w-4" />
    </BaseContextMenu.CheckboxItemIndicator>
    {children}
  </BaseContextMenu.CheckboxItem>
))
ContextMenuCheckboxItem.displayName = "ContextMenuCheckboxItem"

const ContextMenuRadioGroup = React.forwardRef<
  React.ComponentRef<typeof BaseContextMenu.RadioGroup>,
  React.ComponentProps<typeof BaseContextMenu.RadioGroup>
>(({ className, ...props }, ref) => (
  <BaseContextMenu.RadioGroup ref={ref} className={className} data-slot="context-menu-radio-group" {...props} />
))
ContextMenuRadioGroup.displayName = "ContextMenuRadioGroup"

const ContextMenuRadioItem = React.forwardRef<
  React.ComponentRef<typeof BaseContextMenu.RadioItem>,
  React.ComponentProps<typeof BaseContextMenu.RadioItem>
>(({ className, children, ...props }, ref) => (
  <BaseContextMenu.RadioItem
    ref={ref}
    className={cn(
      "relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none",
      "focus:bg-accent focus:text-accent-foreground",
      "data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
      "data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground",
      className
    )}
    data-slot="context-menu-radio-item"
    {...props}
  >
    <BaseContextMenu.RadioItemIndicator className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
      <Circle className="h-2 w-2 fill-current" />
    </BaseContextMenu.RadioItemIndicator>
    {children}
  </BaseContextMenu.RadioItem>
))
ContextMenuRadioItem.displayName = "ContextMenuRadioItem"

const ContextMenuGroup = React.forwardRef<
  React.ComponentRef<typeof BaseContextMenu.Group>,
  React.ComponentProps<typeof BaseContextMenu.Group>
>(({ className, ...props }, ref) => (
  <BaseContextMenu.Group ref={ref} className={className} data-slot="context-menu-group" {...props} />
))
ContextMenuGroup.displayName = "ContextMenuGroup"

const ContextMenuLabel = React.forwardRef<
  React.ComponentRef<typeof BaseContextMenu.GroupLabel>,
  React.ComponentProps<typeof BaseContextMenu.GroupLabel> & {
    inset?: boolean
  }
>(({ className, inset, ...props }, ref) => (
  <BaseContextMenu.GroupLabel
    ref={ref}
    className={cn(
      "px-2 py-1.5 text-sm font-medium text-foreground",
      inset && "pl-8",
      className
    )}
    data-slot="context-menu-label"
    {...props}
  />
))
ContextMenuLabel.displayName = "ContextMenuLabel"

const ContextMenuSeparator = React.forwardRef<
  React.ComponentRef<typeof BaseContextMenu.Separator>,
  React.ComponentProps<typeof BaseContextMenu.Separator>
>(({ className, ...props }, ref) => (
  <BaseContextMenu.Separator
    ref={ref}
    className={cn("-mx-1 my-1 h-px bg-border", className)}
    data-slot="context-menu-separator"
    {...props}
  />
))
ContextMenuSeparator.displayName = "ContextMenuSeparator"

const ContextMenuShortcut = ({
  className,
  ...props
}: React.HTMLAttributes<HTMLSpanElement>) => (
  <span
    className={cn(
      "ml-auto text-xs tracking-widest text-muted-foreground",
      className
    )}
    data-slot="context-menu-shortcut"
    {...props}
  />
)
ContextMenuShortcut.displayName = "ContextMenuShortcut"

const ContextMenuSub: React.FC<React.ComponentProps<typeof BaseContextMenu.SubmenuRoot>> = (props) => (
  <BaseContextMenu.SubmenuRoot {...props} />
)
ContextMenuSub.displayName = "ContextMenuSub"

const ContextMenuSubTrigger = React.forwardRef<
  React.ComponentRef<typeof BaseContextMenu.SubmenuTrigger>,
  React.ComponentProps<typeof BaseContextMenu.SubmenuTrigger> & {
    inset?: boolean
  }
>(({ className, inset, children, ...props }, ref) => (
  <BaseContextMenu.SubmenuTrigger
    ref={ref}
    className={cn(
      "flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none",
      "focus:bg-accent focus:text-accent-foreground",
      "data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground",
      "data-[popup-open]:bg-accent data-[popup-open]:text-accent-foreground",
      "data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
      inset && "pl-8",
      className
    )}
    data-slot="context-menu-sub-trigger"
    {...props}
  >
    {children}
    <ChevronRight className="ml-auto h-4 w-4" />
  </BaseContextMenu.SubmenuTrigger>
))
ContextMenuSubTrigger.displayName = "ContextMenuSubTrigger"

const ContextMenuSubContent = React.forwardRef<
  React.ComponentRef<typeof BaseContextMenu.Popup>,
  React.ComponentProps<typeof BaseContextMenu.Popup>
>(({ className, ...props }, ref) => (
  <BaseContextMenu.Portal>
    <BaseContextMenu.Positioner className="z-50 outline-none" alignOffset={-4} sideOffset={8}>
      <BaseContextMenu.Popup
        ref={ref}
        className={cn(
          "min-w-32 overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg",
          "origin-[var(--transform-origin)]",
          "outline-none focus:outline-none focus-visible:outline-none",
          "transition-[transform,scale,opacity] duration-[var(--motion-duration-fast,150ms)] ease-[var(--motion-ease-out,cubic-bezier(0.23,1,0.32,1))]",
          "data-[starting-style]:scale-95 data-[starting-style]:opacity-0",
          "data-[ending-style]:scale-95 data-[ending-style]:opacity-0",
          "motion-reduce:data-[starting-style]:scale-100 motion-reduce:data-[ending-style]:scale-100",
          className
        )}
        data-slot="context-menu-sub-content"
        {...props}
      />
    </BaseContextMenu.Positioner>
  </BaseContextMenu.Portal>
))
ContextMenuSubContent.displayName = "ContextMenuSubContent"

export {
  ContextMenu,
  ContextMenuTrigger,
  ContextMenuPortal,
  ContextMenuPositioner,
  ContextMenuContent,
  ContextMenuItem,
  ContextMenuLinkItem,
  ContextMenuCheckboxItem,
  ContextMenuRadioGroup,
  ContextMenuRadioItem,
  ContextMenuGroup,
  ContextMenuLabel,
  ContextMenuSeparator,
  ContextMenuShortcut,
  ContextMenuSub,
  ContextMenuSubTrigger,
  ContextMenuSubContent,
}
```
