ZUI

Search documentation

Find a page or a heading.

Tag input

A tag editor with removable chips above a field that adds a new tag on the return key, a comma, or leaving the field.

Installation

bash

The CLI writes components/data-entry/tag-input.tsx, installs Badge, Button, Icon, Input, Text and Utils, and adds lucide-react-native.

Usage

tsx
tsx

The root owns the tag array and hands adding and removing to its parts; other props land on the root View. Use it for a free-form list of tags the reader types, such as keywords or labels.

Composition

text

API reference

TagInput

Takes every prop of a View, plus:

A tag is trimmed, and an empty one or one the list holds already is never added.

TagInputList

Takes every prop of a View. The row the tags wrap in; it draws nothing while it holds no tag.

TagInputTag

Takes every prop of Badge, plus:

One tag, a secondary badge unless given another variant: the label, then its TagInputTagRemove. A string child is drawn in a Text, so the label goes in as the tag itself.

TagInputTagRemove

Takes every prop of Button except children. A ghost icon-xs button drawing a cross, announced as a button; name it with aria-label. Disabled with the root. An onPress runs first, and one that calls preventDefault keeps the tag. Throws outside a TagInputTag.

TagInputInput

Takes every prop of Input except value and defaultValue, and keeps the draft itself; name it with aria-label. The return key adds the draft and keeps the field focused for the next tag. A comma adds the text before it, so a pasted ui, docs, web adds each tag. Leaving the field adds what is left. Backspace in an empty field removes the last tag. Disabled with the root. Your own onChangeText, onSubmitEditing, onKeyPress and onBlur run before the field's.

Differences from the web

  • Android's soft keyboards do not report Backspace in an empty field, so there a tag goes by its own remove button.
  • A comma is read from the text as it changes rather than as a key, since a touch keyboard does not report every key.
  • onPress, onChangeText, onSubmitEditing and onKeyPress stand in for the web's onClick, onChange and onKeyDown.
  • The cross is a static icon; the web's plays while the button is hovered or focused. The badge does not pad its inline end for the button, since the web's padding reads a data-icon attribute.
  • The web's data-slot and data-disabled attributes are not set; a View takes no data attributes.