composer require sadam/livewire-range-slider
npm install nouislider --save-dev
npm run dev
npx livewire-discover
use Sadam\LivewireRangeSlider\LivewireRangeSlider;
// In your Livewire component
public $rangeValue = [20, 80];
public function render()
{
return view('livewire.your-component')->with([
'slider' => LivewireRangeSlider::make('rangeValue')
->min(0)
->max(100)
->step(1),
]);
}
<livewire:your-component />
// Livewire component
public $priceRange = [50, 500];
public function updatedPriceRange($value)
{
$this->filterProductsByPrice($value);
}
<x-livewire-range-slider
wire:model="priceRange"
min="0"
max="1000"
step="50"
label="Price Range ($)"
/>
// Component
public $sliderValue = [10, 90];
public function render()
{
return view('livewire.slider')->with([
'slider' => LivewireRangeSlider::make('sliderValue')
->min(0)
->max(100)
->step(5),
]);
}
// Component
public $singleValue = 50;
public function render()
{
return view('livewire.slider')->with([
'slider' => LivewireRangeSlider::make('singleValue')
->min(0)
->max(100)
->step(1)
->pips(true)
->pipsFormat('n'),
]);
}
// Component
public $dynamicRange = [25, 75];
public $minValue = 0;
public $maxValue = 100;
public function mount()
{
$this->minValue = DB::table('products')->min('price');
$this->maxValue = DB::table('products')->max('price');
}
public function render()
{
return view('livewire.dynamic-slider')->with([
'slider' => LivewireRangeSlider::make('dynamicRange')
->min($this->minValue)
->max($this->maxValue)
->step(10),
]);
}
<div x-data="{ open: false }">
<button @click="open = true">Toggle Slider</button>
<div x-show="open" x-transition>
<livewire:dynamic-slider />
</div>
</div>
protected $listeners = ['refreshSlider' => 'refreshSlider'];
public function refreshSlider()
{
$this->minValue = DB::table('products')->min('price');
$this->maxValue = DB::table('products')->max('price');
$this->emit('sliderUpdated');
}
// Component
public function updatedSliderValue($value)
{
$this->emit('rangeUpdated', $value);
}
<!-- Parent component -->
<div @range-updated.window="handleRangeUpdate">
<livewire:child-slider />
</div>
protected $rules = [
'rangeValue' => 'required|array|min:2|max:2',
'rangeValue.*' => 'integer|min:0|max:100',
];
x-) may interfere with Livewire's reactivity.x-ignore on parent elements or wrap the slider in a div with x-data isolation:
<div x-data="{ /* Alpine state */ }">
<livewire:slider-component />
</div>
step due to floating-point precision.->step(0.5)
public function updatedRangeValue($value)
{
$this->rangeValue = array_map('round', $value, array_fill(0, 2, 2));
}
wire:model syntax changed in Livewire 4.wire:model.live or wire:model.debounce:
<x-livewire-range-slider
wire:model.live="rangeValue"
debounce="500ms"
...
/>
!important sparingly or target the slider's root class:
.nouislider-horizontal .noUi-handle {
background: var(--handle-color) !important;
}
console.log events:
document.addEventListener('update.nouislider', (e) => {
console.log('Slider value:', e.detail);
});
min, max, step) are set. Missing props default to null, causing unexpected behavior.php artisan view:clear
npm run dev
connect:
->connect([
'range' => true,
'format' => ['to' => 'formatWage($value)'],
])
// In a custom Alpine component
formatWage(value) {
return `$${value.toLocaleString()}`;
}
wire:model modifiers to update labels dynamically:
public function updatedRangeValue($value)
{
$this->minLabel = "Min: {$value[0]}";
$this->maxLabel = "Max: {$value[1]}";
}
<div>{{ $minLabel }}</div>
<x-livewire-range-slider wire:model="rangeValue" />
<div>{{ $maxLabel }}</div>
public function updatedRangeValue($value)
{
FilterProductsJob::dispatch($value)->onQueue('filters');
}
wire:model is not set, the slider defaults to [0, 100] if min/max are omitted.step to be defined. Omitting step with pips(true) will throw an error.->keyboardSupport(true)
Tab/Shift+Tab and arrow keys.format to localize values:
->format(['to' => 'formatCurrency', 'from' => 'parseCurrency'])
// In a custom script
function formatCurrency(value) {
return new Intl.NumberFormat('de-DE', {
style: 'currency',
currency: 'EUR'
}).format(value);
}
How can I help you explore Laravel packages today?