Command palette

@yasinsensoy/native

React Native · Components

TagInput

Tag field: type and add a tag with a comma or the "done" key, remove it with the chip's × button; backspace in an empty input removes the last tag.

5 exports

Live example

The preview runs in the browser with the web component; the native component takes the same props and looks the same on iOS and Android.

Preview

  • React
  • TypeScript

Try pasting from Excel or a comma-separated list, and ← and Backspace in the empty field.

Code

import { TagField } from "@yasinsensoy/native";

<TagField label="Skills" name="tag" max={8} maxLength={24} placeholder="Type, add with Enter or a comma" required
  items={["React", "Next.js", …]} />

Events

  1. Events appear here when you interact with the preview.

Email recipients: split by space/comma/semicolon, validate

Hashtag: # is removed, only letters/digits/dashes, color by tag

  • #urgent
  • #design
  • #frontend

Team members: from the list only, search on the server

Read only

  • Turkish
  • English
  • Deutsch

Import

import { TagInput } from "@yasinsensoy/native";

TagInput

component

Tag field: type and add a tag with a comma or the "done" key, remove it with the chip's × button; backspace in an empty input removes the last tag. Rules are the same as the web TagInput (@yasinsensoy/core/tag-rules): duplicates, limit, length, pattern and validation; the reason for a rejected text is written below. A pasted list is split at separators.

TagInput(props: TagInputProps): ReactElement<unknown, string | JSXElementConstructor<any>>

Examples

<TagInput label="Tags" placeholder="Add a tag" max={5} />
<TagInput label="Languages" items={["TypeScript", "Kotlin", "Swift"]} allowCustomValue={false} />

Why a tag wasn't added.

type TagRejectReason = /** The same tag is already added (case and Turkish character differences are ignored). */ "duplicate" /** The `max` limit was reached. */ | "limit" /** Longer than `maxLength`. */ | "tooLong" /** Doesn't match the `pattern` or `validate` rule. */ | "invalid" /** Not among the suggestions while `allowCustomValue={false}`. */ | "notInList"

Tag validator. Returns true (or nothing) when valid, false or an error message to show when invalid.

type TagValidator = (tag: string, tags: readonly string[]) => boolean | string | null | undefined

Examples

`(tag) => tag.includes("@") || "Enter a valid email"`

Suggestion: text, or a value + display name.

type TagSuggestion = string | { value: string; label?: string; }

TagInputProps

interface

TagInput props.

Extends: FieldProps

NameTypeDefaultDescription
variant?FieldVariant"outline"Appearance. See FieldVariant.
value?readonly string[]Tags (controlled).
defaultValue?readonly string[]Initial tags (uncontrolled).
onValueChange?(tags: string[]) => voidWhen the tags change.
onTagAdd?(tag: string) => voidWhen a tag is added.
onTagRemove?(tag: string) => voidWhen a tag is removed.
onReject?(text: string, reason: TagRejectReason, message: string) => voidWhen a text cannot be added (the message is already shown below).
items?readonly TagSuggestion[]Suggestions: filtered as you type and shown as tappable chips under the field; tags already added are not shown.
allowCustomValue?booleantrueAllow adding text not in the suggestions.
separators?readonly string[][","]Separators that split the text while typing or pasting.
max?numberMaximum tags; when given a 3/10 counter shows.
maxLength?numberMaximum characters of a tag.
pattern?RegExpPattern the whole tag must match.
validate?TagValidatorExtra validation: return false or a message if invalid.
transform?(text: string) => stringTransforms the text before adding (e.g. lowercasing).
allowDuplicates?booleanfalseAllow the same tag more than once.
addOnBlur?booleantrueThe typed text becomes a tag on blur.
tone?Tone | ((tag: string) => Tone)"neutral"Tag color, or a color per tag.
renderTag?(tag: string) => ReactNodeRender the tag content yourself.
inputValue?stringText in the input (controlled).
onInputChange?(text: string) => voidWhen the text in the input changes.
placeholder?stringText shown while the box is empty.
icon?IconPropIcon at the start of the box.
clearable?booleanButton that removes all tags.
readOnly?booleanRead-only.
accessibilityLabel?stringScreen reader label.
style?StyleProp<ViewStyle>Style of the box.