All components (283)
Mention field
Fields · MentionField
What it is and when to use it
A long text field where @ opens a list of people: comments, tasks, a chat. The list appears where the mention is, and the value stays plain text ("Hello @Marta Ruiz, look at this"), which is what gets stored and sent.
When to use it
- Comments on an order or a task that notify someone.
optionsare the people andtriggerthe character that opens the list (@, by default;#for tags).onSearchto search on the server: it is called with what is typed after the character, andloadingsays the options are on their way.onMentionsChangehands over who is mentioned in the text, to notify them on saving.- In a chat,
PromptInputdoes the same with itsmentionsprop.useMentionsmounts it on any othertextarea.
When not to
- Choosing people without writing anything else:
PeoplePicker. - Choosing from a closed list in a one-line field:
Combobox.
Keyboard: @ opens the list and what you type filters it, ignoring case and accents. The arrows move, Enter or Tab choose and Escape closes the list without leaving the field. Focus always stays in the field. An email (ana@correo.es) opens nothing: the character only counts at the start or after a space.
Accessibility: the field points to the list with aria-controls and says which one is marked with aria-activedescendant. A spoken notice says how many suggestions there are. Like any field, it has a mandatory label, hint and error.
Fine-tuning: the field is a TextArea and accepts its --amset-field-* variables. The panel is adjusted with the amset-mention__panel class.
What it looks like
<MentionField
label="Comment"
hint="Type @ to notify someone"
defaultValue="Reviewed with "
options={personas}
/>Props
Import it with import { MentionField } from '@amset/ui'. Required props are marked.
| Prop | Type | What it does |
|---|---|---|
labelrequired | string | — |
optionsrequired | MentionOptions | Who can be mentioned. With `onSearch`, what the last search returned. With several triggers, a function that returns the list for each one: people for `@`, tags for `#`. |
className | string | — |
countBy | CountStrategy | How characters are counted: `graphemes` (default, an emoji with its skin tone is one), `characters` (what `maxLength` measures) or a custom function (words, bytes). |
counter | boolean | "inside" | Shows "123 / 500", with the limit of `maxCount` or `maxLength`. `inside` puts it inside the border, bottom right, instead of under the field. |
defaultValue | string | — |
disabled | boolean | — |
emptyMessage | string | What is said when nobody matches. |
error | string | — |
filterOption | false | ((option: ListOption, query: string, trigger: string) => boolean) | How an option matches what is typed after the character. By default, that it contains it, case- and accent-insensitive. `false` does not filter: the list is shown as is. |
footer | ReactNode | A strip inside the border, under the text: formatting buttons, an attachment. The `inside` counter goes next to it. |
hiddenLabel | boolean | The label for the screen reader only. For when the field sits inside something that already explains itself (a table cell, a group of filters), never to save space. |
hint | string | — |
inputRef | Ref<HTMLTextAreaElement> | The real `<textarea>`. |
invalid | boolean | — |
loading | boolean | The options are arriving. |
maxCount | number | A limit that WARNS without cutting: typing can go on, the count turns red, the field is marked invalid and how many are left over is announced. To cut off hard there is `maxLength`. With `maxCount` the counter shows even if not asked for. |
maxRows | number | How many rows it grows to while typing; beyond that the scrollbar shows. By default, 20. With the same number as `rows` the field does not grow. |
onChange | (value: string) => void | — |
onChangeEvent | (event: ChangeEvent<HTMLTextAreaElement>) => void | Like `onChange`, but with the native event of the `<textarea>`: `e.target.value`, `e.currentTarget`... It exists to migrate a front end that already writes its handlers with the event (AMS-735). If you only want the text, `onChange` already gives it to you. |
onMention | (option: ListOption, trigger: string) => void | Called when someone is picked from the list, with the character that opened it. |
onMentionsChange | (mentioned: readonly ListOption[]) => void | Who is mentioned in the text, after each change. What you want to store with the text to notify them. |
onSearch | (query: string, trigger: string) => void | To search elsewhere: called with the text typed after the character and with the character, and `options` are no longer filtered here. |
placeholder | string | — |
readOnly | boolean | — |
required | boolean | — |
resize | "none" | "vertical" | Whether it can be resized by hand: downwards (`vertical`, the default) or not at all (`none`). Not sideways, which breaks the grid. |
rows | number | Rows shown at first (1 to 12). As more is typed, it grows by itself up to `maxRows`. |
size | "sm" | "md" | "lg" | — |
success | string | The confirmation that what was typed is valid. An error or a warning take precedence over it. |
trigger | string | readonly string[] | The character that opens the list, or several (`['@', '#']`). By default, `@`. |
validateSearch | (query: string, trigger: string) => boolean | Whether what is typed after the character is a search. With `false` the list does not open and `onSearch` is not called. |
validationBehavior | "aria" | "native" | `aria` (the default) announces the state without the browser interrupting submission with its bubble; `native` also adds its own validation. |
value | string | — |
variant | FieldVariant | — |
warning | string | A warning that lets you go on, with its icon and colour, where the error would go. The field is still valid. |
It also accepts the attributes of the element it renders: className, style, data-*, aria-* and its events.
In the test bench
Every state and variant, to try one at a time, on its page at storybook.amsetui.com:
