Forms
TagInput
Enter free-text tags — labels, keywords, email addresses — in one field. Enter or comma adds, pasting a list adds each item, and every tag has a remove button.
import { TagInput } from '@reactloom/ui';Examples
Labels with suggestions
Suggestions come from a native datalist.
import { TagInput } from '@reactloom/ui';
import { useState } from 'react';
export default function Example() {
const [labels, setLabels] = useState(['bug', 'accessibility']);
return (
<div style={{ maxInlineSize: 440 }}>
<TagInput label="Labels" value={labels} onValueChange={setLabels} suggestions={['design', 'docs', 'performance', 'security']} />
</div>
);
}Validated email addresses
validate rejects a tag with a message; maxTags limits the count.
import { TagInput } from '@reactloom/ui';
const isEmail = (text: string) => /^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(text);
export default function Example() {
return (
<div style={{ maxInlineSize: 440 }}>
<TagInput
label="Invite people"
description="Paste a list or separate addresses with commas. Up to 5."
maxTags={5}
validate={(tag) => (isEmail(tag) ? null : `“${tag}” is not an email address.`)}
messages={{ hint: 'Press Enter or comma to add an address.' }}
type="email"
autoComplete="off"
/>
</div>
);
}API reference
| Prop | Type | Default |
|---|---|---|
value / defaultValue | readonly string[] | — |
onValueChange | (tags: string[]) => void | — |
separatorsKeys that add the typed text. | readonly string[] | ['Enter', ','] |
validateReturn a message to reject a tag. | (tag, tags) => string | null | — |
allowDuplicatesCase-insensitive duplicates are rejected by default. | boolean | false |
maxTags | number | — |
suggestionsOffered while typing. | readonly string[] | — |
messagesTranslate remove, added, removed, duplicate, limit and hint texts. | Partial<TagInputMessages> | — |
labelVisible label. | ReactNode | — |
description · errorHelp text and error, linked with aria-describedby. | ReactNode | — |
hideLabel · required · disabled · sizeAs on Input. | | — |
Customization
Extracted from the component’s source on every build, so it matches the code. How the layers fit together is explained in Customization.
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-disabled] | present when on |
[data-invalid] | present when on |
[data-size] | sm · md · lg |
Theme tokens it reads
--pl-color-bg-muted --pl-color-bg-subtle --pl-color-bg-surface --pl-color-border-focus --pl-color-border-input --pl-color-danger-solid --pl-color-fg-default --pl-color-fg-muted --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-radius-md --pl-radius-sm --pl-radius-xs --pl-shadow-xs
Accessibility
- Tags are a list; each remove button is named “Remove …”.
- Additions, removals and rejections are announced in a live region.
- Remove buttons are reached with Backspace or ← from the start of the field, not with Tab, so Tab moves on to the next field.
- A rejected tag stays in the field with the reason as its error.
| Key | Action |
|---|---|
| Enter / , | Add the typed text |
| Backspace (empty field) or ← | Move to the last tag |
| ← / → | Move between tags |
| Backspace / Delete on a tag | Remove it |
Usage guidelines
Do
- Validate each tag as it is added, not on submit.
- Use a Combobox or MultiSelect when people must pick from a fixed list.
Don’t
- Don’t use tags for a single value.