datui
Color scheme

Forms

ChipsInput

Free-form tag input: Enter or a delimiter turns typed text into chips.

import { ChipsInput } from "datui";

Playground

<ChipsInput placeholder="Add a tag" status="default" />

Examples

Basic

  • react
  • tailwind
Press Enter or type a comma to add

Controlled with delimiters

Split on comma, semicolon or space; add on blur.

0 recipient(s)

Accessibility

  • The text input takes its label from FormItem or aria-label; chips are a list named chipsListLabel.
  • Enter adds the typed text, typing or pasting a delimiter splits it into chips, Backspace in the empty input removes the last chip.
  • Each chip's remove button is a labelled native button ("Remove alpha"); removing returns focus to the input.
  • disabled / readOnly block adding and removing.

API

ChipsInput

Free-form tag input. Enter or a delimiter (`,` by default; pasting splits too) turns the typed text into a chip, Backspace in the empty input removes the last chip, each chip has a remove button. Duplicate values are ignored. `ref` points at the text input.

PropTypeDefaultDescription
addOnBlurbooleanfalseTurn leftover text into a chip when the field loses focus.
afterReactNode—Content after the control, e.g. an icon, clear button or unit.
allowClearButtonbooleanfalseShows a button that removes every chip and the typed text.
beforeReactNode—Content before the control, usually an icon.
chipsListLabelstring"Selected"Accessible name of the chips list.
classNamestring—
clearLabelstring"Clear"
defaultInputValuestring—
defaultValueChipOption[]—
delimiterstring | RegExp | string[]","Typing or pasting a delimiter turns the text before it into chips. `[]` disables splitting.
getNewOptionData((label: string) => ChipOption)label => ({ value: label, label })Builds a chip from typed text.
inputValuestring—Text typed after the chips.
maxHeightnumber—Caps the field height in px; content scrolls beyond it.
onChange((value: ChipOption[]) => void)—
onInputChange((value: string) => void)—
removeLabelstring"Remove"Prefix of each chip's remove-button label.
renderChip((props: ChipProps, option: ChipOption) => ReactNode)—Custom chip. Spread the given props onto `Chip` to keep removal working.
slotProps{ root?: (FormFieldProps & { ref?: Ref<HTMLDivElement>; }); } | undefined—Props for the FormField shell.
statusFormFieldStatus"default"Visual validation state. Pair `error` with `aria-invalid` on the control (FormItem does this).
valueChipOption[]—Chips.