WlTagsInput
Change props to see the result: the example and code use the same settings. “Reset” restores the initial values.
Settings
Hint shown when the control has no displayed text.
Name used by the component's native form controls.
Maximum number of tag values accepted in the model.
Allow repeated tag values in the model.
Disable user interaction with this component.
Keep the current value readable while preventing user edits.
Expose a validation error state on the control.
Indicate pending work supplied by the application.
Props separators, validator, variant, size, density, pt, models, handlers and slots can be edited in the SFC. See their descriptions in API.
Example
Editable string tags with validation, duplicate control and form submission.
Explore the live example and copy its Vue SFC into your application. Settings on the left can be combined.
Code for your application
Vue SFC · current settings
<script setup lang="ts">
import { WlButton, WlTagsInput } from "legato-ui";
import { useWlId } from "legato-ui/composables";
import { ref } from "vue";
const tags = ref(["Vue"]);
const rejected = ref("");
const helpId = `tags-example-${useWlId()}`;
</script>
<template>
<div class="wl-stack" data-space="md" data-review-example="WlTagsInput">
<WlTagsInput
v-model="tags"
aria-label="Tags"
:aria-describedby="helpId"
placeholder="Add a tag"
:max="3"
:validator="(value) => value.length >= 2"
:invalid="!!rejected"
@reject="(value) => rejected = value"
@add="rejected = ''"
/>
<p :id="helpId" class="wl-text-small">{{ "Editable string tags with validation, duplicate control and form submission." }}</p>
<p v-if="rejected" role="alert">{{ "Could not add “{value}”. Check length, duplicates and the three-tag limit.".replace("{value}", () => rejected) }}</p>
<WlButton size="sm" @click="tags = ['Vue']; rejected = ''">{{ "Restore example" }}</WlButton>
<output aria-label="Tags">{{ tags.join(", ") }}</output>
</div>
</template>Tags with validation and recovery
Editable string tags with validation, duplicate control and form submission.
Editable string tags with validation, duplicate control and form submission.
Vue SFC · additional example
<script setup lang="ts">
import { WlButton, WlTagsInput } from "legato-ui";
import { useWlId } from "legato-ui/composables";
import { ref } from "vue";
const tags = ref(["Vue"]);
const rejected = ref("");
const helpId = `tags-example-${useWlId()}`;
</script>
<template>
<div class="wl-stack" data-space="md" data-review-example="WlTagsInput">
<WlTagsInput
v-model="tags"
aria-label="Tags"
:aria-describedby="helpId"
placeholder="Add a tag"
:max="3"
:validator="(value) => value.length >= 2"
:invalid="!!rejected"
@reject="(value) => rejected = value"
@add="rejected = ''"
/>
<p :id="helpId" class="wl-text-small">{{ "Editable string tags with validation, duplicate control and form submission." }}</p>
<p v-if="rejected" role="alert">{{ "Could not add “{value}”. Check length, duplicates and the three-tag limit.".replace("{value}", () => rejected) }}</p>
<WlButton size="sm" @click="tags = ['Vue']; rejected = ''">{{ "Restore example" }}</WlButton>
<output aria-label="Tags">{{ tags.join(", ") }}</output>
</div>
</template>Props
Types, accepted values and literal defaults come from the public manifest. Inherited settings name their source; “Not set” means no default is declared.
v-model: string[]
| Prop | Type / values | Default | Purpose |
|---|---|---|---|
placeholder | string | Not set | Hint shown when the control has no displayed text. |
name | string | Not set | Name used by the component's native form controls. |
separators | readonly string[] | [","] | Text delimiters splitting pasted or entered text into tag values. |
validator | (value: string) => boolean | Not set | Application validation predicate for a proposed tag value. |
max | number | Not set | Maximum number of tag values accepted in the model. |
allowDuplicates | boolean | false | Allow repeated tag values in the model. |
disabled | boolean | false | Disable user interaction with this component. |
readonly | boolean | false | Keep the current value readable while preventing user edits. |
invalid | boolean | false | Expose a validation error state on the control. |
loading | boolean | false | Indicate pending work supplied by the application. |
variant | "default" | "default" | Visual treatment within this component family. |
size | WlSizeSm | "md" | Size within the component family's documented scale. |
density | WlDensity | "default" | Spacing density for this component family. |
pt | WlPt< | Not set | Attributes and callbacks for the component's documented pass-through sections. |
Events
| Event | Payload | When emitted |
|---|---|---|
add | [value: string] | Emitted when a valid tag value is added. |
remove | [value: string, | Emitted when the removal action is activated. |
reject | [value: string, | Emitted when a proposed value is rejected, with its reason. |
update:modelValue | string[] | Emitted when the component requests a model change; the payload is the next value. |
Slots
| Slot | Type / values | Content |
|---|---|---|
tag | tag?(props: { value: string; index: number; remove: () => void }): unknown; | Custom tag content with its value, index and removal callback. |
Pass-through: pt
Sections WlTagsInput are listed below. Attributes merge in this order: createWlPt() WlConfig.ptpt instance. Class and style merge; the last supplied value takes priority for other attributes.
| Section | DOM | Purpose |
|---|---|---|
root | div.wl-tags-input | Main element of the component. |
tag | span.wl-tags-input__tag | One selected tag. |
label | span.wl-tags-input__label | Visible component label. |
removeButton | button.wl-tags-input__remove | Button that removes the associated value or file. |
input | input.wl-tags-input__input | Native input that receives focus and control attributes. |
Sections refer to the component DOM. Dotted names identify a configuration group and its section; composite parts use their own pt groups. Global and local attributes merge, with class and style added together.
Keyboard and accessibility
- Name the text input and connect validation feedback through aria-describedby.
- The string-array model remains application-owned. Each remove action includes its tag in the accessible name.
- Enter or a separator adds a valid tag; Backspace removes the last tag only from an empty input. IME composition is preserved.
Keyboard and application responsibilities
| Key | Action |
|---|---|
| Enter / separator | Validate and add the current tag. |
| Backspace | Remove the last tag only when the input is empty. |
| Tab | Focus the input and the named remove actions. |
Provide a meaningful accessible name and connect labels, hints and errors to the focusable element. Check the behavior with your own data and a screen reader.
WAI-ARIA Authoring PracticesChanges are emitted through v-model. After selection, cancellation and reset, labels and states must remain clear.
In your application, check keyboard controls, zoom and focus visibility. State labels and required information must be readable in every theme.