v0.0.2
Demos (demo panel, opens in a new tab)

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

PRO

This component is in Zubazar UI Pro; Zubazar UI Pro brings Zubazar UI with it. Installing Zubazar UI Pro →

Tag input

Tag input: view
BLADE

Type and press Enter or a comma to make a tag; give the initial tags as an array with value.

blade
<zb:tag-input name="tags" label="Tags" :value="['priority', 'wholesale']" />
PropValues
valueInitial tags (array)
placeholderType and press Enter

Choosing from a list, with a limit

Choosing from a list, with a limit: view
BLADE

suggestions allows only the values in the list and max limits the number of tags.

blade
<zb:tag-input name="categories" label="Categories" :suggestions="['Electronics', 'Clothing', 'Books', 'Home & living', 'Sports']" :value="['Electronics']" :max="3" />
PropValues
suggestionsAllowed values
maxMaximum number of tags

Disabled

Disabled: view
BLADE

disabled locks the field; in a classic form no value is sent.

blade
<zb:tag-input name="locked_tags" label="Tags" :value="['priority', 'wholesale']" disabled />
PropValues
disabledtrue | false (default false)

With Alpine

With Alpine: view
BLADE

x-model binds the field two-way to an outside array.

blade
<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>
PropValues
x-modelArray
classAdded to the outer container

In a form and with Livewire

BLADE

In a classic form each tag is sent in a hidden name[] field; wire:model writes the array straight to the Livewire property.

blade
<zb:tag-input wire:model="tags" label="Tags" :suggestions="$tagOptions" required hint="Used in the store search." />
PropValues
wire:modelArray
changeWhen a tag is added or removed (bubbles)
hintShown when there is no error
requiredAt least one tag

Props

The values the component takes. What are props and slots?

PropTypeDefaultDescription
label—nullLabel above
value—[]Initial tags
placeholder—Type and press EnterText in the empty box
suggestions—[]If given, only values from this list can be chosen
max—nullMaximum number of tags
disabledbooleanfalseTurns off typing and removing; hidden fields are not submitted
hint—nullHelp text below when there is no error; linked to the text box with aria-describedby
input-class—nullClasses 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

Events, hooks and details
  • 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 change event; text typed in the box is not a change.
  • Hidden fields are added with wire:model too, so zb:form dirty-check and zb:form-actions see tag changes.
  • A validation error of the list (tags) or of one tag (tags.*) shows below the box; required asks for at least one tag.
Zubazar UI · ZubazarDesigned for people.