TextArrayInput

Lets users enter multiple free-text values (like tags or email addresses) displayed as removable badges.

Installation

pnpm dlx shadcn@latest add @shadmin/text-array-input

This input allows editing values that are arrays of strings, e.g. ["tag1", "tag2"].

Usage

import { TextArrayInput } from "@/components/admin";
 
<TextArrayInput source="tags" />;

Users type text and press Enter to add items. Items appear as removable badges. Press Backspace when the input is empty to remove the last item.

Tip: If you need to let users choose values from a predefined list instead, use <AutocompleteArrayInput>.

Props

PropRequiredTypeDefaultDescription
sourceRequiredstring-Field name
classNameOptionalstring-CSS classes
defaultValueOptionalstring[]-Default value
disabledOptionalboolean-Disable the input
formatOptionalfunction-Callback to convert API value to form value
helperTextOptionalReactNode-Help text displayed below the input
labelOptionalstring | falseInferred from sourceCustom label, or false to hide it
optionsOptionalstring[]-Preset suggestion strings shown in a dropdown
parseOptionalfunction-Callback to convert form value to API value
placeholderOptionalstring-Input placeholder (shown when no values exist)
readOnlyOptionalboolean-Make the input read-only
renderTagsOptional(tags, getTagProps) => ReactNode-Custom renderer for the selected-value chips
validateOptionalValidator | Validator[]-Validation rules

Keyboard Shortcuts

KeyAction
EnterAdd the typed text as a new value
BackspaceRemove the last value (when input is empty)
EscapeBlur the input

renderTags

Custom render function for the selected-value chips. When provided it replaces the default <Badge> per tag. Receives the full tags array and a getTagProps(tag, index) helper that returns { key, onDelete }.

import { Tag } from "lucide-react";
 
<TextArrayInput
  source="tags"
  renderTags={(tags, getTagProps) =>
    tags.map((tag, index) => {
      const { key, onDelete } = getTagProps(tag, index);
      return (
        <span
          key={key}
          className="flex items-center gap-1 rounded bg-muted px-2 py-0.5 text-xs"
        >
          <Tag className="size-3" />
          {tag}
          <button onClick={onDelete} type="button">
            ×
          </button>
        </span>
      );
    })
  }
/>;

options

An array of preset suggestion strings. When the user types in the input, matching suggestions appear in a dropdown and can be selected by clicking — this adds the suggestion to the value array without pressing Enter.

Only suggestions that contain the typed text (case-insensitive) and are not already selected are shown.

<TextArrayInput
  source="tags"
  options={["react", "typescript", "javascript", "css", "html"]}
/>

Format and Parse

<TextArrayInput
  source="tags"
  format={(v) => v?.map((tag) => tag.toLowerCase())}
  parse={(v) => v?.map((tag) => tag.trim().toLowerCase())}
/>