Skip to content
h v3.13.3
Search the docs
Find a component, section or page.

Tags input

Labels picked from the values already used. Typing filters them, a near miss puts the fix first, and a new label takes the Create row.

Installation

pnpm add @heyramzi/ui

Usage

import { TagsInput } from "@heyramzi/ui/components/tags-input";
<TagsInput
  value={used}
  options={tools}
  label="Tools"
  labels={{ add: "Add a tool" }}
  onValueChange={(next) => (used = next)}
/>

Keyboard and accessibility

Key Does
Space Enter On the field, starts editing.
Arrow Down Arrow Up Moves through the suggestions. The list loops.
Enter Adds the highlighted suggestion. With the box empty, stops editing.
, Adds the highlighted suggestion.
Tab With text typed, adds the highlighted suggestion and stays in the box.
Backspace With the box empty, removes the last tag.
Arrow Left At the start of the box, moves onto the last tag. On a tag, moves to the one before.
Arrow Right On a tag, moves to the next one, then back to the box.
Backspace Delete Enter Space On a tag, removes it. Focus moves to the next tag or the box.
Esc On a tag, goes back to the box. In the box, clears what's typed, then stops editing and returns focus to the field.
  • The box is a combobox, and the suggestions are a listbox it points at.
  • With free set the box is a plain text field with no suggestions: Enter, comma, Space or Tab adds what's typed.
  • Pasting a comma-separated list adds each known label at once.
  • A tag's remove button is named "Remove" plus the tag. It stays out of the Tab order; the arrows reach it.
  • A polite status says "Added Make" or "Removed Make" once the change saves. labels.added and labels.removed change the words.
  • At rest the field is named by label and its tags, like "Tools: Docusign, SharePoint".

API reference

value required readonly string[]
The tags. Order is kept.
onValueChange required (next: string[]) => void | Promise<void>
Called with the whole next list. Throw to refuse: the list reverts.
options readonly string[]
Default []
The labels people pick from. Picking one stores its exact spelling and case.
allowCreate boolean
Default true
Whether a label that isn't an option may be made, through the "Create" row only. Text close to an option never becomes a label unless that row is chosen.
max number
Most tags the list holds. Past it the input goes away.
free boolean
Default false
Free typing, no options or menu: Enter, comma, space or Tab adds what's typed, a paste adds every part, and leaving the field keeps the text.
label required string
Accessible name of the field.
labels Partial<Labels>
disabled boolean
Default false
class string
Prop Type Default
value required

The tags. Order is kept.

readonly string[]
onValueChange required

Called with the whole next list. Throw to refuse: the list reverts.

(next: string[]) => void | Promise<void>
options

The labels people pick from. Picking one stores its exact spelling and case.

readonly string[] []
allowCreate

Whether a label that isn't an option may be made, through the "Create" row only. Text close to an option never becomes a label unless that row is chosen.

boolean true
max

Most tags the list holds. Past it the input goes away.

number
free

Free typing, no options or menu: Enter, comma, space or Tab adds what's typed, a paste adds every part, and leaving the field keeps the text.

boolean false
label required

Accessible name of the field.

string
labels Partial<Labels>
disabled boolean false
class string