Tag input
A field that turns typed text or a picked suggestion into tags; to choose from a long list use zb:combobox.
zb:tag-input zubazar/ui-pro
This component is in Zubazar UI Pro; Zubazar UI Pro brings Zubazar UI with it. Installing Zubazar UI Pro →
Tag input
Type and press Enter or a comma to make a tag; give the initial tags as an array with value.
<zb:tag-input name="tags" label="Tags" :value="['priority', 'wholesale']" />
| Prop | Values |
|---|---|
value | Initial tags (array) |
placeholder | Type and press Enter |
Choosing from a list, with a limit
suggestions allows only the values in the list and max limits the number of tags.
<zb:tag-input name="categories" label="Categories" :suggestions="['Electronics', 'Clothing', 'Books', 'Home & living', 'Sports']" :value="['Electronics']" :max="3" />
| Prop | Values |
|---|---|
suggestions | Allowed values |
max | Maximum number of tags |
Disabled
disabled locks the field; in a classic form no value is sent.
<zb:tag-input name="locked_tags" label="Tags" :value="['priority', 'wholesale']" disabled />
| Prop | Values |
|---|---|
disabled | true | false (default false) |
With Alpine
x-model binds the field two-way to an outside array.
<div x-data="{ tags: ['priority'] }" class="space-y-2">
<zb:tag-input x-model="tags" label="Tags" />
<p class="text-sm text-dim">Tags: <span x-text="tags.join(', ')"></span></p>
</div>
| Prop | Values |
|---|---|
x-model | Array |
class | Added to the outer container |
In a form and with Livewire
In a classic form each tag is sent in a hidden name[] field; wire:model writes the array straight to the Livewire property.
<zb:tag-input wire:model="tags" label="Tags" :suggestions="$tagOptions" required hint="Used in the store search." />
| Prop | Values |
|---|---|
wire:model | Array |
change | When a tag is added or removed (bubbles) |
hint | Shown when there is no error |
required | At least one tag |
Props
The values the component takes. What are props and slots?
| Prop | Type | Default | Description |
|---|---|---|---|
label | — | null | Label above |
value | — | [] | Initial tags |
placeholder | — | Type and press Enter | Text in the empty box |
suggestions | — | [] | If given, only values from this list can be chosen |
max | — | null | Maximum number of tags |
disabled | boolean | false | Turns off typing and removing; hidden fields are not submitted |
hint | — | null | Help text below when there is no error; linked to the text box with aria-describedby |
input-class | — | null | Classes of the text box itself; class places the whole field |
wire:model / x-model | — | — | Livewire or Alpine binding (array); stays on the outer container |
Slots: id goes to the text box, name to the hidden fields. required, autofocus, aria-* and data-* are added to the text box; wire:model, x-model, class, style, x-show, wire:key and events stay on the component's outer container.
Developer notes
- Backspace in an empty box removes the last tag; the same tag is not added twice.
- Up to six suggestions show while typing; they are matched case-insensitively, with Turkish letter rules.
- Adding or removing a tag sends a
changeevent; text typed in the box is not a change. - Hidden fields are added with
wire:modeltoo, sozb:formdirty-checkandzb:form-actionssee tag changes. - A validation error of the list (
tags) or of one tag (tags.*) shows below the box;requiredasks for at least one tag.