Todae

Todae

Mention

defineMentionSource describes a mention once. Pass that object to useMentions for suggestions, and to MentionText for the sent message. renderPeek is the only content of the peek. Todae draws it in a Popover. The chat card that uses it, with a peek while the caret rests in a mention, is the chat composer mentions recipe.

On this page
const people = defineMentionSource({
  char: '@',
  options,
  resolve: (id, signal) => loadPerson(id, signal),
  peekLabel: (person) => person.name,
  renderPeek: (person, peek) => (
    <button type="button" onClick={peek.close}>
      {person.name}
    </button>
  ),
});
import {
  Attachment,
  Avatar,
  Button,
  Field,
  Message,
  MentionText,
  OptionList,
  Popover,
  Stack,
  Text,
  VisuallyHidden,
  defineMentionSource,
  useMentions,
  usePopover,
  type MentionDraft,
  type MentionToken,
  type UseMentionsResult,
} from '@tounsoo/todae';
import { ArrowUp, FileText, Image } from 'lucide-react';
  • peek-card.png248 KB
  • m8-contrast.pdf1.2 MB
Enter to send

Keyboard

KeySuggestion listMention
ArrowDown / ArrowUpMove the active option
Enter or TabPick the option. Enter does not sendOn a link, Enter follows the link
EscapeClose the listClose the peek. Focus stays on the mention
SpaceToggle the peek

Todae has no caret peek of its own. While the caret is inside a token and the list is closed, useMentions returns caretPeekAnchorName, and the recipe opens a peek there that does not take focus and describes the textarea. Escape closes the list first, then that peek.

Peek

A peek with a focusable control is a dialog named by peekLabel, or by the mention text. A text-only peek is the trigger's description and has no role. peek.mode is interactive on a sent mention. A caret peek you build passes caret, as the recipe does. On a sent mention, peek.close() closes the peek and returns focus to the mention.

Hover or focus opens the peek and leaves focus where it is, so it closes when the pointer leaves or focus moves on. A click, or Space on a link, pins the peek open, moves focus into a dialog peek, and returns focus to the mention when it closes. The peek renders a <span>, so a mention can sit inside a paragraph, such as a Text.Root; its content renders from its first open and stays as it closes, so the card fades out with what it showed.

When to use

A sent message should show a mention as a real button or link, with the same peek the composer recipe shows while the caret is in that mention.

When not

A suggestion list that is not a mention → useCombobox. Painted tokens with no peek → useMentions and Field.Textarea.

Props

defineMentionSource props
NameTypeDescription
source RequiredMentionSource

A useMentions trigger plus resolve, renderPeek, peekLabel, and href. renderPeek(entity, { id, mode, close }) is the only content of the peek.

Mention.Root props
NameTypeDescription
source RequiredMentionSource

The source that resolves this mention and renders its peek.

id Requiredstring

The token value, passed to source.resolve and source.href.

childrenReact.ReactNode

The mention text, such as @Mina Park.

MentionText props
NameTypeDescription
value RequiredMentionDraft

The text and its tokens.

sources Requiredreadonly MentionSource[]

Sources used to turn matching tokens into Mention.Root.

classNamestring

Class on the wrapping span.