TagEditor
Tag input with comma-separated entry, duplicate detection, validation, max limit, and typeahead suggestions (static or async). Tags display as removable chips.
import { TagEditor } from "phoundry-ui";Basic
Loading interactive example…
View source
<script lang="ts"> import { TagEditor } from "phoundry-ui";
let basicTags = $state<string[]>(["svelte", "typescript"]);</script>
<TagEditor tags={basicTags} onchange={(t: string[]) => { basicTags = t; }}/>With Suggestions
Loading interactive example…
View source
<script lang="ts"> import { TagEditor } from "phoundry-ui";
let suggestedTags = $state<string[]>(["react"]);
const allSuggestions = [ "svelte", "react", "vue", "angular", "solid", "preact", "lit", "qwik", ];</script>
<TagEditor tags={suggestedTags} onchange={(t: string[]) => { suggestedTags = t; }} suggestions={allSuggestions} placeholder="Type to see suggestions…"/>With Max Tags (4)
Loading interactive example…
View source
<script lang="ts"> import { TagEditor } from "phoundry-ui";
let limitedTags = $state<string[]>(["alpha", "beta"]);</script>
<TagEditor tags={limitedTags} onchange={(t: string[]) => { limitedTags = t; }} maxTags={4}/><p class="mt-2 text-xs text-txt-tertiary">{limitedTags.length} / 4 tags</p>Validation
Loading interactive example…
View source
<script lang="ts"> import { TagEditor } from "phoundry-ui";
let validatedTags = $state<string[]>([]);</script>
<p class="mb-2 text-xs text-txt-secondary"> Return <code>true</code>, <code>false</code>, or a string error message from <code>validate</code>.</p><TagEditor tags={validatedTags} onchange={(t: string[]) => { validatedTags = t; }} validate={(tag: string) => tag.length >= 3 || "Use at least 3 characters"} placeholder="Try “ab” vs “abc”"/>Async suggestions
Loading interactive example…
View source
<script lang="ts"> import { TagEditor } from "phoundry-ui";
let asyncTags = $state<string[]>([]);
const allSuggestions = [ "svelte", "react", "vue", "angular", "solid", "preact", "lit", "qwik", ];</script>
<p class="mb-2 text-xs text-txt-secondary"> The lookup is debounced (~200ms). Errors fall back to an empty suggestion list.</p><TagEditor tags={asyncTags} onchange={(t: string[]) => { asyncTags = t; }} suggestions={async (q: string) => { await new Promise((r) => setTimeout(r, 150)); return allSuggestions.filter((s) => s.toLowerCase().includes(q.trim().toLowerCase()), ); }} placeholder="Type “sv”…"/>Disabled
Loading interactive example…
View source
<script lang="ts"> import { TagEditor } from "phoundry-ui";
let basicTags = $state<string[]>(["svelte", "typescript"]);</script>
<TagEditor tags={basicTags} onchange={() => {}} disabled />API
From phoundry-ui@0.4.21
| Name | Type | Default | Description |
|---|---|---|---|
tagsrequired | string[] | — | Current tags. |
placeholder | string | 'Add tags (comma-separated)…' | Input placeholder text. |
onchangerequired | (tags: string[]) => void | — | Called when tags change. |
onChange | (tags: string[]) => void | Promise<void> | — | Deprecated - use onchange instead. |
disabled | boolean | false | Disable input and remove buttons. |
maxTags | number | — | Maximum number of tags allowed. |
validate | (tag: string) => string | boolean | — | Custom validation - return true, false, or an error message string. |
suggestions | string[] | ((query: string) => Promise<string[]>) | — | Static array or async function for typeahead suggestions. |
class | string | '' | Additional CSS classes. |
Usage tips
- Type a tag and press Enter or click Add. Use commas to add multiple tags at once.
- Backspace on an empty input removes the last tag.
- Duplicates are rejected automatically with an inline validation message.
- Pass an async function to
suggestionsfor server-side typeahead (debounced at 200ms).
CSS styling
.ph-tag-editor is the stable identification hook for TagEditor. Part selectors and --_ph-* properties are internal. Component CSS is scoped and unlayered; Consumer classes remain additive and utility overrides may lose precedence.
Tag validation, limits, callbacks, and suggestion behavior are unchanged. Invalid fields and disabled controls retain their semantic state.
Keep the shared component stylesheet and a named Theme imported. Decorative motion respects reduced-motion preferences.