Search docs

Tags Input

Input for entering, editing, and managing a list of tags.

Tags Input renders a role="group" container with a native text <input>, keyboard-navigable tag items, inline editing, paste splitting, screen reader announcements, and a HiddenInput for form submission.

Qwik
TypeScript
import { component$, useSignal, useStyles$ } from '@builder.io/qwik';
import { TagsInput } from '@leve-ui/tags-input';
import { LuX } from '@qwikest/icons/lucide';
import styles from './default.css?inline';

export default component$(() => {
  useStyles$(styles);
  const tags = useSignal<string[]>(['Qwik', 'TypeScript']);

  return (
    <TagsInput.Root bind:value={tags} class="tags-input-default">
      <TagsInput.Label class="tags-input-default-label">Frameworks</TagsInput.Label>
      <TagsInput.Control class="tags-input-default-control">
        {tags.value.map((tag, index) => (
          <TagsInput.Item
            key={`${tag}-${index}`}
            index={index}
            value={tag}
            class="tags-input-default-item"
          >
            <TagsInput.ItemPreview class="tags-input-default-item-preview">
              <TagsInput.ItemText class="tags-input-default-item-text">{tag}</TagsInput.ItemText>
              <TagsInput.ItemDeleteTrigger class="tags-input-default-item-delete">
                <LuX aria-hidden="true" />
              </TagsInput.ItemDeleteTrigger>
            </TagsInput.ItemPreview>
            <TagsInput.ItemInput class="tags-input-default-item-input" />
          </TagsInput.Item>
        ))}
        <TagsInput.Input placeholder="Add framework..." class="tags-input-default-input" />
        <TagsInput.ClearTrigger class="tags-input-default-clear" aria-label="Clear all tags">
          <LuX aria-hidden="true" />
        </TagsInput.ClearTrigger>
      </TagsInput.Control>
    </TagsInput.Root>
  );
});

Installation#

Install the individual package, or use @leve-ui/core to get every component at once:

pnpm add @leve-ui/tags-input

Anatomy#

import { TagsInput } from '@leve-ui/tags-input'; // or '@leve-ui/core'

<TagsInput.Root>
  <TagsInput.Label>Tags</TagsInput.Label>
  <TagsInput.Control>
    <TagsInput.Item index={0} value="qwik">
      <TagsInput.ItemPreview>
        <TagsInput.ItemText>qwik</TagsInput.ItemText>
        <TagsInput.ItemDeleteTrigger />
      </TagsInput.ItemPreview>
      <TagsInput.ItemInput />
    </TagsInput.Item>
    <TagsInput.Input />
    <TagsInput.ClearTrigger />
  </TagsInput.Control>
  <TagsInput.HiddenInput name="tags" />
</TagsInput.Root>
PartElementDescription
TagsInput.Root<div>Group container (role="group") managing tag state, keyboard navigation, and Field wiring.
TagsInput.Label<label>Accessible label associated with TagsInput.Input.
TagsInput.Control<div>Interactive wrapper that focuses TagsInput.Input when clicking empty space.
TagsInput.Item<div>Container for a single tag item. Double-clicking enters inline edit mode.
TagsInput.ItemPreview<div>Displays the tag text and delete trigger when not editing.
TagsInput.ItemText<span>Displays the tag text content.
TagsInput.ItemDeleteTrigger<button>Removes the tag and returns focus to TagsInput.Input.
TagsInput.ItemInput<input>Inline text input shown while editing an existing tag.
TagsInput.Input<input>Primary text input for adding new tags and navigating existing tags.
TagsInput.ClearTrigger<button>Clears all tags and returns focus to TagsInput.Input.
TagsInput.HiddenInput<input>Visually hidden input that submits comma-joined tags in a <form> and resets on form reset.

Examples#

Controlled#

Control the tags array with bind:value and update it externally.

design
a11y

Value: design, a11y

Editable#

Double-click a tag or press Enter / F2 while a tag is highlighted to edit it inline.

alpha
beta
gamma

Validation#

Limit the number of tags with max, disallow duplicates with allowDuplicates={false}, and split pasted text with addOnPaste.

one
two

Disabled#

disabled on the Root disables adding, editing, and removing tags.

Qwik
TypeScript

Read Only#

readOnly prevents modifying tags while keeping the input focusable.

Qwik
TypeScript

With Field#

Inside a Field.Root, Field.Label points to the input, and Field.Description, Field.ErrorMessage, and inherited states are wired automatically.

accessibility
Press Enter or comma to add a skill.

With Form#

Use TagsInput.HiddenInput to submit comma-joined tags in a <form> and reset on form reset.

qwik
ui
Not submitted yet

With Combobox#

Compose TagsInput.Control and TagsInput.Input with Combobox.Control and Combobox.Input using the as prop, share bind:inputValue, and set selectionBehavior="clear" on Combobox.Root so choosing a suggestion adds a tag and clears the filter text while still allowing custom tags.

Qwik
TypeScript
Playwright
Vitest
Vite
Biome
Solid
Press Enter to add custom tag
import { $, component$, useComputed$, useSignal, useStyles$ } from '@builder.io/qwik';
import { Combobox } from '@leve-ui/combobox';
import { TagsInput } from '@leve-ui/tags-input';
import { LuChevronDown, LuX } from '@qwikest/icons/lucide';
import styles from './with-combobox.css?inline';

const FRAMEWORKS = ['Qwik', 'TypeScript', 'Playwright', 'Vitest', 'Vite', 'Biome', 'Solid'];

export default component$(() => {
  useStyles$(styles);
  const tags = useSignal<string[]>(['Qwik']);
  const inputValue = useSignal('');

  const available = useComputed$(() => {
    const query = inputValue.value.trim().toLowerCase();
    return FRAMEWORKS.filter(
      (item) => !tags.value.includes(item) && item.toLowerCase().includes(query),
    );
  });

  // Add the chosen suggestion to the tags array while Combobox clears the filter text
  const handleSelect$ = $((value: string | null) => {
    if (!value) return;
    if (!tags.value.includes(value)) {
      tags.value = [...tags.value, value];
    }
  });

  return (
    <TagsInput.Root bind:value={tags} bind:inputValue={inputValue} class="tags-input-with-combobox">
      <Combobox.Root
        bind:inputValue={inputValue}
        selectionBehavior="clear"
        openOnClick
        onValueChange$={handleSelect$}
      >
        <TagsInput.Label class="tags-input-with-combobox-label">Frameworks</TagsInput.Label>
        <TagsInput.Control as={Combobox.Control} class="tags-input-with-combobox-control">
          {tags.value.map((tag, index) => (
            <TagsInput.Item
              key={`${tag}-${index}`}
              index={index}
              value={tag}
              class="tags-input-with-combobox-item"
            >
              <TagsInput.ItemPreview class="tags-input-with-combobox-item-preview">
                <TagsInput.ItemText class="tags-input-with-combobox-item-text">
                  {tag}
                </TagsInput.ItemText>
                <TagsInput.ItemDeleteTrigger class="tags-input-with-combobox-item-delete">
                  <LuX aria-hidden="true" />
                </TagsInput.ItemDeleteTrigger>
              </TagsInput.ItemPreview>
              <TagsInput.ItemInput class="tags-input-with-combobox-item-input" />
            </TagsInput.Item>
          ))}
          <TagsInput.Input
            as={Combobox.Input}
            placeholder="Type or select a framework..."
            class="tags-input-with-combobox-input"
          />
          <Combobox.Trigger
            class="tags-input-with-combobox-trigger"
            aria-label="Toggle suggestions"
          >
            <LuChevronDown class="tags-input-with-combobox-trigger-icon" aria-hidden="true" />
          </Combobox.Trigger>
        </TagsInput.Control>
        <Combobox.Content class="tags-input-with-combobox-content">
          <Combobox.List aria-label="Framework suggestions">
            {available.value.map((item) => (
              <Combobox.Item key={item} value={item} class="tags-input-with-combobox-option">
                <Combobox.ItemText>{item}</Combobox.ItemText>
              </Combobox.Item>
            ))}
            <Combobox.Empty class="tags-input-with-combobox-empty">
              Press Enter to add custom tag
            </Combobox.Empty>
          </Combobox.List>
        </Combobox.Content>
      </Combobox.Root>
    </TagsInput.Root>
  );
});

Suggestions Only#

Set allowCustomValue={false} on TagsInput.Root with autoHighlight on Combobox.Root to restrict tags to items selected from the suggestion list.

Qwik
TypeScript
Playwright
Vitest
Vite
Biome
Solid
No matching frameworks

API Reference#

Root#

PropDefaultType
ids–{ root?: string; label?: string; control?: string; input?: string }

Overrides the element IDs of the parts. Inside a Field, the input ID comes from the Field.

defaultValue[]string[]

The initial tags array (uncontrolled).

bind:value–Signal<string[]>

A signal with the tags array (controlled).

onValueChange$–QRL<(value: string[]) => void>

Called when the tags array changes.

defaultInputValue''string

The initial text value of the input (uncontrolled).

bind:inputValue–Signal<string>

A signal with the input text value (controlled).

onInputValueChange$–QRL<(value: string) => void>

Called when the input text value changes.

delimiter','string

The delimiter character that splits and commits tags while typing or pasting.

max–number

Maximum number of tags allowed.

allowDuplicatesfalseboolean

Whether duplicate tag values are allowed.

editabletrueboolean

Whether existing tags can be edited inline via double-click or Enter/F2.

addOnPastefalseboolean

Whether pasting text splits on the delimiter/newlines and adds tags automatically.

allowCustomValuetrueboolean

Whether free-text values typed or pasted into the input can be added as tags. Set to false to only allow tags added programmatically (for example from a composed Combobox).

disabledfalseboolean

Disables the tags input. Inside a Field or Fieldset, the inherited disabled also applies.

readOnlyfalseboolean

Marks the tags input as read-only. Inside a Field, the Field's readOnly also applies.

requiredfalseboolean

Marks the tags input as required. Inside a Field, the Field's required also applies.

invalidfalseboolean

Marks the tags input as invalid. Inside a Field, the Field's invalid also applies.

Also accepts all <div> attributes.

Data attributeValue
data-leve-tags-inputAlways present
data-state"has-tags" | "empty"
data-disabledPresent when disabled
data-readonlyPresent when read-only
data-invalidPresent when invalid

Label#

No props of its own. Accepts all <label> attributes.

Control#

PropDefaultType
as–keyof HTMLElementTagNameMap | Component<any>

The element or component to render instead of <div>. A component must spread the props it receives onto one element.

Also accepts all <div> attributes.

Item#

PropDefaultType
index (required)–number

Zero-based index of this tag item.

value (required)–string

Value of this tag item.

disabledfalseboolean

Disables this individual tag item.

Also accepts all <div> attributes.

Data attributeValue
data-leve-tags-input-itemAlways present
data-indexZero-based item index
data-state"editing" | "active" | "idle"
data-highlightedPresent when highlighted
data-disabledPresent when disabled

ItemPreview#

No props of its own. Accepts all <div> attributes.

ItemText#

No props of its own. Accepts all <span> attributes.

ItemDeleteTrigger#

No props of its own. Accepts all <button> attributes.

ItemInput#

No props of its own. Accepts all <input> attributes.

Input#

PropDefaultType
as–keyof HTMLElementTagNameMap | Component<any>

The element or component to render instead of <input>. A component must spread the props it receives onto one element.

Also accepts all <input> attributes.

ClearTrigger#

No props of its own. Accepts all <button> attributes.

HiddenInput#

PropDefaultType
form–string

The id of the form element to associate the input with.

Also accepts all <input> attributes.

Accessibility#

Tags Input uses native <label> and <input> elements inside a role="group" container with aria-labelledby, aria-describedby, aria-invalid, and aria-disabled, plus live-region announcements when tags are added, updated, removed, or cleared.

Keyboard Interactions#

KeyDescription
EnterAdds the trimmed input text as a tag, or starts editing the highlighted tag. In ItemInput, commits the edit.
BackspaceHighlights the last tag when the input is empty, or removes the highlighted tag.
DeleteRemoves the highlighted tag.
ArrowLeftMoves highlight to the previous tag.
ArrowRightMoves highlight to the next tag, or returns to the text input.
Home / EndHighlights the first or last tag when a tag is highlighted or the input is empty.
F2Enters inline edit mode on the highlighted tag when editable is enabled.
EscapeCancels inline editing or clears tag highlight and returns focus to TagsInput.Input.