Forms
Mentions
A text area that suggests people, topics or anything else after a trigger character such as @ or #. Focus stays in the text while you choose.
import { Mentions } from '@reactloom/ui';Examples
Mention teammates
Type @ and a few letters; ↓ / ↑ choose, Enter inserts. onMention reports who was mentioned.
Nobody mentioned yet.
import { Avatar, Mentions } from '@reactloom/ui';
import { useState } from 'react';
const people = [
{ value: 'ada', label: 'Ada Lovelace', description: 'Analytics' },
{ value: 'alan', label: 'Alan Turing', description: 'Research' },
{ value: 'grace', label: 'Grace Hopper', description: 'Compilers' },
{ value: 'katherine', label: 'Katherine Johnson', description: 'Flight dynamics' },
].map((p) => ({ ...p, icon: <Avatar name={p.label} size="xs" alt="" /> }));
export default function Example() {
const [mentioned, setMentioned] = useState<string[]>([]);
return (
<div style={{ display: 'grid', gap: 8, width: '100%', maxWidth: 480 }}>
<Mentions
label="Comment"
placeholder="Type @ to mention a teammate"
options={people}
onMention={(option) => setMentioned((list) => [...new Set([...list, option.label ?? option.value])])}
/>
<p role="status" style={{ margin: 0 }}>{mentioned.length ? `Will notify: ${mentioned.join(', ')}` : 'Nobody mentioned yet.'}</p>
</div>
);
}People and topics
Several triggers: @ from a list, # loaded from a server as you type.
import { Mentions } from '@reactloom/ui';
const topics = ['release', 'roadmap', 'bug', 'billing', 'design', 'docs'];
// Stand-in for a server search.
const searchTopics = (query: string) =>
new Promise<Array<{ value: string }>>((resolve) =>
setTimeout(() => resolve(topics.filter((t) => t.includes(query.toLowerCase())).map((value) => ({ value }))), 250),
);
export default function Example() {
return (
<div style={{ width: '100%', maxWidth: 480 }}>
<Mentions
label="Post"
placeholder="Use @ for people and # for topics"
triggers={[
{ trigger: '@', options: [{ value: 'ada', label: 'Ada Lovelace' }, { value: 'grace', label: 'Grace Hopper' }] },
{ trigger: '#', loadOptions: searchTopics },
]}
/>
</div>
);
}API reference
| Prop | Type | Default |
|---|---|---|
optionsSuggestions for @: { value, label?, description?, icon? }. | MentionOption[] | — |
triggersSeveral trigger characters, static or loaded suggestions. | { trigger, options?, loadOptions? }[] | — |
onMentionCalled when a suggestion is inserted. | (option, trigger) => void | — |
value / defaultValue / onValueChange | string | — |
limitMaximum suggestions shown. | number | 8 |
emptyMessage | ReactNode | 'No matches' |
renderOptionCustom suggestion content. | (option, { active }) => ReactNode | — |
suggestionsTextLive announcement when suggestions appear. | (count) => string | — |
label · description · error · …As on Textarea. | | — |
classNames · styles · textareaClassNamesSuggestion list parts (popover, listbox, option, …) and the Textarea slots. | | — |
Customization
Extracted from the component’s source on every build, so it matches the code. How the layers fit together is explained in Customization.
Renders Textarea, so its hooks apply too.
Slot class names
Add classes to inner parts with classNames (className is shorthand for root): popover, listbox, option, optionIcon, optionText, optionLabel, optionDescription, empty.
CSS variables
| Variable | Default |
|---|---|
--pl-input-radius | var(--pl-radius-md) |
State attributes
Target these in your CSS to style states without depending on class names.
| Attribute | Values |
|---|---|
[data-autosize] | present when on |
[data-disabled] | present when on |
[data-invalid] | present when on |
[data-multiline] | present when on |
[data-over] | present when on |
[data-radius] | none · sm · md · lg · full |
[data-readonly] | present when on |
[data-size] | sm · md · lg |
Theme tokens it reads
--pl-color-bg-subtle --pl-color-bg-surface --pl-color-border-default --pl-color-border-focus --pl-color-border-input --pl-color-danger-border --pl-color-danger-fg --pl-color-fg-default --pl-color-fg-disabled --pl-color-fg-muted --pl-color-fg-subtle --pl-control-height-lg --pl-control-height-md --pl-control-height-sm --pl-focus-ring-color --pl-focus-ring-width --pl-font-size-lg --pl-font-size-md --pl-font-size-sm --pl-font-size-xs --pl-radius-full --pl-radius-lg --pl-radius-md --pl-radius-none --pl-radius-sm --pl-shadow-xs
Accessibility
- The field stays a textbox (a textarea cannot be a combobox); it uses aria-autocomplete, aria-controls and aria-activedescendant to point at the active suggestion.
- A polite live region says how many suggestions there are when the list appears.
| Key | Action |
|---|---|
| @ (or another trigger) | Start a mention |
| ↓ / ↑ | Choose a suggestion |
| Enter / Tab | Insert it |
| Escape | Close the list |
Usage guidelines
Do
- Show who or what will be notified, as in the first example.
Don’t
- Don’t rely on the mention alone to grant access or notify; confirm on submit.