<x-widget.slider>
Slider Blade component for Laravel and Livewire
A slider on the native range input, so its keyboard and screen reader support stay: one thumb, or two for a span such as a price range. A prefix or suffix on the value, in the page's number format. Range values submit as name[] and bind with wire:model.
php artisan bladewell:add slider
- 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; no name is needed. One thumb binds a number: public int $volume = 40. A range binds an array, public array $price = [200, 750], each thumb its own end (price.0 and price.1). The slider shows the property after every render, so setting it in PHP moves the thumbs.
<div class="space-y-6">
<x-widget.slider label="Volume" wire:model.live="volume" suffix="%" />
<x-widget.slider label="Price" range wire:model="price" :max="1000" :step="10" prefix="$" />
</div>
Examples
Basic
A native range input underneath: the arrow keys move it a step, Page Up and Down move it further, Home and End jump to the ends. suffix (or prefix) goes on the value shown under the label and on what a screen reader hears.
Show code Hide code
<x-widget.slider name="volume" label="Volume" :value="60" suffix="%" class="max-w-sm" />
Range
range puts two thumbs on one track. They can't cross, and the one moved last stays on top. It submits [from, to] as name[] (here price[]): validate 'price' => ['array', 'size:2'], 'price.*' => ['integer', 'between:0,1000'].
Per night, before taxes.
Show code Hide code
<x-widget.slider name="price" label="Price" range :value="[200, 750]" :min="0" :max="1000" :step="10" prefix="$" info="Per night, before taxes." class="max-w-sm" />
Props
Other attributes, such as autocomplete or data-*, are passed through to the element. class styles the component's outer wrapper.
<x-widget.slider>
| Prop | Default | Description |
|---|---|---|
| name |
null
|
What it submits as; its error and old input are found under it. With range, two values as name[]. 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 slider, and its name for screen readers. |
| value |
null
|
The value, or with range [from, to]. Old input wins after a failed submit; with wire:model and no value, the bound Livewire property. Defaults to min (and max, for range). |
| min |
0
|
The lowest value. |
| max |
100
|
The highest value. |
| step |
1
|
How far one move goes: the arrow keys move a step, and values snap to steps from min. |
| range |
false
|
Two thumbs on one track, for a span such as a price range. Submits [from, to] as name[]. |
| prefix |
''
|
Shown before each value, under the label and to screen readers: "$". |
| suffix |
''
|
Shown after each value: " km", "%". |
| from-label |
'Minimum'
|
With range, the first thumb's name for screen readers, after the field's label: "Price Minimum". |
| to-label |
'Maximum'
|
With range, the second thumb's. |
| 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 slider. |
| 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 moved. With disabled, disabled wins. |
Accessibility
All 2 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 slider writes to your app with the default namespaces. Prefer to copy by hand? Take these files, plus the ones from
Field, and the theme and base CSS.
resources/views/components/widget/slider/index.blade.php Show
resources/js/widget/slider/index.js Show
app/View/Widget/ElementIds.php Show
app/View/Widget/FormField.php Show