Skip to content
Eskais UI

Forms

Token Input

UI SDK Token Input styled as a field: removable token chips with undo, Backspace and arrow keys, and a labels mode where Enter or a comma commits and a paste splits; agents set it by label.

Example

​bug label​​docs label​

Enter or a comma adds a label; Backspace removes one and Ctrl+Z brings it back.

Installation

npx shadcn@latest add @eskais/token-input
npm packageslucide-react

Usage

Import
import {  TokenInput,  TokenInputEditor,  TokenInputToken,  TokenInputTokenRemove,  createTokenInputController,  labelCodec,  tokenLabels,} from "@/components/ui/token-input"import {  draftText,  labelCodec,  labelToken,  labelTokens,  sameLabels,  settleLabels,  tokenLabels,} from "@/components/ui/token-input-labels"

Reach for it when a field holds a list, like labels or topics; without tokenType it mixes text with mentions or files.

API reference

TokenInput

PropTypeDefault
classNamestring–
onBlurFocusEventHandler<HTMLDivElement>–
toneThe chips' tone, or a function of each token; `neutral` by default.TokenTone–
labelsPartial<TokenInputLabels>–
tokenTypeMakes it a list of labels, each a token of this type: Enter or a comma turns the typed text into one, and pasted text splits on commas and line breaks. The value is the labels.undefined | string–
valuereadonly (string | Token)[] | readonly string[]–
defaultValuereadonly (string | Token)[] | readonly string[]–
onValueChange(value: TokenInputValue, details: TokenInputValueChangeDetails) => void | (labels: string[], details: TokenInputValueChangeDetails) => void–
validateWhether a label may become a token; one that can't stays as text to fix.(label: string) => boolean–
maxThe most labels it holds; text typed past it stays as text.number–

Also takes TokenInputProps except value, defaultValue, onValueChange.

TokenInputToken

PropTypeDefault
toneThe chip's tone; the TokenInput's `tone` by default.Tone–

Also takes every prop of UI SDK TokenInputToken.

TokenInputTokenRemove

Takes every prop of UI SDK TokenInputTokenRemove.

Other exports

createTokenInputControllerlabelCodectokenLabelsdraftTextlabelTokenlabelTokenssameLabelssettleLabelstype TokenInputLabelstype TokenInputLabelPropstype TokenInputPropstype TokenInputTextPropstype TokenInputTokenPropstype Tokentype TokenCodectype TokenInputControllertype TokenInputValuetype TokenInputValueChangeDetailstype TokenLabelRules

Accessibility

  • One multiline text box named by its Field; each token reads as its label and kind, and adding or removing one is announced.
  • Backspace and Delete remove the token beside the caret, arrows cross a token in one press, and Ctrl+Z or Cmd+Z undoes.
  • The remove buttons are for pointers only, grow to 44px on touch and are named for hover by labels.remove.

Agent actions

Agents find it by its label and call setValue with comma-separated labels, insert, removeToken or clear.

Runs agent.snapshot() from @ui-sdk/react/agent on the live preview above.