Tags Input

Display submitted tags one by one.

Preview
Code

Basic Example

<script>
	import { Tags, TagsDelete, TagsInput, TagsItem } from 'lithesome';

	let tags = $state([]);
</script>

<Tags bind:value={tags}>
	<div class="inline-flex flex-wrap gap-1">
		{#each tags as tag}
			<TagsItem value={tag}>
				<span>{tag}</span>
				<TagsDelete value={tag}>X</TagsDelete>
			</TagsItem>
		{/each}
	</div>
	<TagsInput />
</Tags>

API Reference

<Tags />

PropertyTypeDescription
value string[]

The current value.

disabled boolean

Disables the entire group, stops all events from firing.

max number

The maximum allowed of tags.

whitelist string[]

Allow only these strings to be added to the `value` prop.

blacklist string[]

Don't allow these string to be addeed to the `value` prop.

ref E

The reference to the underlying element.

children Snippet<[ S extends Record<string, any> ? S : never ]>

The default snippet to render.

custom Snippet<[ S extends Record<string, any> ? { props: P; state: S; } : { props: P; } ]>

Snippet to be used when wanting a custom implementation. This will tell Lithesome not the render the default element and any state along with it.

StateTypeDescription
activeTagstring | nullThe value if the selected tag via keyboard navigation.
invalidbooleanTrue if: - Input value is less than 1. - Tag already exists. - Tag isn't in the whitelist. - Tag isn't allowed by the blacklist.

<TagsInput />

PropertyTypeDescription
ref E

The reference to the underlying element.

StateTypeDescription
invalidbooleanTrue if: - Input value length is less than 1. - Tag already exists. - Tag isn't in the whitelist. - Tag isn't allowed by the blacklist.

<TagsItem />

PropertyTypeDescription
value string

The value of the tag.

ref E

The reference to the underlying element.

children Snippet<[ S extends Record<string, any> ? S : never ]>

The default snippet to render.

custom Snippet<[ S extends Record<string, any> ? { props: P; state: S; } : { props: P; } ]>

Snippet to be used when wanting a custom implementation. This will tell Lithesome not the render the default element and any state along with it.

StateTypeDescription
activebooleanTrue if selected via keyboard navigation.

<TagsDelete />

PropertyTypeDescription
value string

The value of the item to remove.

ref E

The reference to the underlying element.

children Snippet<[ S extends Record<string, any> ? S : never ]>

The default snippet to render.

custom Snippet<[ S extends Record<string, any> ? { props: P; state: S; } : { props: P; } ]>

Snippet to be used when wanting a custom implementation. This will tell Lithesome not the render the default element and any state along with it.