Skip to content

Slider ​

The Slider field renders a range slider for numeric input. It supports single values, a range mode with two thumbs, custom marks, units, and a vertical orientation.

Basic Usage ​

By default, the slider runs from 0 to 100 with a step of 1. The current value appears beside a visible field label, or above the track when the label is hidden:

Example
64
php
use InertiaUI\Forms\Fields\Slider;

Slider::make('volume');

Min, Max, and Step ​

To change the bounds and the increment, you may use the min, max, and step methods:

Example
450
php
Slider::make('price')
    ->min(0)
    ->max(1000)
    ->step(50);

The min and max methods add numeric bounds for scalar slider submissions. Bounded sliders also receive the numeric rule, unless you already added a numeric, integer, or decimal: rule. See Slider Validation for the generated rules.

Range Mode ​

The range method adds a second thumb for selecting a range. The field stores the value as an array, [min, max]. The range method adds the array, list, and size:2 validation rules, verifies that the values are in order, and validates each item as numeric within the configured minimum and maximum:

Example
125350
php
Slider::make('price_range')
    ->range()
    ->min(0)
    ->max(500);

Minimum Steps Between Thumbs ​

To keep the two thumbs from getting too close to each other, use the minStepsBetween method:

Example
2570
php
Slider::make('price_range')
    ->range()
    ->min(0)
    ->max(100)
    ->step(5)
    ->minStepsBetween(2); // At least 10 apart (2 steps * 5)

The slider UI and backend validation both enforce this gap.

Value Display ​

The slider shows its current value by default. To hide it, call the hideValue method:

Example
72
php
Slider::make('brightness');

Slider::make('contrast')->hideValue();

Passing false to the showValue method is equivalent:

php
Slider::make('contrast')->showValue(false);

Min/Max Labels ​

The showMinMax method shows the minimum and maximum values at the ends of the slider:

Example
64
0100
php
Slider::make('volume')
    ->min(0)
    ->max(100)
    ->showMinMax();

Units ​

The unit method adds a unit label to the displayed value. By default, the unit appears as a suffix:

Example
22°C
$500
php
Slider::make('temperature')
    ->min(-20)
    ->max(50)
    ->unit('°C');

To show the unit as a prefix, pass the position argument:

php
Slider::make('budget')
    ->min(0)
    ->max(10000)
    ->step(100)
    ->unit('$', 'prefix');

You may also set the position separately using the unitPosition method:

php
Slider::make('budget')
    ->unit('EUR')
    ->unitPosition('prefix');

The default 'suffix' position renders the unit after the value, like 50°C. The 'prefix' position renders it before the value, like $500.

Marks ​

The marks method adds labeled tick marks along the slider track:

Example
75
Poor
Fair
Good
Great
Excellent
php
Slider::make('rating')->marks([
    0 => 'Poor',
    25 => 'Fair',
    50 => 'Good',
    75 => 'Great',
    100 => 'Excellent',
]);

The PHP marks method accepts either an array keyed by slider value or the normalized array that direct components use:

php
Slider::make('rating')->marks([
    ['value' => 0, 'label' => 'Poor'],
    ['value' => 50, 'label' => 'Good'],
    ['value' => 100], // Unlabeled tick
]);

PHP normalizes keyed maps to { value, label } records and throws an InvalidArgumentException for non-numeric mark values. Direct Vue and React component props use the normalized array shape.

Orientation and Interaction ​

These methods change the orientation of the slider and how the user interacts with it.

Vertical Orientation ​

The vertical method renders the slider vertically. You'll usually want to set a height in pixels as well:

Example
64
php
Slider::make('volume')
    ->vertical()
    ->height(200); // pixels

The vertical orientation also supports range mode, and it keeps both native thumbs available for keyboard interaction and form submission.

Lazy Updates ​

By default, the value updates on every input event while the thumb moves. To update the value only when the user releases the thumb, use the lazy method:

php
Slider::make('quality')->lazy();

This helps when the slider value triggers expensive computations or network requests.

Jump Step ​

Keyboard users may make small or large adjustments. ArrowRight and ArrowUp add one step, while ArrowLeft and ArrowDown subtract one step. Holding Shift with an arrow key uses the larger jump increment. PageUp and PageDown always use the jump increment.

Without a custom jump value, the frontend uses step * 10, so with the default step(1), Shift+Arrow and PageUp or PageDown move by 10. To use a different keyboard increment, pass the jump argument to the step method:

php
Slider::make('opacity')
    ->min(0)
    ->max(100)
    ->step(1, jump: 10); // Shift+Arrow moves by 10

For direct component rendering, pass the frontend prop as jumpStep in React or jump-step in Vue templates.

Readonly ​

The Slider field doesn't currently support a readonly state, because native range inputs don't have a readonly mode. Use the disabled method when users should see the value but not change it.

Budget Range Slider ​

The following field combines range mode with units, labels, and marks:

php
Slider::make('budget')
    ->label('Monthly Budget')
    ->help('Drag to set your budget range')
    ->range()
    ->min(0)
    ->max(5000)
    ->step(100)
    ->unit('$', 'prefix')
    ->showMinMax()
    ->minStepsBetween(2)
    ->marks([
        0 => 'Free',
        2500 => 'Mid',
        5000 => 'Max',
    ])
    ->required();

Shared Field APIs ​

The slider methods work together with the shared field APIs:

Using the Component Directly ​

Each package exports the Slider component from its components subpath. You may use it for standalone numeric input or while rendering forms manually:

vue
<script setup lang="ts">
import { Slider } from '@inertiaui/form-vue/components'
import { shallowRef } from 'vue'

const comfortRange = shallowRef<[number, number]>([18, 24])
const temperatureMarks = [
    { value: 16, label: 'Cool' },
    { value: 22, label: 'Comfort' },
    { value: 30, label: 'Warm' },
]
</script>

<template>
    <Slider
        v-model="comfortRange"
        id="comfort-range"
        name="comfort_range"
        label="Comfort range"
        help="Set the preferred room temperature."
        range
        :min="16"
        :max="30"
        :step="1"
        :jump-step="2"
        unit="°C"
        unit-position="suffix"
        :marks="temperatureMarks"
        show-value
        show-min-max
        vertical
        :height="220"
        lazy
        :min-steps-between="2"
        data-testid="comfort-range"
    />
</template>
tsx
import { useState } from 'react'
import { Slider } from '@inertiaui/form-react/components'

const temperatureMarks = [
    { value: 16, label: 'Cool' },
    { value: 22, label: 'Comfort' },
    { value: 30, label: 'Warm' },
]

export default function ComfortRangeSlider() {
    const [comfortRange, setComfortRange] = useState<number | [number, number]>([18, 24])

    return (
        <Slider
            value={comfortRange}
            onValueChange={setComfortRange}
            id="comfort-range"
            name="comfort_range"
            label="Comfort range"
            help="Set the preferred room temperature."
            range
            min={16}
            max={30}
            step={1}
            jumpStep={2}
            unit="°C"
            unitPosition="suffix"
            marks={temperatureMarks}
            showValue
            showMinMax
            vertical
            height={220}
            lazy
            minStepsBetween={2}
            data-testid="comfort-range"
        />
    )
}

Native attributes and listeners target the underlying native element. See Native Attributes And Events.