aiellie

Search

Find a component, template or page

GitHub
Components

Mentions

The people and agents an at sign opens in the composer, filtered as you type and put into the message as @Name.

fig. 01 · open it full screen from the corner

Installation

npx shadcn@latest add "@aiellie/mentions"

shadcn needs the @aiellie registry in components.json first. npx aiellie add mentions adds it on its first run, then installs the same way.

Mentions lists the people and agents a message can name when an at sign is typed in the composer, anywhere in the text. It filters by what follows the at sign, moves with the arrow keys and picks with Enter or Tab, writing @Name in place and leaving the caret after it.

Getting started

  1. Wrap the input

    Like SlashMenu, it goes inside Composer, around ComposerInput.

    components/chat-input.tsx
    import {
      Composer,
      ComposerFooter,
      ComposerInput,
      ComposerSubmit,
    } from "@/components/aiellie/composer"
    import { Mentions, type MentionOption } from "@/components/aiellie/mentions"
    
    const OPTIONS: MentionOption[] = [
      { id: "researcher", name: "Researcher", kind: "agent" },
      { id: "ada", name: "Ada", description: "Design" },
    ]
    
    export function ChatInput({ onSend }: { onSend: (text: string) => void }) {
      return (
        <Composer onSubmit={onSend}>
          <Mentions options={OPTIONS}>
            <ComposerInput />
          </Mentions>
          <ComposerFooter>
            <ComposerSubmit />
          </ComposerFooter>
        </Composer>
      )
    }

Anatomy

<div data-slot="mentions">
  <textarea data-slot="composer-input" aria-autocomplete="list" aria-expanded aria-activedescendant />
  <div role="listbox"> {/* above the field, while open */}
    <div role="option" aria-selected data-highlighted /> {/* picture, name, description */}
  </div>
</div>

An option shows its avatar, or a sparkle for an agent and a silhouette for a person. Escape closes the list until the text changes.

Focus stays in the field, and the keys the list answers are caught before the field sees them.

Examples

Know who was named

onMention is called with each option picked, for a message that should notify them.

No one named yet.

API reference

Mentions

PropTypeDefaultDescription
optionsMentionOption[]requiredThe people and agents a message can name.
onMention(option: MentionOption) => voidCalled with whoever was picked.
emptyMessagestring"No one matches"

All other div props are forwarded.

MentionOption

FieldTypeDefaultDescription
idstringrequired
namestringrequiredWritten into the message as @name.
descriptionstringShown at the end of the row.
avatarstringA picture's address.
kind"person" | "agent""person"Picks the glyph when there's no picture.