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
- Write a placeholder that says what to add, like “Add labels…” or “Email addresses”.
- Set
delimitersso a comma or a space ends a tag, and a pasted list turns into tags. - Set
maxSelectedwhen the number is limited, like five reviewers. - Offer suggestions from existing tags, so people don’t create near duplicates.
- 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.
| Prop | Type | Default |
|---|---|---|
valueThe tags. Pass it to control the input. | string[] | — |
defaultValueThe tags at first, when uncontrolled. | string[] | [] |
onValueChangeRuns when a tag is added or removed. | (value: string[], details) => void | — |
delimitersKeys that add the typed text as a tag. Pasted text is split on them and on new lines. | string[] | [','] |
maxSelectedHow many tags it holds at most. | number | — |
nameThe name each tag submits under. | string | — |
disabledCan’t be focused or changed, and isn’t submitted. | boolean | false |
TagInputField
The box around the tags and the text input. Renders a <div>.
| Prop | Type | Default |
|---|---|---|
sizeHeight of one row; matches Input sizes. | 'sm' | 'md' | 'lg' | 'md' |
placeholderHint shown in the input. | string | — |
inputPropsProps for the text input, such as aria-label when there is no Field. | ComboboxInputProps | — |
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
TagInputContent
The popup of suggestions, anchored under the field. Opens as you type.
| Prop | Type | Default |
|---|---|---|
alignHow it lines up with the field. | 'start' | 'center' | 'end' | 'start' |
sideOffsetGap below the field, in pixels. | number | 6 |
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
TagInputItem
One suggestion, with a check while it’s a tag. Choosing it again removes it.
| Prop | Type | Default |
|---|---|---|
valueThe tag it adds. | string | — |
labelText to match, when children aren’t plain text. | string | — |
disabledCan’t be chosen. | boolean | false |
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
TagInputEmpty
Shown while no suggestion matches the text.
| Prop | Type | Default |
|---|---|---|
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |