Tags Input

A text field where each value the user enters becomes a removable tag.

SolidJS
Lever UI
TypeScript
Press Enter or Return to add a tag

Usage

Code
import { TagsInput } from '@leverui/components';
Code
<TagsInput.Root>
  <TagsInput.Label />
  <TagsInput.Control>
    <TagsInput.Item>
      <TagsInput.ItemPreview>
        <TagsInput.ItemText />
        <TagsInput.ItemDeleteTrigger />
      </TagsInput.ItemPreview>
      <TagsInput.ItemInput />
    </TagsInput.Item>
    <TagsInput.Input />
  </TagsInput.Control>
</TagsInput.Root>

Shortcuts

TagsInputItems

TagsInputItems renders one item for every tag in the current value.

Code
<TagsInput.Context>
  {(api) => (
    <For each={api().value}>
      {(tag, index) => (
        <TagsInput.Item index={index()} value={tag}>
          <TagsInput.ItemPreview>
            <TagsInput.ItemText>{tag}</TagsInput.ItemText>
            <TagsInput.ItemDeleteTrigger />
          </TagsInput.ItemPreview>
          <TagsInput.ItemInput />
        </TagsInput.Item>
      )}
    </For>
  )}
</TagsInput.Context>

Shorter, if you do not customize the items:

Code
<TagsInput.Items />

Examples

Sizes

Use the size prop to adjust the size of the tags input.

SolidJS
Lever UI
TypeScript
Press Enter or Return to add a tag
SolidJS
Lever UI
TypeScript
Press Enter or Return to add a tag
SolidJS
Lever UI
TypeScript
Press Enter or Return to add a tag
SolidJS
Lever UI
TypeScript
Press Enter or Return to add a tag

Variants

Use the variant prop to change the visual style of the tags input.

SolidJS
Lever UI
TypeScript
Press Enter or Return to add a tag
SolidJS
Lever UI
TypeScript
Press Enter or Return to add a tag
SolidJS
Lever UI
TypeScript
Press Enter or Return to add a tag

Controlled

Use the value and onValueChange props to programmatically control the tags.

SolidJS
Lever UI

Store

An alternative way to control the tags input is to use the RootProvider component and the useTagsInput store function. This way you can access the tags input state and methods from outside the component.

Use RootProvider + useTagsInput or Root, not both.

Max Tags

Pass the max prop to the TagsInput.Root component to limit the number of tags that can be added.

You've invited 1 / 3 guests to your event

Editable Tags

Use the editable prop to enable inline editing of existing tags by double clicking or pressing Enter when highlighted, allowing users to quickly update tag values.

SolidJS
Lever UI
Use the arrow keys to pick a tag, then press Enter to edit it

Validate Tag

Use the validate prop to implement custom validation rules. Tags will be added when the validation passes.

SolidJS
Lever UI

Disabled

Use the disabled prop to disable the tags input to prevent user interaction.

SolidJS
Lever UI

Readonly

Use the readOnly prop to make the tags input read-only. Tags input can be focused but can't be modified.

SolidJS
Lever UI

Invalid

Pass the invalid prop to the TagsInput.Root component to display the tags input in an invalid state with error messages.

SolidJS
Lever UI
Add at least three tags.

Field

Here's an example that composes the TagsInput.Root with the Field component to add labels, helper text, and error messages.

SolidJS
Lever UI
TypeScript
Separate tags with a comma

Form

Here's an example that composes the TagsInput.Root with a form to collect structured data and handle submissions.

Add frameworks and libraries you use

Paste

Pass the addOnPaste prop to the TagsInput.Root component to allow users to paste multiple values at once, automatically splitting them into individual tags based on a delimiter.

Copy tags
SolidJS,Lever UI,TypeScript

Sanitize Values

Use the sanitizeValue prop to normalize a value before it is added, such as trimming whitespace or converting text to lowercase.

Tags are trimmed and converted to lowercase.

Blur Behavior

Use the blurBehavior prop to configure how the input behaves when it loses focus, such as automatically creating a tag from the current input value.

Custom Delimiter

Use the delimiter prop to use custom delimiters like commas, semicolons, or spaces to create new tags as users type.

Colors

Here's an example that assigns rather color scheme to the tags based on the tag value.

SolidJS
Lever UI
TypeScript

Combobox

Here's an example that composes the TagsInput component with the Combobox component to create a tags input that allows users to select from a list of predefined tags.

Props

Root

PropDefaultTypeDescription
delimiter,string | RegExpKey that adds a tag. Also separates pasted values.
maxInfinitynumberMost tags allowed.
sanitizeValue(value) => value.trim()(value: string) => stringClean up a tag value before it is added.
colorPalettegray'gray' | 'red' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'cyan' | 'purple' | 'pink'Color palette.
sizemd'xs' | 'sm' | 'md' | 'lg'Tags input size. Responsive.
variantoutline'outline' | 'subtle' | 'flushed'Tags input style. Responsive.
asdivNative HTML tagHTML tag to render.
asChild—Solid render functionRender your own element with the part's props.
unstyledfalsebooleanTurn off the default styles. Behavior and parts stay.
addOnPastefalsebooleanAdd tags from pasted values.
allowDuplicatesfalsebooleanAllow the same tag more than once.
allowOverflow—booleanLet tags go over max. The root is then marked invalid.
autoFocus—booleanFocus the input on first render.
blurBehavior—'clear' | 'add'On blur, add the typed text as a tag or clear it.
defaultInputValue—stringStarting input text.
defaultValue—string[]Starting tags.
disabled—booleanDisable the tags input.
editablefalsebooleanEdit a highlighted tag with Enter or a double click.
form—stringForm the underlying input belongs to.
id—stringUnique id.
ids—Element ID mapIds of the elements.
inputValue—stringInput text, when you control it.
invalid—booleanMark the tags input invalid.
maxLength—numberMost characters allowed in the input.
name—stringname attribute submitted with the form.
onFocusOutside—(event: FocusOutsideEvent) => voidCalled when focus moves outside.
onHighlightChange—(details: HighlightChangeDetails) => voidCalled when a tag is highlighted.
onInputValueChange—(details: InputValueChangeDetails) => voidCalled when the input text changes.
onInteractOutside—(event: InteractOutsideEvent) => voidCalled on an interaction outside.
onPointerDownOutside—(event: PointerDownOutsideEvent) => voidCalled on pointer down outside.
onValueChange—(details: ValueChangeDetails) => voidCalled when the tags change.
onValueInvalid—(details: ValidityChangeDetails) => voidCalled when max is reached or validation fails.
placeholder—stringInput placeholder text.
readOnly—booleanMake the tags input read-only.
required—booleanMark the tags input required.
translations—IntlTranslationsTranslated text for assistive technology.
validate—(details: ValidateArgs) => booleanDecide whether a tag can be added.
value—string[]Tags, when you control them.

Item

PropDefaultTypeDescription
index—string | numberPosition of the item in the list. Required.
value—stringTag value of the item. Required.
asdivNative HTML tagHTML tag to render.
asChild—Solid render functionRender your own element with the part's props.
disabled—booleanDisable the item.

Form submit: set name on Root and include HiddenInput. The tags are then in the browser's FormData. Inside Field, link the input to the helper text with aria-describedby. Check for duplicates in validate. Delete tags through the item parts, which carry an index.

Items renders the current tags by index and adds no wrapper element. For per-tag content or styling, use Context, Item, ItemPreview, ItemText, ItemDeleteTrigger, and ItemInput directly. PropsProvider can take an accessor, so shared defaults can change without replacing the root.

Suggestions: create the Tags Input state and the Combobox state yourself, with one shared input element and the same label, input, and control IDs. Render Combobox.Control through TagsInput.Control with asChild so the popup is positioned against the tags control. Pass the shared label ID to TagsInput.Label as id.

Customize with CSS

The root and every public part have stable .leverui-tags-input__* classes. Override those or the --leverui-* theme tokens. class and style also work. --leverui-private-tags-input-* variables are for internal sizing.

Code
.email-tags .leverui-tags-input__control {
  border-radius: 1rem;
}

.email-tags {
  --leverui-colors-color-palette-subtle: #e0f2fe;
}

Add class="email-tags" to TagsInput.Root to scope these to one field. Load your CSS after styles.css.

Explorer

Click a part name to highlight it in the preview.

Component Anatomy

Hover to highlight, click to select parts