Skip to content
Forms

TagInput

Free-text tags with keyboard editing and a limit.

import
import { TagInput } from '@joshicodes/cock';

Tags

Try adding a tag twice: the one you already have flashes instead of nothing happening.

design svelte long walks

Keyboard

Enter or ,
Adds the tag being typed
Backspace
On an empty field, removes the last tag
Paste
Splits on commas and newlines

Behaviour

  • A rejected tag — duplicate, over the limit or turned down by `validate` — flashes instead of disappearing silently, so Enter never looks broken.

API

Read out of the component sources at build time, so it matches the version you installed. Every component also takes class, merged through tailwind-merge so your utility wins.

Props of TagInput

PropTypeDefault
value bindable
string[][]
placeholder
string'Add a tag…'
max

Stop accepting tags at this many.

number—
allowDuplicates
booleanfalse
validate

Return false to reject a tag.

(tag: string) => boolean—
disabled
booleanfalse
invalid
booleanfalse
id
string—
class
string—

Events of TagInput

EventTypeDefault
onchange
(tags: string[]) => void—

See also

cock. Yes, it stands for core component kit. We checked twice.