Examples

Labels with suggestions

Suggestions come from a native datalist.

Preview
  • bug
  • accessibility
Press Enter or comma to add. Backspace in the empty field moves to the last item.
Example.tsx
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.

Preview

Paste a list or separate addresses with commas. Up to 5.

Press Enter or comma to add an address.
Example.tsx
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

TagInput props
PropTypeDefault
value / defaultValue
readonly string[]—
onValueChange
(tags: string[]) => void—
separators
Keys that add the typed text.
readonly string[]['Enter', ',']
validate
Return a message to reject a tag.
(tag, tags) => string | null—
allowDuplicates
Case-insensitive duplicates are rejected by default.
booleanfalse
maxTags
number—
suggestions
Offered while typing.
readonly string[]—
messages
Translate remove, added, removed, duplicate, limit and hint texts.
Partial<TagInputMessages>—
label
Visible label.
ReactNode—
description · error
Help text and error, linked with aria-describedby.
ReactNode—
hideLabel · required · disabled · size
As 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

VariableDefault
--pl-input-radiusvar(--pl-radius-md

State attributes

Target these in your CSS to style states without depending on class names.

AttributeValues
[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.
Keyboard interactions
KeyAction
Enter / ,Add the typed text
Backspace (empty field) or ←Move to the last tag
← / →Move between tags
Backspace / Delete on a tagRemove 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.