Message Context Menu
The menu a message opens on right click or long press, with a row of reactions above its actions.
Installation
npx shadcn@latest add "@aiellie/message-context-menu"shadcn needs the @aiellie registry in components.json first. npx aiellie add message-context-menu adds it on its first run, then installs the same way.
Message Context Menu is the menu a message opens on right click, or on a long press on touch. A row of reactions sits above the message's actions, and pressing the one you already gave takes it back.
The actions are the aiellie menu's own MenuItem, MenuSeparator and MenuSub. This adds the area that opens the menu and the row of reactions.
Getting started
Wrap the message
The trigger fits the message, so a right click in the empty part of the thread opens nothing. Render it as the bubble with
render.components/message-with-menu.tsx"use client" import * as React from "react" import { MenuItem } from "@/components/ui/menu" import { MessagePart } from "@/components/aiellie/message" import { MessageContextMenu, MessageContextMenuContent, MessageContextMenuTrigger, MessageReactionPicker, } from "@/components/aiellie/message-context-menu" export function MessageWithMenu({ text }: { text: string }) { const [reaction, setReaction] = React.useState<string | null>(null) return ( <MessageContextMenu> <MessageContextMenuTrigger render={<MessagePart />}> {text} </MessageContextMenuTrigger> <MessageContextMenuContent> <MessageReactionPicker value={reaction} onValueChange={setReaction} /> <MenuItem onClick={() => navigator.clipboard.writeText(text)}> Copy </MenuItem> </MessageContextMenuContent> </MessageContextMenu> ) }
Anatomy
<div data-slot="message-context-menu-trigger" /> {/* the message */}
<div data-slot="message-context-menu-content"> {/* in a portal, at the pointer */}
<div data-slot="message-reaction-picker" role="group">
<div data-slot="message-reaction" role="menuitemcheckbox" />
</div>
{/* your menu items */}
</div>It's Base UI's context menu with the aiellie menu's surface. The reactions are checkbox items, so they can be taken back, and the menu closes once one is picked.
Examples
Your own reactions
reactions replaces the six defaults.
API reference
MessageReactionPicker
| Prop | Type | Default | Description |
|---|---|---|---|
reactions | string[] | DEFAULT_REACTIONS | 👍 ❤️ 😂 🎉 👀 🙏 |
value | string | null | null | The reaction you gave. |
onValueChange | (value: string | null) => void | Called with null when you take it back. |
All other div props are forwarded.
Other parts
| Part | Built on | Default | Description |
|---|---|---|---|
MessageContextMenu | ContextMenu.Root | ||
MessageContextMenuTrigger | ContextMenu.Trigger | Fits its content. | |
MessageContextMenuContent | MenuContent | sideOffset={2} | Opens at the pointer. |