# TagInput

A multi-value field. The user types a value into a single-line input and commits it with Enter or a comma, and each value becomes a removable chip listed below the input, or, with `tagPlacement="inside"`, inside the input box. The same component covers free-form lists (email addresses, numbers, IAM principals) and picking several values from suggestions, with an optional custom value on top.

## When to Use

- The value is a list of short strings the user types or pastes: recipients, domains, bin boundaries, tags
- The user picks several values from a long list and should see what is picked while searching for the next one
- A list of options where the user may also add a value that is not in it (`allowsCustomValue`)
- Not for a short, fixed list of options: use [FilterPicker](./FilterPicker.md) or [CheckboxGroup](https://cube-ui-kit.vercel.app/?path=/docs/forms-checkboxgroup--docs)
- Keep the chips below the input (the default) wherever there is room for them. Put them inside the box (`tagPlacement="inside"`) only where the field sits in a row with no room below it, such as a filter row

## Component

---

### Properties

- **`children`** `ReactNode | (item: T) => ReactElement` — `TagInput.Item` elements, or a render function for `items`, that suggest values. Without options the field accepts any typed value
- **`items`** `Iterable<T>` — Options to suggest, as data
- **`placeholder`** `string` — Placeholder text for the input
- **`icon`** `ReactElement` — Icon element rendered before the input
- **`prefix`** `ReactNode` — Input decoration before the main input
- **`suffix`** `ReactNode` — Input decoration after the main input
- **`suffixPosition`** `'before' | 'after'` — Whether the suffix goes before or after the validation and loading icons
- **`tagProps`** `(value: string) => Partial<CubeTagProps>` — Props for each chip's `Tag` (theme, icon, label), by value. A string `children` also names the value to screen readers, and `isDisabled` locks the chip
- **`value`** `string[]` — The values in controlled mode
- **`defaultValue`** `string[]` — The initial values in uncontrolled mode
- **`inputValue`** `string` — The text being typed, in controlled mode
- **`defaultInputValue`** `string` — The initial text being typed, in uncontrolled mode
- **`allowsCustomValue`** `boolean` (default: `false`) — Whether typed values that are not among the options are accepted. Only applies when options are given. Text that matches an option only in case or accents is then added as typed
- **`delimiters`** `string[]` (default: `[',']`) — Characters that commit the typed text and split pasted text. Pasted text is also split on line breaks
- **`validateTag`** `(value: string) => boolean | string | null | undefined` — Checks one value before it becomes a chip. Return `false` or a message to reject it
- **`normalizeTag`** `(value: string) => string` — Rewrites a typed value before it is checked and added. Return an empty string to drop it
- **`maxTags`** `number` — The most values the field holds. Values past it are refused and stay in the input
- **`shouldCommitOnBlur`** `boolean` (default: `true`) — Whether leaving the field commits the typed text
- **`isClearable`** `boolean` (default: `false`) — Whether a button in the input clears the field: the typed text and every chip but the locked ones. It shows while there is something to clear
- **`filter`** `((textValue: string, inputValue: string) => boolean) | false` — Custom filter for the options, or `false` to show every option
- **`popoverTrigger`** `'focus' | 'input' | 'manual'` (default: `input`) — When the suggestions popover opens on its own, as in `ComboBox`: `input` on typing or a press in the input, `focus` on focus as well, `manual` only from the chevron and the arrow keys
- **`emptyLabel`** `ReactNode` — What the popover says when no option matches the typed text, or while `isLoading` with no option to show. Defaults to "No results found", and to "Loading…" while loading
- **`hideTrigger`** `boolean` (default: `false`) — Whether to hide the button that toggles the popover
- **`disabledKeys`** `Iterable<Key>` — Keys of options that cannot be picked
- **`size`** `'small' | 'medium' | 'large'` (default: `medium`) — Size of the input. The chips follow it
- **`tagPlacement`** `'below' | 'inside'` (default: `below`) — Where the chips go: in a list below the input, or in the input box, in one wrapping row with the text
- **`hidePlaceholderWithTags`** `boolean` (default: `false`) — Whether the placeholder hides once there is a tag, so it only prompts for the first value
- **`listGap`** `number` — Space between options, in pixels. Defaults to a hairline (`$item-gap`, `1px`)
- **`direction`** `'bottom' | 'top'` (default: `bottom`) — Where the suggestions popover opens
- **`shouldFlip`** `boolean` (default: `true`) — Whether the popover flips when there is no room
- **`overlayOffset`** `number` (default: `8`) — Distance between the input and the popover, in pixels
- **`containerPadding`** `number` (default: `8`) — Minimum space between the popover and the viewport edge, in pixels
- **`autoComplete`** `string` (default: `off`) — HTML `autocomplete` attribute for the input
- **`isIdentifier`** `boolean` (default: `false`) — Whether the values are identifiers, such as emails, keys or attribute names, rather than prose. Turns off the browser's text services for the input: `autocapitalize="none"`, `autocorrect="off"` and `spellcheck="false"` (the input's `autocomplete` is already `off`), so a phone keyboard neither starts each tag with a capital nor rewrites it. An explicit `autoComplete` still wins: for email addresses, pass `autoComplete="email"` with the flag so the browser can still suggest saved addresses. iOS still offers contact AutoFill above the keyboard: no attribute turns that off
- **`inputMode`** `'text' | 'email' | 'url' | 'tel' | 'numeric' | 'decimal' | 'search' | 'none'` — Which virtual keyboard the input asks for. The input stays a text input, so the browser does not validate what is typed
- **`enterKeyHint`** `'enter' | 'done' | 'go' | 'next' | 'previous' | 'search' | 'send'` — The label of the virtual keyboard's Enter key
- **`onChange`** `(value: string[]) => void` — Called with the whole new list of values
- **`onInputChange`** `(value: string) => void` — Called when the text being typed changes
- **`onClear`** `() => void` — Called when the clear button is pressed
- **`onOpenChange`** `(isOpen: boolean) => void` — Called when the suggestions popover opens or closes
- **`onFocus`** `() => void` — Called when focus enters the component: the input, a chip or the popover
- **`onBlur`** `() => void` — Called when focus leaves the component entirely, after the typed text is committed and before the press that moved focus is handled, so a Save click sees the new value
- **`onKeyDown`** `(e: KeyboardEvent) => void` — Called when a key is pressed in the input, before the component handles it. Call `e.preventDefault()` to stop the built-in handling. `Escape` and `Tab` go on to ancestors, so a surrounding `Dialog` still closes on `Escape` and moves focus on `Tab`, unless TagInput acts on them or you prevent them
- **`inputRef`**, **`wrapperRef`**, **`popoverRef`**, **`listBoxRef`** `RefObject` — Refs to the input, the bordered input box, the popover and its listbox. The forwarded `ref` points at the root, which holds the input and the chips
- **`mods`** `Record<string, boolean>` — Modifiers for the bordered input box, see [Modifiers](#modifiers)

#### Notable Properties

**delimiters** - Typing a delimiter commits the text before it, and pasting splits the text on every delimiter and line break, so a column copied from a spreadsheet or a comma-separated list becomes one chip per entry. A single pasted value is inserted as plain text for the user to finish. Pass `[]` when a value may contain a comma: only Enter and pasted line breaks separate values then. Refused values go back to the input joined by the first delimiter, so they split into the same values again; with `[]` nothing can separate them in one line, so only the first refused value stays there, with its message.

**validateTag** - Runs on every value about to become a chip. A rejected value stays in the input, the field turns invalid and the message shows below it until the text is edited. A value picked from the options is not checked. Values already in `value` that fail the check are drawn in the danger theme and carry the message as their description, so an invalid entry loaded from the server stands out. Duplicates are always refused, with a message of their own, and leave the input: the value is there already, as a chip. When a paste mixes the two, the message is the one for the text left in the input. A message is cleared by Escape, and by leaving the field once nothing is left in the input, so a refused duplicate does not leave an empty field marked invalid.

**normalizeTag** - Runs on typed text before anything else looks at it, so the duplicate check, `validateTag` and the new chip all see the rewritten value: lowercase an email address, strip thousands separators, write a number one way. The rejected text that stays in the input is what the user typed. Picked options keep their keys.

**maxTags** - A hard limit on the number of values. Past it, typed, pasted and picked values are refused with a message and stay in the input, while values up to the limit are still added. For a limit that only flags the field, use a `rules` entry instead.

**tagProps** - Called per value. Return a theme, an icon or `qa` for the chip. A string `children` replaces the chip's text and also names the value in the input's description and in the "Added"/"Removed" announcements, for values whose label does not come from the options. `isDisabled: true` locks the chip: it has no remove button, Delete and Backspace leave it, and its option cannot be unpicked. The arrow keys still reach it, so a screen reader says it is disabled. An invalid chip stays in the danger theme whatever theme it asks for.

**tagPlacement** - `below` is the default and the preferred layout: the input is a fixed single line that never moves, stays level with a side label, and keeps the arrow keys for the suggestions. `inside` puts the chips in the input box for a field that has no room below it. The chips and the text share one wrapping row and the box grows a row at a time; one row is exactly the input's height. The text is as wide as what is typed, never under 6x: text that does not fit after the chips moves to a row of its own, and is cut only past the full width. The placeholder does not size the text, so a long one ends in an ellipsis instead of taking a row (`hidePlaceholderWithTags` hides it once there is a value). The suffix (validation icon, clear button, popover trigger) rides on the end of the text, so the two always wrap together. A long value shrinks to the box's width and ends in an ellipsis. Inside, the arrow keys cross between the text and the chips (see [Keyboard Navigation](#keyboard-navigation)). Moving to the chips closes the popover in either placement, by keyboard or with a press on a chip or its remove button, and a press keeps the typed text. Typed text sizes itself with `field-sizing`; a browser without it keeps a fixed share of the row for the text, which scrolls. Right-to-left layouts are not supported yet, as in the rest of UI Kit.

**popoverTrigger** - When the suggestions popover opens on its own, with the same values as `ComboBox` and React Aria's `menuTrigger`. `input`, the default, opens it on typing and on a press in the input, also when the input already has focus, as after Escape closed it. A press on the box around the input counts too, with `tagPlacement="inside"` as well; a press on a chip or a button does not, and a click on the label only focuses the input. A press on typed text that matches no option keeps the popover closed, so a press that moves the caret does not change what Enter adds. `focus` also opens it whenever the input takes focus: from a click, Tab, or back from the chips. `manual` opens it only from the chevron and the arrow keys. With any of them, the chevron toggles the popover.

**children / items** - Options turn the input into a combobox. Typing filters them and focuses the option the typed text names, or else the first match. Enter or a click toggles the focused option, and the popover stays open so the user can pick several in a row. A picked option is added as its own key, whatever other options its text resembles. Typed text means "add": pressing Enter on an option that is already a chip refuses it as a duplicate, and unpicking it takes the arrow keys, a click, or an empty input. A picked option shows a checked box. Typed text names an option by its exact label, then by its key, anywhere in the list, before any looser match counts, so `active` finds `active` even when `Active` comes first. Enter, a delimiter, a paste and blur all go by the same rule, and the option the text names stays listed and focused even when the filter would hide it, as when a key is typed, so they always add the same option. Without `allowsCustomValue`, typed text must name an option, and a label in another case or without its accents counts too: `production` adds `Production`. On blur a query that names nothing is dropped. With `allowsCustomValue`, only an exact match counts: `paris` next to an option `Paris` is a value of its own, offered and focused as its own row and added as typed, since a case-sensitive filter treats the two apart. A press on a control outside while the popover shows (a button, a link, another field) is not taken by it: it reaches the control, so a Save button saves on the first click, with the typed text already committed. A press anywhere else, such as blank space in or the backdrop of a dialog the field sits in, or a control outside the dialog or popover it sits in, only closes the popover, keeps the typed text in the input, and leaves the dialog open. An enabled UI Kit `Button` or `ItemButton` is the exception: it is reached from anywhere. A press on a disabled control never commits the typed text. The typed text is offered as its own option after the matches, the same way [FilterListBox](./FilterListBox.md) does, and custom values already added are listed there too, checked and sorted, so they can be unpicked from the list as well as from their chips. One unpicked in the list stays there, unchecked, until focus leaves the field, so it can be picked back. An option in `disabledKeys` is refused however it is entered. A chip for an option shows the option's label, while the value holds its key. The label is remembered, so it survives server-side filtering (`filter={false}` with changing `items`).

### Base Properties

Supports [Base properties](../../BaseProperties.md)

### Field Properties

Supports all [Field properties](../../FieldProperties.md)

A standalone TagInput renders field chrome by default, so refused values show their reason below the control and the input references that reason through `aria-describedby`, even without a visible `label`. No empty `message` prop is needed. A local rejection takes precedence over the ordinary field error until the draft is edited. With `isBare`, there is no visible message slot; rejection feedback is announced through the live region instead.

```jsx
<TagInput aria-label="Recipients" defaultValue={['ana@acme.com']} />
<TagInput isBare aria-label="Inline recipients" defaultValue={['ana@acme.com']} />
```

### Styling Properties

#### styles

Styles the input element, a column holding the input box and the chips. Its style props place and size the field: see [Field properties](../../FieldProperties.md).

#### wrapperStyles

Customizes the bordered input box.

**Sub-elements:**

- `Prefix` - Container for prefix content and icons
- `Suffix` - Container for suffix content, validation icons, the clear button and the popover trigger, which always comes last
- `InputIcon` - Container for the left icon
- `ValidationIcon` - Container for validation state icons
- `State` - Container for the validation and loading icons

#### inputStyles

Customizes the text input element.

#### tagListStyles

Customizes the wrapping row of chips. With `tagPlacement="inside"` the list is `display: contents`, so its chips are items of the input box's own row.

#### tagStyles

Customizes every chip. Use `tagProps` for per-value props.

#### triggerStyles

Customizes the button that toggles the popover.

#### overlayStyles

Customizes the popover.

By default the popover is as wide as its options, long labels and descriptions included. It is never narrower than the field, and never wider than half the viewport or `60x`, whichever is larger, nor than the viewport less a margin. It does not narrow while open, as the list scrolls or the input filters it. A `width` here replaces that rule.

#### listBoxStyles

Customizes the listbox in the popover.

#### optionStyles

Customizes each option.

#### sectionStyles

Customizes option sections.

#### headingStyles

Customizes option section headings.

### Style Properties

These properties allow direct style application without using the `styles` prop:

- **Position:** `gridArea`, `order`, `gridColumn`, `gridRow`, `placeSelf`, `alignSelf`, `justifySelf`, `zIndex`, `margin`, `blockMargin`, `inlineMargin`, `inset`, `blockInset`, `inlineInset`, `position`, `scrollMargin`, `blockScrollMargin`, `inlineScrollMargin`, `scrollPadding`, `blockScrollPadding`, `inlineScrollPadding`
- **Dimension:** `width`, `height`, `blockSize`, `inlineSize`, `flexBasis`, `flexGrow`, `flexShrink`, `flex`

### Modifiers

The `mods` prop accepts the following modifiers for the bordered input box:

- **`focused`** `boolean` — Forces focus ring appearance.
- **`disabled`** `boolean` — Forces disabled appearance.
- **`readonly`** `boolean` — Set while `isReadOnly`: a recessed fill and a softer border, except in high contrast.
- **`invalid`** `boolean` — Forces invalid state styling.
- **`valid`** `boolean` — Forces valid state styling.
- **`prefix`** `boolean` — Indicates presence of prefix content.
- **`suffix`** `boolean` — Indicates presence of suffix content.

## Variants

### Sizes

- `small` - Compact input with extra-small chips
- `medium` - Default size, with extra-small chips
- `large` - Emphasized input with small chips

### Tags Inside the Input

```jsx
<TagInput
  tagPlacement="inside"
  aria-label="Values"
  placeholder="Add a value"
  defaultValue={['active', 'pending']}
/>
```

To prompt only for the first value, hide the placeholder once there is one:

```jsx
<TagInput
  hidePlaceholderWithTags
  tagPlacement="inside"
  aria-label="Values"
  placeholder="Add a value"
/>
```

### Disabled and Read-only

A disabled field's chips drop out of the Tab order. A read-only field keeps them focusable but shows no remove buttons and ignores Delete.

## Examples

### Free-form Values

```jsx
const EMAIL = /^[^\s@,]+@[^\s@,]+\.[^\s@,]+$/;

<TagInput
  label="Also send to"
  placeholder="name@company.com"
  defaultValue={['ana@acme.com']}
  validateTag={(value) => EMAIL.test(value) || 'Enter an email address'}
/>;
```

### Pasting a List

Pasted text is split on delimiters and line breaks. Accepted entries become chips, rejected ones stay in the input with the message from `validateTag`, and duplicates of existing chips are dropped with a message of their own.

### Identifiers and Email Addresses

`isIdentifier` keeps a phone keyboard from capitalizing or autocorrecting each typed value. For email addresses, pass `autoComplete="email"` with it so the browser can still suggest saved addresses.

```jsx
<TagInput label="Recipients" isIdentifier inputMode="email" autoComplete="email" />
```

### Picking from Suggestions

```jsx
<TagInput label="Allowed actions" placeholder="Search actions">
  <TagInput.Item key="read">read</TagInput.Item>
  <TagInput.Item key="refresh">refresh</TagInput.Item>
  <TagInput.Item key="rebuild">rebuild</TagInput.Item>
  <TagInput.Item key="deploy">deploy</TagInput.Item>
</TagInput>
```

### Suggestions with Custom Values

```jsx
<TagInput
  allowsCustomValue
  label="Allowed actions"
  placeholder="Search or add an action"
>
  <TagInput.Item key="read">read</TagInput.Item>
  <TagInput.Item key="refresh">refresh</TagInput.Item>
</TagInput>
```

### Data-driven Options

```jsx
const members = [
  { key: 'orders.count', label: 'Orders count' },
  { key: 'orders.status', label: 'Order status' },
];

<TagInput label="Members" items={members}>
  {(member) => <TagInput.Item key={member.key}>{member.label}</TagInput.Item>}
</TagInput>;
```

### Nothing Found and Loading

When no option matches the typed text, the popover stays open and says so, "No results found" by default, instead of disappearing while the user types. ArrowDown or the chevron brings back every option. With `isLoading`, the chevron takes the `loading` modifier and, while there is no option to show, the popover says "Loading…" instead, so a server-side search never reads "No results found" before its results arrive. Options already listed stay while new ones load. Pass `emptyLabel` for words of your own.

```jsx
<TagInput
  label="Members"
  items={results}
  filter={false}
  isLoading={isFetching}
  emptyLabel={isFetching ? 'Searching members…' : 'No member matches'}
  onInputChange={setQuery}
>
  {(member) => <TagInput.Item key={member.key}>{member.label}</TagInput.Item>}
</TagInput>
```

### Per-chip Props

```jsx
<TagInput
  label="Members"
  defaultValue={['orders.count', 'orders.status']}
  tagProps={(value) => ({
    theme: isMeasure(value) ? 'primary' : 'success',
  })}
>
  {members.map((key) => (
    <TagInput.Item key={key}>{key}</TagInput.Item>
  ))}
</TagInput>
```

### Values with Commas

```jsx
<TagInput
  label="Allowed IAM principals"
  delimiters={[]}
  description="Only Enter and pasted line breaks separate values."
/>
```

### Many Values in a Narrow Field

```jsx
<TagInput
  label="Bin boundaries"
  width="240px"
  placeholder="Add a number"
  defaultValue={['0', '10', '25', '50', '75', '100']}
  validateTag={(value) => Number.isFinite(Number(value)) || 'Enter a number'}
/>
```

### Moving Between the Input and the Chips

Tab goes from the input to the chips. Backspace in the empty input does too, landing on the last chip without removing it; the next Backspace removes it and moves to the one before. From a chip, Escape goes back to the input, and so does typing, which carries on in the input.

### Locked Values and Clearing the Field

A locked chip has no remove button. The arrow keys stop on it, so a screen reader announces it as disabled, but `Backspace` and `Delete` never remove it. The clear button inside the input clears the whole field: the typed text and every chip but the locked ones. It shows while there is something to clear, and calls `onChange` once with what is left. `Escape` clears only the typed text, so a stray key press never loses the values.

```jsx
<TagInput
  isClearable
  label="Owners"
  defaultValue={['you@acme.com', 'ana@acme.com']}
  tagProps={(value) =>
    value === currentUser ? { isDisabled: true, children: `${value} (you)` } : undefined
  }
/>
```

### A Limit on the Number of Values

```jsx
<TagInput label="Reviewers" maxTags={3} description="Up to three reviewers." />
```

### Rewriting Typed Values

```jsx
<TagInput
  label="Also send to"
  normalizeTag={(value) => value.toLowerCase()}
  validateTag={validateEmail}
/>
```

With the rewrite, `Ana@Acme.com` is a duplicate of `ana@acme.com` rather than a second chip.

### Numbers

The value is always a `string[]`. Map a numeric model at the boundary, and let `normalizeTag` write each number one way, so `10.0` is a duplicate of `10`:

```jsx
const [bounds, setBounds] = useState([0, 10, 25]);

<TagInput
  label="Bin boundaries"
  inputMode="decimal"
  delimiters={[',', ';', ' ']}
  value={bounds.map(String)}
  onChange={(next) => setBounds(next.map(Number).sort((a, b) => a - b))}
  normalizeTag={(value) =>
    Number.isFinite(Number(value)) ? String(Number(value)) : value
  }
  validateTag={(value) => Number.isFinite(Number(value)) || 'Enter a number'}
/>;
```

For numbers written with thousands separators, turn the comma delimiter off and strip them in `normalizeTag`: `delimiters={[]}` with `normalizeTag={(value) => value.replaceAll(',', '')}`.

### Labels for Values Outside the Options

When a value's label is not in the options, for example because the options are loaded on demand or leave out what is already picked, give the chip its label in `tagProps`:

```jsx
<TagInput
  label="Roles"
  items={unpickedRoles}
  tagProps={(id) => ({ children: roleTitles[id] })}
>
  {(role) => <TagInput.Item key={role.id}>{role.title}</TagInput.Item>}
</TagInput>
```

### Controlled

```jsx
const [recipients, setRecipients] = useState(['ana@acme.com']);

<TagInput label="Recipients" value={recipients} onChange={setRecipients} />;
```

### Side Label

```jsx
<TagInput
  labelPosition="side"
  label="Also send to"
  description="Press Enter or type a comma to add an address."
/>
```

## Accessibility

### Keyboard Navigation

- `Tab` - Moves focus from the input to the chips, then out of the field. The chips are one Tab stop; the popover trigger and the clear button are not Tab stops. Tabbing away closes the popover and commits the typed text
- `Shift+Tab` - Moves back from the chips to the input
- `Enter` - Commits the typed text. With the popover open, toggles the focused option, the one `aria-activedescendant` announces; with text typed, an option that is already a chip is refused as a duplicate rather than removed, and the text is cleared. Never submits a surrounding form, even with nothing typed, so one Enter too many after the last value does not send a half-filled dialog
- `,` (or another delimiter) - Commits the text before the caret and keeps the rest typed
- `Escape` - Closes the popover, or clears the typed text when it is closed. Either way it clears a message about the text, even once the input is empty
- `Backspace` in the empty input - Moves focus to the last chip you can remove, without removing it, and closes the popover. A Backspace held down to clear the text stops at the empty input
- `ArrowDown` / `ArrowUp` - Opens the popover or moves through the options. On typed text that matches no option, opens it with every option
- `Home` / `End` - Moves to the first or last option while the popover is open
- `ArrowLeft` / `ArrowRight` - Moves between chips, locked ones included. A locked chip is announced as disabled and is never removed
- `ArrowLeft` at the start of the text, with `tagPlacement="inside"` - Moves focus to the last chip, as Backspace in the empty input does. `ArrowRight` on the last chip moves back to the text, with the caret at its start, and `ArrowLeft` on the first chip stays there instead of wrapping round. A modified arrow (Shift, Alt, Ctrl, Cmd) stays text editing. Below the box, the arrows in the input move the caret only
- `Delete` / `Backspace` on a chip - Removes it and focuses its neighbour, or the input when no chip that can be removed is left. Holding the key down removes one chip, not the whole row
- `Escape` on a chip - Moves focus back to the input
- Typing on a chip - Moves focus back to the input, where the typed character lands

### Screen Reader Support

- Without options the input is a text field. With options it is a combobox with a multi-select listbox of checkable options
- The input's description reads the current values ("Selected: …") and says that Backspace moves to them, so the user hears what is already added and how to reach it
- Focus on a chip reads its label, its position and React Aria's hint to press Delete or Backspace to remove it
- A polite live region announces "Added …" and "Removed …" when the user adds or removes a value. Changes made from outside the field are not announced
- The chips, the popover trigger, the clear button and the options listbox are named after the field, however the field is named. With a visible label or `aria-labelledby`, they point at the same elements: the grid reads "Selected values" followed by the field's name, the trigger "Show options" followed by it, and the listbox the field's name alone. An `aria-label` has no element to point at, so its text is joined in: "Selected values, …", "Show options, …", "Clear all, …", and the listbox takes the `aria-label`. Next to a visible label or `aria-labelledby` it comes first, as it does on the input itself: with `aria-label="Values"` and `aria-labelledby` pointing at "Primary key", the input reads "Values Primary key" and the grid "Selected values, Values Primary key". Each row of a table whose fields are labelled by a header and a row cell so gets its own names
- Each chip is a row, and its remove button reads "Remove" followed by the chip's label. An invalid chip is described by its validation message, not only by its color
- A rejected value marks the input invalid. With a visible label its message is shown under the field and announced as an alert, again for each new attempt. Without one, the message is announced through the live region
- A disabled field's chips are out of the Tab order. A locked chip is reached by the arrow keys like any other and announced as disabled. A read-only field's chips stay focusable, without remove buttons
- The clear button is named "Clear all" followed by the field's name. It announces the removed values as "Removed …", as a chip's remove button does

### ARIA Properties

- `aria-label` / `aria-labelledby` - Name the input when there is no visible label, and through it the chips, the buttons and the listbox. Pass one of them, or `label`
- `aria-describedby` - Adds the summary of current values and the Backspace hint to the input's own descriptions, such as one passed in `aria-describedby`
- `aria-invalid` - Set while a typed value is rejected, or when the field is invalid
- `role="combobox"`, `aria-expanded`, `aria-controls`, `aria-activedescendant`, `aria-autocomplete="list"` - Set when options are given. `aria-activedescendant` follows both arrow keys and clicks

## Best Practices

1. **Do**: Validate each value with `validateTag` and the whole list with `rules`

   ```jsx
   <TagInput
     name="recipients"
     validateTag={validateEmail}
     rules={[{ max: 5, type: 'array', message: 'Up to five recipients' }]}
   />
   ```

2. **Don't**: Use it for a handful of fixed options. A [CheckboxGroup](https://cube-ui-kit.vercel.app/?path=/docs/forms-checkboxgroup--docs) or [FilterPicker](./FilterPicker.md) shows the choices without typing

3. **Do**: Say how to add a value in the `description` or `placeholder` when the delimiter is not obvious

4. **Do**: Turn delimiters off with `delimiters={[]}` when a value may contain a comma

5. **Don't**: Reach for `tagPlacement="inside"` by default. Chips below a fixed input are easier to read and to reach, and keep the field level with its neighbours; put them inside only where the field has no room below it

## Integration with Forms

The field value is an array of strings. With a `name`, the form stores the array and validates on change by default, and array rules like `{ type: 'array', max: 5 }` apply to it. The input itself holds only the text being typed, so it carries no `name` and a native form submission does not include it.

```jsx
<Form defaultValues={{ recipients: ['ana@acme.com'] }} onSubmit={save}>
  <TagInput
    name="recipients"
    label="Recipients"
    validateTag={validateEmail}
    rules={[{ required: true, message: 'Add at least one recipient' }]}
  />
  <Form.Submit>Save</Form.Submit>
</Form>
```

## Related Components

- [FilterPicker](./FilterPicker.md) - Use for picking several values from a list behind a button, without typing new ones
- [ComboBox](./ComboBox.md) - Use for one value with suggestions
- [CheckboxGroup](https://cube-ui-kit.vercel.app/?path=/docs/forms-checkboxgroup--docs) - Use for a short, fixed list of choices
- [Tag](../content/Tag.md) - The chip each value renders as
