<x-widget.tags>
Tags input Blade component for Laravel and Livewire
Free-text tags in a field: Enter or a comma adds what's typed, a pasted list adds each item, Backspace removes the last, and each tag has its own remove button. Suggestions from the browser's own list, no duplicates in any case, an optional maximum, and a screen reader hears every change. Submits as name[] and works with Livewire wire:model.
php artisan bladewell:add tags
- Also adds
- Icon
- Works with
- Laravel 12 and 13, Livewire 3 and 4, Tailwind CSS 4.1+, PHP 8.3+
Usage
Livewire
In a Livewire component, bind with wire:model (deferred) or wire:model.live to an array property: public array $labels = []. No name is needed. With .live each tag added or removed reaches the server at once. The field shows the property after every render, so setting it in PHP shows the new tags, and its validation errors show under the field.
<x-widget.tags label="Labels" wire:model.live="labels" :suggestions="['urgent', 'billing', 'refund']" />
On the server
The tags input can't stop a request that skips it. Here's what to check on your server, and what to keep cheap.
Security
-
maxand the suggestions only act in the browser: a request can send any number of tags, of any length. Cap both in your Form Request (max:on the array, and on each withtags.*), and drop duplicates in any case.
Server cost
-
If each new tag becomes a row, typos and one-offs pile up and every tag list grows. Consider limiting tags to an allowlist (
Rule::in()orexists:) where the set is known, or tidying unused tags with a scheduled job.
Examples
Basic
Type and press Enter or a comma; paste "red, green, blue" to add all three at once. Backspace in the empty box removes the last tag. The tags submit as name[] (here labels[]), so validate them as an array: 'labels' => ['array', 'max:5'], 'labels.*' => ['string', 'max:30'].
Show code Hide code
<x-widget.tags name="labels" label="Labels" :value="['urgent', 'billing']" class="max-w-md" />
Suggestions
suggestions lists tags the browser offers as people type; any other text can still be added. max caps how many: past it, typing more is refused and a screen reader hears why.
Up to five.
Show code Hide code
<x-widget.tags name="skills" label="Skills" placeholder="Add a skill" :suggestions="['Laravel', 'Livewire', 'Tailwind CSS', 'PHP', 'JavaScript', 'MySQL', 'Redis']" :max="5" info="Up to five." class="max-w-md" />
Props
Other attributes, such as autocomplete or data-*, are passed through to the element. class styles the component's outer wrapper.
<x-widget.tags>
| Prop | Default | Description |
|---|---|---|
| name |
null
|
What the tags submit as (name[]); their error and old input are found under it. Optional with wire:model, which then names it. |
| id |
null
|
Defaults to one made from the name (or the wire:model property). |
| label |
null
|
Shown above the field, and its name for screen readers. |
| value |
null
|
The tags to start with. Old input wins after a failed submit; with wire:model and no value, the bound property. |
| placeholder |
'Add a tag'
|
Shown in the box while there are no tags and nothing is typed. |
| suggestions |
[]
|
Tags to suggest as people type (the browser's own list). Any other text can still be added. |
| max |
null
|
How many tags it takes at most. Past that, typing more is refused and said so. |
| error |
null
|
An error message of your own; otherwise the validation error for the name, from the session or Livewire. |
| info |
null
|
A hint under the field. |
| required-message |
'Add at least one tag.'
|
Said, in the field's own error style, when a required tags field is submitted empty. |
| bag |
'default'
|
Which error bag to read the error from. |
| disabled |
false
|
Greyed out: it can't be changed. |
| readonly |
false
|
Shown, and submitted, but it can't be changed: no typing, and no remove buttons. With disabled, disabled wins. |
| layout |
'inline'
|
Where the tags show: inline, in the box before the text; or below, as cards under a one-line box, for a long list. |
Accessibility
All 3 examples above are checked with axe-core against the WCAG 2.2 A and AA rules, in the light theme and the dark one, both as the page draws and with each popover, dialog, toast and tooltip opened, on every change. A change that fails can't be merged. Where axe can't decide, such as contrast on SVG text, the test measures the colours itself instead of letting it pass.
Automated checks can't judge everything: how it sounds in a screen reader, and how it feels to use from the keyboard, still need a person. Check those on your own pages too.
Source
What bladewell:add tags writes to your app with the default namespaces. Prefer to copy by hand? Take these files, plus the ones from
the components it also adds and Field, and the theme and base CSS.
resources/views/components/widget/tags/index.blade.php Show
resources/js/widget/tags/index.js Show
app/View/Widget/ElementIds.php Show
app/View/Widget/FormField.php Show