Skip to content
satin

Mentions and commands

Reference people and records with @ and run actions with / from the prompt bar.

Installation

Terminal
npm i @uisatin/ui
Import
import { MentionsAndCommands } from '@uisatin/ui/prompt-mentions'

About 46.4 kB of JavaScript, minified and gzipped, with what it imports (React aside). The stylesheet is one file for every component.

First time with Satin? Set it up once, styles and fonts included, with the installation guide.

API Reference

Mentions and commands are props on PromptBar, so any bar has them, in either shape, with its attachments, models, + menu and dictation. mentions is { trigger, search }: search(query) returns PromptMention[] ({ id, label, description, icon }), or a promise of them. commands is PromptCommand[] ({ name, description, icon, run }). A pick goes into the text as a token, and the value is a PromptValue, { text, mentions, command }, each token with its start and end; command.args is the text after it. Send calls the command’s run({ args, value, attachments }) if it has one, onSubmit otherwise. Build a starting value with promptValue([tara, " ", schedule, " interview next week"]). On a textarea of your own, usePromptMentions({ textareaRef, value, onValueChange, mentions, commands }) returns textareaProps, overlay (the tokens’ fills, under the textarea) and menu. On a field that isn’t a textarea (a contenteditable editor), find the trigger yourself and pass it to usePromptMenuState({ query, mentions, commands }) (query is { kind, trigger, text, start } or null): it searches, filters, keeps the highlight and the status message, and returns open, items, current, move(±1), dismiss(), release(query), announce(text), listId, activeId and menuProps; render <PromptMentionsMenu {...menuProps} onPick anchorRef /> or with virtualAnchor (a rect, such as the caret’s), side, align, sideOffset and matchAnchorWidth={false} for a fixed 288px. Mention shows a mention outside a field, “@Tara Mendes” in a token’s fill: <Mention label="Tara Mendes" id="tara" />, plain CSS on [data-slot="mention"], so an editor’s own <span data-slot="mention"> looks the same. Give it avatar (20px) or name (the full name, label by default) and it has a preview: a Tooltip with the avatar and the full name opens on hover and on keyboard focus, so the mention becomes a tab stop with the focus ring.

PropTypeDefault
mentions
PromptMentions
—
mentions.trigger
string
"@"
mentions.search
(query: string) => PromptMention[] | Promise<PromptMention[]>
—
commands
PromptCommand[]
—
command.run
(input: { args, value, attachments }) => void
—
value
stringPromptValue
—
defaultValue
stringPromptValue
""
onValueChange
(value: string, detail: PromptValue) => void
—
onSubmit
(value: string, attachments: File[], detail: PromptValue) => void
—
PromptMentionsMenu.anchorRef
RefObject<HTMLElement>
—
PromptMentionsMenu.virtualAnchor
{ getBoundingClientRect(): DOMRect }
—
PromptMentionsMenu.side
"top""right""bottom""left"
"top"
PromptMentionsMenu.matchAnchorWidth
boolean
true
Mention.label
string
—
Mention.trigger
string
"@"
Mention.id
string
—
Mention.avatar
ReactNode
—
Mention.name
string
—

Accessibility

Focus stays in the "Message" textarea, which follows the combobox pattern without its role (HTML allows no role on a textarea): it has aria-autocomplete="list", and while the menu shows rows, aria-controls names the listbox ("Mentions" or "Commands") and aria-activedescendant names the highlighted option. The text is the field’s own, so a token reads as what it says, "@Tara Mendes", and spelling, selection and input methods work as in any field; the tokens’ fills are a hidden layer under it. A status region says how many suggestions there are, "No results for “@zz”", and "@Tara Mendes added" or "removed". While an input method composes, no menu opens and no key is taken. The menu’s rows are hidden from the tab order; the panel is named like its list. The menu lives only while focus is in the field: the + button, the model menu, dictation or Send take focus and close it, and @ or / typed in the + panel’s search is that search’s text. Escape closes the menu alone, not a dialog the bar sits in. A Mention with a preview (avatar or name) is a tab stop with the focus ring; its Tooltip opens on focus and hover and describes it (aria-describedby) with the full name, the avatar hidden.

KeyAction
@or/At the start or after a space: opens the mentions or the commands. The text typed after it filters them.
↑or↓In the open menu: moves the highlight, wrapping at the ends.
EnterorTabIn the open menu: inserts the highlighted row as a token, followed by a space.
EscCloses the menu until the next @ or /.
BackspaceRight after a token: removes the whole token. Delete does the same just before one.
←or→Steps over a token in one move.
EnterWith the menu shut or empty: sends; a message with a command runs it.