Controls

Slider

Select a value from a range by dragging.

Rust
1use herogpui::components::slider::Slider;

Usage

Labels and values use 14px text with a 20px line height, independent of the surrounding text style.

Rust
1use herogpui::prelude::Slider;
2use gpui::prelude::*;
3use gpui::px;
4
5gpui::div()
6    .w(px(320.))
7    .child(
8        Slider::new("slider-main", 30.)
9            .default_value(30.)
10            .label("Volume")
11            .show_value(true),
12    )

Live HeroGPUI compiled to WebAssembly. Select any example without loading another WASM instance.

Anatomy

Rust types

Slider

Slider is assembled from these builders. The API reference lists each one.

Customization

Appearance builders and theme tokens Slider uses.

Styling

Slider styling
StyleDescription
Slider::render flex_col + gap(px(4.))Root layout with label and output above the track.
Slider::render text_size(px(14.)) + line_height(px(20.)) + FontWeight::MEDIUMLabel and output typography.
20px default-color track + small_radius + axis_inset(12px) + fill_start/fill_end capsTwenty-pixel track with transparent 12px end borders for the thumb overhang; fill caps paint those ends accent when the fill reaches them.
absolute accent fill from fill_from to fill_toAccent span representing the selected interval.
28x20 / 20x28 outer + 24x16 / 16x24 innerAccent outer handle with accent-foreground inner handle.
DragState inner geometry scale; instant under gpuiDragging feedback and reduced-motion override.
util::ring_if_focusedKeyboard focus treatment.
layout.disabled_opacityWhole-slider disabled treatment.

API reference

Builders

Slider builders
BuilderTypeDefaultDescription
value(f32) / values(values)f32 / valuesThe current value or values (controlled).
default_value(f32) / default_values(values)f32 / valuesThe initial value or values (uncontrolled).
on_change(callback) / on_change_all(callback)Fn(value: number | number[]) -> ()Handler called whenever a thumb changes value.
on_change_end(callback) / on_change_end_all(callback)Fn(value: number | number[]) -> ()Handler called once when a drag or keyboard step completes.
min_value(f32)f320The minimum value.
max_value(f32)f32100The maximum value.
step(f32)f321The increment between valid values.
format_options(NumberFormat)NumberFormatFormats the displayed value; supports decimal, percent and currency without CLDR locale data.
orientation(Orientation)OrientationOrientation::HorizontalThe direction in which values increase.
is_disabled(bool)boolDisables every thumb and removes the slider from the tab order.
label(value)AnyElement | render closureCompound slider content; the monolithic port exposes its label, output and thumb customizations as builders.
output(render)AnyElement | render closureCustom output content handed every live value and its formatted thumb label.
thumb(render)AnyElement | render closureTrack content; the thumb closure receives each computed index and value.
disabled_keys(indices)boolDisables this thumb only and removes its form field and tab stop.
thumb_names(names)namesName of this thumb's submitted form value.

Parts

Slider parts
PartDescription
SliderRoot value, form, pointer and keyboard state owner.
SliderOptional text label rendered above or beside the track.
SliderFormatted current values or custom content rendered from the live value array.
SliderPointer and keyboard surface containing fill and thumbs.
SliderAccent span from the minimum or between the outermost thumbs.
SliderOne draggable, focusable value handle per value.

States

Slider states
BuilderStateDescription
Orientation::HorizontalHorizontalValues increase from left to right.
Orientation::VerticalVerticalValues increase from bottom to top.
ring_if_focused + active_thumbFocus visibleThe active enabled thumb carries the keyboard focus ring.
DragStateDraggingPointer drag state updates the value and scales the inner thumb to 90%; gpui applies the scale without CSS's 250ms ramp.
Slider::is_disabledDisabled sliderAll thumbs are inert, dimmed and removed from form submission and tab order.
Slider::disabled_keysDisabled thumbOne thumb is inert and omitted while its siblings remain interactive.
fill_from == 0Fill startThe accent fill reaches the low edge.
fill_to == 1Fill endThe accent fill reaches the high edge.