aiellie

Search

Find a component, template or page

GitHub
Components

Message Context Menu

The menu a message opens on right click or long press, with a row of reactions above its actions.

Right-click this message, or press and hold it.
Open full screen
fig. 01 · open it full screen from the corner

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

  1. 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.

Ship it on Monday? ✅

API reference

MessageReactionPicker

PropTypeDefaultDescription
reactionsstring[]DEFAULT_REACTIONS👍 ❤️ 😂 🎉 👀 🙏
valuestring | nullnullThe reaction you gave.
onValueChange(value: string | null) => voidCalled with null when you take it back.

All other div props are forwarded.

Other parts

PartBuilt onDefaultDescription
MessageContextMenuContextMenu.Root
MessageContextMenuTriggerContextMenu.TriggerFits its content.
MessageContextMenuContentMenuContentsideOffset={2}Opens at the pointer.