Skip to content

Tags

InputMIT
View in Storybook

Multi-select tag input with type-to-add, autocomplete suggestions, validation, and max-tags limit.

bun add @otfdashkit/ui

Preview

Tags
Loading Storybook preview…

Code

import { useState } from 'react'
import { Tags } from '@otfdashkit/ui'

export function Example() {
  const [tags, setTags] = useState<string[]>([])
  return (
    <div className="flex w-[420px] flex-col gap-3">
      <Tags value={tags} onValueChange={setTags} placeholder="Type and press Enter…" />
      <p className="font-mono text-xs text-muted-foreground">
        value: [{tags.map((t) => `"${t}"`).join(', ')}]
      </p>
    </div>
  )
}

Free with the SDK. This component ships in @otfdashkit/ui under the MIT license.

Props

Props declared in the Tags source. Inherited HTML attributes are not listed.

PropTypeDefaultDescription
allowDuplicatesbooleanfalseAllow duplicate tags. Default false.
defaultValue(string | number | readonly string[]) & string[]Uncontrolled initial value.
disabledbooleanfalse
maxTagsnumberCap the total tags. When reached, the input is disabled.
onValueChange(tags: string[]) => voidFires whenever the tag list changes.
placeholderstring'Add a tag…'
suggestionsstring[]Optional autocomplete pool.
validate(tag: string) => string | booleanReturn false or an error string to reject a tag.
valuestring[]Controlled value.