Skip to content

ChipInput

ChipInput

Basic Usage

Press Enter to add tags

reactsolid

With Transform (Lowercase)

Input is automatically lowercased

With Validation (Email)

Only valid emails are accepted. Try typing an invalid email and pressing Enter.

user@example.com

Custom Add Keys (Comma)

Press Enter or Comma to add

onetwo

Layout Options

Above (default)

chipabove

Below

chipbelow

Left

left

Disabled State

disabledchips
import { ChipInput } from "@f0rbit/ui";
const [tags, setTags] = createSignal<string[]>([]);
<ChipInput
value={tags()}
onChange={setTags}
placeholder="Add a tag..."
/>
PropTypeDefaultDescription
valuestring[]Array of chip values
onChange(value: string[]) => voidCallback when chips change
transform(input: string) => stringTransform input before adding (e.g., lowercase)
validate(input: string, current: string[]) => booleanValidate input before adding
allowDuplicatesbooleanfalseAllow duplicate chip values
addKeysstring[]["Enter"]Keys that trigger adding a chip
placeholderstringPlaceholder text for the input
disabledbooleanfalseDisable the input
errorbooleanfalseShow error styling

Use the transform prop to modify input before adding as a chip:

<ChipInput
value={tags()}
onChange={setTags}
transform={(s) => s.trim().toLowerCase()}
placeholder="Lowercase tags..."
/>

Use the validate prop to control which values can be added:

const isValidEmail = (email: string) =>
/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
<ChipInput
value={emails()}
onChange={setEmails}
validate={(email) => isValidEmail(email)}
placeholder="Add email..."
/>

By default, pressing Enter adds a chip. Use addKeys to customize:

<ChipInput
value={items()}
onChange={setItems}
addKeys={["Enter", ","]}
placeholder="Press Enter or comma..."
/>

By default, duplicate values are prevented. Enable with allowDuplicates:

<ChipInput
value={items()}
onChange={setItems}
allowDuplicates
placeholder="Duplicates allowed..."
/>

Combine with FormField for labels and error messages:

<FormField label="Tags" error={error()}>
<ChipInput
value={tags()}
onChange={setTags}
error={!!error()}
placeholder="Add tags..."
/>
</FormField>
<ChipInput
value={tags()}
onChange={setTags}
transform={(s) => s.trim().toLowerCase()}
placeholder="Add tag..."
/>
<ChipInput
value={emails()}
onChange={setEmails}
validate={(email) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)}
placeholder="Add email address..."
/>
<ChipInput
value={values()}
onChange={setValues}
addKeys={["Enter", ","]}
placeholder="Type values separated by comma..."
/>