GhostTagsInput
Use GhostTagsInput to enter and remove a small collection of strings. The themed component comes from @ghostvue/themes. Import the headless component from @ghostvue/vue to supply your own styling.
Save project labels
Add and remove labels, submit committed tags, and reset the form.
<script setup lang="ts">
import { ref } from 'vue'
import {
GhostButton,
GhostField,
GhostFieldControl,
GhostFieldDescription,
GhostFieldLabel,
GhostTagsInput,
} from '@ghostvue/themes'
const initialLabels = ['frontend']
const labels = ref<string[]>([...initialLabels])
const saved = ref<string[] | null>(null)
function save(event: SubmitEvent): void {
if (!(event.target instanceof HTMLFormElement)) return
saved.value = new FormData(event.target).getAll('labels').map(String)
}
</script>
<template>
<form class="project-labels" @submit.prevent="save">
<GhostField required>
<GhostFieldLabel>Project labels</GhostFieldLabel>
<GhostFieldDescription>
Press Enter to add a label. Press Backspace on the empty entry to focus
the last label's remove button.
</GhostFieldDescription>
<GhostFieldControl v-slot="field">
<GhostTagsInput
v-bind="field"
v-model="labels"
:default-value="initialLabels"
name="labels"
placeholder="Add a label"
/>
</GhostFieldControl>
</GhostField>
<div class="project-label-actions">
<GhostButton type="submit">Save project</GhostButton>
<GhostButton type="reset">Reset labels</GhostButton>
</div>
<p v-if="saved">Saved labels: {{ saved.join(', ') }}</p>
</form>
</template>
<style scoped>
.project-labels,
.project-label-actions {
display: flex;
gap: var(--ghost-space-gap-sm);
}
.project-labels {
flex-direction: column;
inline-size: min(100%, 28rem);
}
.project-label-actions {
flex-wrap: wrap;
}
</style>
Type urgent, press Enter, then select Save project. new FormData(form).getAll('labels') returns ['frontend', 'urgent']. An unfinished draft stays visible when you leave the field and is excluded from submission. Reset labels clears the draft and requests the initial tags again. An editable required field with zero committed tags blocks native submission even if its draft contains text.
Add several tags
Add comma-separated tags to a labelled headless field.
Press Enter, or paste a comma-separated list to add several skills.
- Vue
<script setup lang="ts">
import {
GhostField,
GhostFieldControl,
GhostFieldDescription,
GhostFieldLabel,
GhostTagsInput,
} from '@ghostvue/vue'
const initial: readonly string[] = ['Vue']
</script>
<template>
<GhostField>
<GhostFieldLabel>Skills</GhostFieldLabel>
<GhostFieldDescription>
Press Enter, or paste a comma-separated list to add several skills.
</GhostFieldDescription>
<GhostFieldControl v-slot="field">
<GhostTagsInput
v-bind="field"
:default-value="initial"
:delimiters="[',']"
>
<template #tag="{ value }"
><strong>{{ value }}</strong></template
>
</GhostTagsInput>
</GhostFieldControl>
</GhostField>
</template>
The default commits only with Enter. Configure :delimiters="[',', ';']" to commit with those keys at the end of the entry or split pasted text. Trimmed, case-sensitive duplicates are skipped. Paste adds all new tags in one update. The tag slot can format the displayed string. Keep its contents non-interactive so the built-in remove button handles activation and focus.
Show imported tags
Display submitted tags in a read-only field.
- frontend
- triage
<script setup lang="ts">
import { useId } from 'vue'
import { GhostTagsInput } from '@ghostvue/themes'
const id = useId()
const labels: readonly string[] = ['frontend', 'triage']
</script>
<template>
<label :for="id">Imported labels</label>
<GhostTagsInput :id="id" :model-value="labels" readonly name="labels" />
</template>
Read-only fields keep the text entry focusable and include committed tags in the form. Disabled fields skip focus, editing, and submission. The nearest native disabled fieldset applies the same rules, including the first legend exception.
Keyboard and focus
Tab enters the text input. On an empty entry, Backspace or the arrow toward the tags focuses the last remove button. Use Left and Right (reversed in RTL) to move through the buttons and back to the input. On a button, Home goes to the first tag and End returns to the input. Enter, Space, Backspace, or Delete removes the focused tag. Focus goes to the next tag, then the previous tag or the entry when there are no tags left. Tab and Shift+Tab leave the widget. Escape, Up, and Down retain their native behavior.
Forms, labels, and localization
- Pass
id,form, input attributes such asplaceholder, andaria-*to the native text entry. Theformattribute also sets the owner of the hidden inputs. Class and style apply to the root. Give the entry a visible label, for example through GhostField. - Use
v-modelfor controlled tags and replace the array when updating it. The component emits one fresh proposal per action. The current parent value determines which tags render and submit. PassdefaultValueto set the captured reset baseline in either mode. - Use
messagesto localize remove-button names, accepted additions, removals, duplicates, and the required validation message. Overrides can change while the field is mounted. - Style the
root,list,tag,remove,input, andstatusparts. The root exposesdata-disabled,data-readonly, anddata-invalid.
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
defaultValue | readonly string[] | "[]" | Initial uncontrolled tags and reset baseline. |
delimiters | readonly (',' | ';')[] | "[]" | Optional typed and pasted separators. |
disabled | boolean | false | Disables editing, focus and submission. |
invalid | boolean | false | Consumer-owned invalid state. |
messages | Partial<GhostTagsInputMessages> | — | Localized button, announcement and validation text. |
modelValue | readonly string[] | — | Controlled committed tags. |
name | string | — | Repeated native form field name. |
readonly | boolean | false | Prevents edits while preserving focus and submission. |
required | boolean | false | Requires a committed tag while editable. |
| Slot | Slot props | Description |
|---|---|---|
tag | value: string | Formats tag text while the component retains its remove control. |
@ghostvue/themes adds no props, events, or slots to the headless GhostTagsInput API, which it forwards.
See the approved behavior specification.