DitherCharts

Tag input

Updated

TagInput collects free-text values as solid ink chips, like keywords or email addresses, where a multiple Combobox only picks from its options. Enter, a comma or leaving the field adds a tag, a pasted list splits on commas, and Backspace removes the last one. Like the charts, it takes your theme's ink and paper, light or dark, and needs no Tailwind.

Example

revenuechurn

Press Enter or a comma to add.

ops@example.com
import "@/components/dithercharts/controls.css"
import { TagInput } from "@/components/dithercharts/tag-input"

<TagInput
  label="Keywords"
  name="keywords"
  defaultValue={["revenue", "churn"]}
  placeholder="Add a keyword"
  hint="Press Enter or a comma to add."
  onValueChange={(tags) => setKeywords(tags)}
/>

Install

Controls install with DitherCharts Pro. See Installation to log in, then import controls.css once, e.g. in your root layout.

npx dithercharts add tag-input

Props

It renders a native element, so every other attribute that element takes passes through.

TagInput props
PropTypeDefaultDescription
labelrequiredType ReactNodeDefault –The caption above the field, and its accessible name.
valueType readonly string[]Default –The tags, for a controlled field; pair it with onValueChange.
defaultValueType readonly string[]Default –The tags at first, for an uncontrolled field.
onValueChangeType (value: string[]) => voidDefault –Called with the tags after one is added or removed.
placeholderType stringDefault –Shown while there are no tags.
nameType stringDefault –The form field name; a hidden input carries each tag.
disabledType booleanDefault false
classNameType stringDefault –
hintType ReactNodeDefault –Help text under the field, read after its label.
errorType ReactNodeDefault –An error under the field; it also marks the field invalid.