Skip to main content

Documentation Index

Fetch the complete documentation index at: https://cometchat-22654f5b-react-uikit-v7.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

{
  "component": "CometChatContextMenu",
  "package": "@cometchat/chat-uikit-react",
  "import": "import { CometChatContextMenu } from \"@cometchat/chat-uikit-react\";",
  "cssImport": "import \"@cometchat/chat-uikit-react/css-variables.css\";",
  "description": "A context menu that displays top-row icon actions and an overflow dropdown for additional options.",
  "cssRootClass": ".cometchat-context-menu",
  "subComponents": ["Root", "Item", "Trigger", "Dropdown"],
  "props": {
    "Root": {
      "items": { "type": "CometChatContextMenuItemData[]", "default": "[]" },
      "topMenuSize": { "type": "number", "default": "2" },
      "onOptionClicked": { "type": "(item: CometChatContextMenuItemData) => void", "default": "undefined" },
      "placement": { "type": "CometChatContextMenuPlacement", "default": "'left'" },
      "moreButtonTooltip": { "type": "string", "default": "undefined" },
      "closeOnOutsideClick": { "type": "boolean", "default": "true" },
      "className": { "type": "string", "default": "undefined" },
      "children": { "type": "ReactNode", "default": "undefined" }
    },
    "Item": {
      "item": { "type": "CometChatContextMenuItemData", "default": "undefined", "note": "Required." },
      "variant": { "type": "'icon' | 'full'", "default": "'full'" },
      "className": { "type": "string", "default": "undefined" }
    },
    "Trigger": {
      "tooltip": { "type": "string", "default": "undefined" },
      "className": { "type": "string", "default": "undefined" },
      "children": { "type": "ReactNode", "default": "undefined" }
    },
    "Dropdown": {
      "placement": { "type": "CometChatContextMenuPlacement", "default": "inherited from Root" },
      "className": { "type": "string", "default": "undefined" },
      "children": { "type": "ReactNode", "default": "undefined" }
    }
  },
  "types": {
    "CometChatContextMenuItemData": {
      "id": "string",
      "title": "string",
      "icon": "ReactNode (optional)",
      "iconURL": "string (optional)",
      "onClick": "() => void",
      "disabled": "boolean (optional)",
      "className": "string (optional)"
    },
    "CometChatContextMenuPlacement": "'top' | 'right' | 'bottom' | 'left'",
    "CometChatContextMenuContextValue": {
      "isOpen": "boolean",
      "open": "() => void",
      "close": "() => void",
      "toggle": "() => void",
      "placement": "CometChatContextMenuPlacement",
      "onOptionClicked": "(item: CometChatContextMenuItemData) => void | undefined",
      "triggerRef": "RefObject<HTMLButtonElement | null>"
    }
  }
}

Where It Fits

CometChatContextMenu is a base component used as the overflow action menu across the UI Kit. It appears on message bubbles, conversation list items, group member rows, user list items, and message headers. It splits actions into a visible top row of icon buttons and a dropdown for the rest.
import { CometChatContextMenu } from "@cometchat/chat-uikit-react";
import "@cometchat/chat-uikit-react/css-variables.css";

const options = [
  { id: "edit", title: "Edit", icon: <EditIcon />, onClick: () => handleEdit() },
  { id: "copy", title: "Copy", icon: <CopyIcon />, onClick: () => handleCopy() },
  { id: "info", title: "Info", icon: <InfoIcon />, onClick: () => handleInfo() },
  { id: "delete", title: "Delete", icon: <DeleteIcon />, onClick: () => handleDelete() },
];

function MessageBubbleActions() {
  return (
    <CometChatContextMenu.Root
      items={options}
      topMenuSize={2}
      placement="left"
      onOptionClicked={(item) => console.log("Selected:", item.id)}
    />
  );
}

Minimal Render

import { CometChatContextMenu } from "@cometchat/chat-uikit-react";
import "@cometchat/chat-uikit-react/css-variables.css";

function Demo() {
  return (
    <CometChatContextMenu.Root
      items={[
        { id: "1", title: "Edit", onClick: () => {} },
        { id: "2", title: "Delete", onClick: () => {} },
      ]}
      topMenuSize={1}
    />
  );
}
Root CSS class: .cometchat-context-menu

Sub-Components

CometChatContextMenu is a compound component with four sub-components:
Sub-componentPurpose
RootContainer that provides context, orchestrates top-row items and dropdown.
ItemA single action rendered as a button. Supports icon (top-row) and full (dropdown) variants.
TriggerThe “more” button that toggles the dropdown.
DropdownThe overflow popover with keyboard navigation and focus trap.

Root

The outermost wrapper. In data-driven mode, pass items and topMenuSize and it renders everything automatically. For full control, pass children instead.
<CometChatContextMenu.Root
  items={options}
  topMenuSize={2}
  placement="left"
  closeOnOutsideClick
/>

Item

Renders a single action. In icon variant, it shows only the icon with an aria-label. In full variant, it shows icon + title and uses role="menuitem".
<CometChatContextMenu.Item
  item={{
    id: "edit",
    title: "Edit Message",
    icon: <EditIcon />,
    onClick: () => handleEdit(),
  }}
  variant="full"
/>

Trigger

The “more” button. Renders a vertical ellipsis icon by default. Pass children for a custom trigger.
<CometChatContextMenu.Trigger tooltip="Show more">
  <span></span>
</CometChatContextMenu.Trigger>
The overflow popover. Positioned relative to the root container using the placement prop. Includes full keyboard navigation and a focus trap.
<CometChatContextMenu.Dropdown placement="bottom">
  <CometChatContextMenu.Item item={action1} variant="full" />
  <CometChatContextMenu.Item item={action2} variant="full" />
</CometChatContextMenu.Dropdown>

Actions and Events

Callback Props

onOptionClicked

Called when any menu item is selected (top-row or dropdown). Receives the full CometChatContextMenuItemData object. When provided, overrides individual item.onClick callbacks.
<CometChatContextMenu.Root
  items={options}
  topMenuSize={2}
  onOptionClicked={(item) => {
    console.log("Selected action:", item.id, item.title);
  }}
/>

Custom View Slots

SlotSignatureReplaces
children on RootReactNodeEntire auto-generated layout (top-row + trigger + dropdown)
children on TriggerReactNodeDefault “more” icon
children on DropdownReactNodeAuto-generated dropdown items

Custom trigger content

<CometChatContextMenu.Root placement="bottom">
  <CometChatContextMenu.Item item={editAction} variant="icon" />
  <CometChatContextMenu.Trigger>
    <span style={{ fontSize: 14, padding: "0 4px" }}></span>
  </CometChatContextMenu.Trigger>
  <CometChatContextMenu.Dropdown>
    <CometChatContextMenu.Item item={copyAction} variant="full" />
    <CometChatContextMenu.Item item={deleteAction} variant="full" />
  </CometChatContextMenu.Dropdown>
</CometChatContextMenu.Root>

Common Patterns

Message bubble options

import { CometChatContextMenu } from "@cometchat/chat-uikit-react";

function MessageOptions({ options }) {
  return (
    <CometChatContextMenu.Root
      items={options}
      topMenuSize={2}
      placement="left"
      closeOnOutsideClick
    />
  );
}

All items in dropdown (no top row)

<CometChatContextMenu.Root items={options} topMenuSize={0} placement="bottom" />

All items in top row (no dropdown)

<CometChatContextMenu.Root items={options.slice(0, 3)} topMenuSize={10} />

Keyboard Navigation

The context menu is fully keyboard-accessible:
KeyBehavior
TabMoves focus between top-row items and the trigger button
Enter / SpaceOn top-row item: activates it. On trigger: toggles dropdown
ArrowDownOn trigger: opens dropdown. In dropdown: moves to next item (wraps)
ArrowUpIn dropdown: moves to previous item (wraps)
HomeIn dropdown: moves focus to first item
EndIn dropdown: moves focus to last item
EscapeCloses dropdown and returns focus to trigger
Tab (in dropdown)Cycles within dropdown items (focus trap)
When the dropdown opens, focus moves to the first enabled item. When it closes, focus returns to the trigger button.

CSS Architecture

The component uses CSS custom properties (design tokens) defined in @cometchat/chat-uikit-react/css-variables.css. The cascade:
  1. Global tokens set on the .cometchat root wrapper.
  2. Component CSS (.cometchat-context-menu) consumes these tokens via var().
  3. Overrides target .cometchat-context-menu descendant selectors.

Key Selectors

TargetSelector
Root container.cometchat-context-menu
Top menu row.cometchat-context-menu__top-menu
Top menu item.cometchat-context-menu__top-menu-item
Top menu item icon.cometchat-context-menu__top-menu-item-icon
Trigger button.cometchat-context-menu__trigger
Trigger icon.cometchat-context-menu__trigger-icon
Dropdown.cometchat-context-menu__dropdown
Dropdown item.cometchat-context-menu__dropdown-item
Dropdown item icon.cometchat-context-menu__dropdown-item-icon
Dropdown item title.cometchat-context-menu__dropdown-item-title

Example: Brand-themed context menu

App.css
.cometchat-context-menu__dropdown {
  border-radius: 12px;
  border-color: var(--brand-border);
}

.cometchat-context-menu__dropdown-item:hover:not(:disabled) {
  background: var(--brand-hover);
}

.cometchat-context-menu__top-menu-item:hover:not(:disabled) {
  background: var(--brand-hover);
}

Customization Matrix

What to changeWhereProperty/APIExample
Menu itemsComponent propsitems on Root<Root items={myItems}>
Top row countComponent propstopMenuSize on Root<Root topMenuSize={3}>
Dropdown positionComponent propsplacement on Root or Dropdown<Root placement="bottom">
Handle selectionComponent propsonOptionClicked on Root<Root onOptionClicked={handler}>
Disable an itemItem datadisabled on CometChatContextMenuItemData{ disabled: true }
Custom triggerSub-componentchildren on Trigger<Trigger><MyIcon /></Trigger>
Change visual stylingGlobal CSS.cometchat-context-menu selectorsSee example above

Props

All props are optional unless noted otherwise.

CometChatContextMenu.Root

items

Array of menu item data objects. When provided without children, the component auto-renders top-row items and dropdown.
TypeCometChatContextMenuItemData[]
Default[]
interface CometChatContextMenuItemData {
  id: string;
  title: string;
  icon?: ReactNode;
  iconURL?: string;
  onClick: () => void;
  disabled?: boolean;
  className?: string;
}

topMenuSize

Number of items visible in the top row. Remaining items go to the dropdown. When 0, all items are in the dropdown. When >= items.length, no dropdown is rendered.
Typenumber
Default2

onOptionClicked

Called when any menu item is selected. Receives the full item data object. When provided, overrides individual item.onClick callbacks.
Type(item: CometChatContextMenuItemData) => void
Defaultundefined

placement

Position of the dropdown relative to the trigger.
Type'top' | 'right' | 'bottom' | 'left'
Default'left'

moreButtonTooltip

Tooltip text for the “more” trigger button.
Typestring
Defaultundefined

closeOnOutsideClick

Whether clicking outside the component closes the dropdown.
Typeboolean
Defaulttrue

className

Custom CSS class appended to the root container.
Typestring
Defaultundefined

children

Custom content. When provided, overrides the data-driven rendering entirely.
TypeReactNode
Defaultundefined

CometChatContextMenu.Item

item

The menu item data object.
TypeCometChatContextMenuItemData
Defaultundefined
Required.

variant

Display mode. icon renders icon-only (for top row). full renders icon + title (for dropdown).
Type'icon' | 'full'
Default'full'

className

Custom CSS class appended to the item button.
Typestring
Defaultundefined

CometChatContextMenu.Trigger

tooltip

Tooltip and aria-label text for the trigger button.
Typestring
Defaultundefined

className

Custom CSS class appended to the trigger button.
Typestring
Defaultundefined

children

Custom trigger content. Replaces the default vertical ellipsis icon.
TypeReactNode
Defaultundefined

CometChatContextMenu.Dropdown

placement

Position of the dropdown. Overrides the value from Root context.
Type'top' | 'right' | 'bottom' | 'left'
Defaultinherited from Root

className

Custom CSS class appended to the dropdown container.
Typestring
Defaultundefined

children

Dropdown content. Typically CometChatContextMenu.Item elements with variant="full".
TypeReactNode
Defaultundefined

CSS Selectors

TargetSelector
Root.cometchat-context-menu
Top menu row.cometchat-context-menu__top-menu
Top menu item.cometchat-context-menu__top-menu-item
Top menu item icon.cometchat-context-menu__top-menu-item-icon
Trigger button.cometchat-context-menu__trigger
Trigger icon.cometchat-context-menu__trigger-icon
Dropdown.cometchat-context-menu__dropdown
Dropdown (top).cometchat-context-menu__dropdown--top
Dropdown (right).cometchat-context-menu__dropdown--right
Dropdown (bottom).cometchat-context-menu__dropdown--bottom
Dropdown (left).cometchat-context-menu__dropdown--left
Dropdown item.cometchat-context-menu__dropdown-item
Dropdown item (disabled).cometchat-context-menu__dropdown-item--disabled
Dropdown item icon.cometchat-context-menu__dropdown-item-icon
Dropdown item title.cometchat-context-menu__dropdown-item-title