Components

Tag Input

Collects tags in a field: typed, pasted as a list, or picked from suggestions.

Usage

import {
  TagInput,
  TagInputContent,
  TagInputEmpty,
  TagInputField,
  TagInputItem,
} from 'nyctoui/tag-input'

<TagInput defaultValue={['Bug']}>
  <TagInputField placeholder="Add a label…" />
  <TagInputContent>
    <TagInputEmpty>Press Enter to add it as a new label.</TagInputEmpty>
    <TagInputItem value="Bug">Bug</TagInputItem>
    <TagInputItem value="Feature">Feature</TagInputItem>
  </TagInputContent>
</TagInput>

ui-sdk has no tag input of its own. This one is its Combobox with multiple and allowCustomValue: the chips, Backspace and arrow keys between tags, the suggestion list and form submission all come from it. On top, a delimiter key turns the text into a tag, and pasting a list adds each entry. A tag that’s already there isn’t added twice.

TagInputField draws the Input box, one row tall at each control height, and wraps onto more rows as tags are added. Tags look like a neutral Badge with a remove button.

Good for

  • Adding labels to an issue or a blog post.
  • Inviting several people by email in team settings, pasting a list at once.
  • Picking skills on a job application or a profile.
  • Adding keywords to a product listing in a marketplace.

Examples

Without suggestions

Leave out TagInputContent and every tag is typed. delimiters sets the keys that add one, here a comma and a space for email addresses; pasting “a@x.com, b@x.com” adds both.

Sizes

One row matches the 24, 32 and 40px control heights, so the field lines up with a button beside it.

In a form

With name, each tag submits as its own value under that name. maxSelected caps the count, and a form reset returns to defaultValue.

Disabled

Keyboard

Enter adds the typed text, or the highlighted suggestion. A delimiter (, by default) adds the text too. Backspace in the empty input removes the last tag. Left and Right move between tags, where Backspace removes the focused one. Down and Up move through the suggestions, and Esc closes them.

Best practices

Do
  • Write a placeholder that says what to add, like “Add labels…” or “Email addresses”.
  • Set delimiters so a comma or a space ends a tag, and a pasted list turns into tags.
  • Set maxSelected when the number is limited, like five reviewers.
  • Offer suggestions from existing tags, so people don’t create near duplicates.
Don’t
  • Use a tag input for a single value. Use a select or an input.
  • Color each tag differently. Keep the default look so the set reads as one.
  • Hide the label; people need to know what the tags are for.

API reference

TagInput

Wraps ui-sdk’s Combobox with multiple and allowCustomValue, and takes its other props, such as required, filter and onQueryChange. Renders no element.

PropTypeDefault
value
The tags. Pass it to control the input.
string[]—
defaultValue
The tags at first, when uncontrolled.
string[][]
onValueChange
Runs when a tag is added or removed.
(value: string[], details) => void—
delimiters
Keys that add the typed text as a tag. Pasted text is split on them and on new lines.
string[][',']
maxSelected
How many tags it holds at most.
number—
name
The name each tag submits under.
string—
disabled
Can’t be focused or changed, and isn’t submitted.
booleanfalse

TagInputField

The box around the tags and the text input. Renders a <div>.

PropTypeDefault
size
Height of one row; matches Input sizes.
'sm' | 'md' | 'lg''md'
placeholder
Hint shown in the input.
string—
inputProps
Props for the text input, such as aria-label when there is no Field.
ComboboxInputProps—
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

TagInputContent

The popup of suggestions, anchored under the field. Opens as you type.

PropTypeDefault
align
How it lines up with the field.
'start' | 'center' | 'end''start'
sideOffset
Gap below the field, in pixels.
number6
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

TagInputItem

One suggestion, with a check while it’s a tag. Choosing it again removes it.

PropTypeDefault
value
The tag it adds.
string—
label
Text to match, when children aren’t plain text.
string—
disabled
Can’t be chosen.
booleanfalse
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

TagInputEmpty

Shown while no suggestion matches the text.

PropTypeDefault
sx
StyleX styles merged after the built-in ones.
StyleXStyles—