SutraUI.Slider (Sutra UI v0.2.0)
View SourceAn input where the user selects a value from within a given range.
Uses a native <input type="range"> element with custom styling and
a colocated JavaScript hook to update the visual progress indicator.
Value Types
The slider automatically determines whether to emit integer or float values
based on the step attribute:
- Integer step (e.g.,
step={1},step={5}) → emits integers - Float step (e.g.,
step={0.1},step={0.5}) → emits floats with matching precision
Examples
# Basic slider (integer mode)
<.slider id="volume-slider" min={0} max={100} value={50} />
# With label
<label for="volume-slider">Volume</label>
<.slider id="volume-slider" min={0} max={100} value={50} name="volume" />
# Float mode - step determines precision
<.slider
id="temperature-slider"
min={-10}
max={40}
step={0.5}
value={20.5}
name="temperature"
aria-label="Temperature in Celsius"
/>
# High precision floats
<.slider id="weight" min={0} max={10} step={0.01} value={5.25} />
# Disabled slider
<.slider
id="brightness-slider"
min={0}
max={100}
value={75}
disabled
/>
# With value text for screen readers
<.slider
id="progress-slider"
min={0}
max={100}
value={75}
aria-valuetext="75 percent complete"
/>Accessibility
- Uses semantic
<input type="range">element - Supports
aria-labeloraria-labelledbyfor labeling - Supports
aria-valuemin,aria-valuemax,aria-valuenow,aria-valuetext - Keyboard accessible (Arrow keys, Home, End, Page Up, Page Down)
- Announces value changes to screen readers
Colocated Hook
This component includes a colocated JavaScript hook (.Slider) that updates:
- The visual progress indicator via CSS custom property
--slider-value - The
aria-valuenowattribute as the value changes
The hook is automatically available when you import colocated hooks via
import { hooks as sutraUiHooks } from "phoenix-colocated/sutra_ui" in your app.js.
Summary
Functions
Renders a slider component.
Functions
Renders a slider component.
Attributes
id- Unique identifier for the slider (required for hook)min- Minimum value (default: 0)max- Maximum value (default: 100)step- Step increment (default: 1). Integer step = integer values, float step = float values.value- Current value (default: 50)name- Form input namedisabled- Whether the slider is disabledclass- Additional CSS classes
Attributes
id(:string) (required) - Unique identifier for the slider (required for hook).min(:any) - Minimum value (integer or float). Defaults to0.max(:any) - Maximum value (integer or float). Defaults to100.step(:any) - Step increment. Integer = integer mode, float = float mode. Defaults to1.value(:any) - Current value. Defaults to50.name(:string) - Form input name. Defaults tonil.disabled(:boolean) - Whether the slider is disabled. Defaults tofalse.class(:string) - Additional CSS classes. Defaults tonil.- Global attributes are accepted. Additional HTML attributes including ARIA. Supports all globals plus:
["form", "phx-change", "phx-blur", "phx-focus", "aria-label", "aria-labelledby", "aria-describedby", "aria-valuetext", "aria-invalid", "min", "max", "step"].