Input Chips

Svelte Component

Allows input of multiple values.

Examples

Type a value then hit ENTER to apply it.

This input allows for any value to be entered.

tutorials,news,interviews

Flavors are whitelisted to: vanilla, chocolate, strawberry, peach, rocky road.

vanilla,chocolate,strawberry

Emails are validated to contain @ and . symbols.

john@email.com,jane@email.com,sally@email.com

Usage

Create an array of values, then bind these to your the InputChip component. As values are added or removed the array will update.

ts
let flavors = ['vanilla', 'chocolate', 'strawberry'];
html
<InputChip label="Flavors" placeholder="Add flavor..." bind:value={flavors} />

Whitelist Values

You can provide an array of strings to use as a whitelist. Only whitelisted items can be entered. Invalid or duplicate values will show an error state.

ts
let flavorsWhitelist = ['vanilla', 'chocolate', 'strawberry'];
html
<InputChip ... whitelist={flavorsWhitelist} />

Custom Validation

You can optionally provide a function to provide custom validation. Make sure to accept a string value and return a boolean.

ts
function isValidEmail(value: string): boolean {
	return value.includes('@') && value.includes('.');
}
html
<InputChip ... validation={isValidEmail} />

Additional Settings

By default, only a single instance of each value is allowed. If you wish to allow duplicates, set allowDuplicates=true.

html
<InputChip ... allowDuplicates={true} />

By default, all values are trimmed and formatted lowercase. If you wish to allow uppercase, set allowUpperCase=true.

html
<InputChip ... allowUpperCase={true} />

Required Attribute

Note the required attribute has no bearing on the validation state of this input. Instead, we recommend disabling form submission if your validation conditions are not for our your source value array - such as too few or too many values. Make sure to inform users of the error state using a message or Alert.

html
<button type="submit" disabled={!flavors.length}>Submit</button>
html
<button type="submit" disabled={flavors.length > 3}>Submit</button>

Chip Elements

Interactive elements for actions, selection, or filtering.

Chip Elements →