Slider
A draggable control for picking a value from a range.
This demo runs the real GPUI component on WebGPU, which this browser does not expose.
Try Chrome or Edge 113+, or Safari 26+. In Firefox, enable dom.webgpu.enabled.
You can also run it natively: cargo run -p showcase slider
The demo failed to start in this browser.
You can run it natively instead: cargo run -p showcase slider
Live examples are not supported on most mobile browsers yet — open this page on a desktop or tablet to run the demo.
Recent phones with WebGPU may manage it (downloads ~18 MB):
#Anatomy
Import the component's parts and compose them under its root:
use base_gpui::slider::{
SliderControl,
SliderIndicator,
SliderLabel,
SliderRoot,
SliderThumb,
SliderTrack,
SliderValue,
};
SliderRoot::new()
.child(
SliderControl::new()
.child(
SliderThumb::new(),
)
.child(
SliderTrack::new()
.child(
SliderIndicator::new(),
),
),
)
.child(
SliderLabel::new(),
)
.child(
SliderValue::new(),
);
The anatomy is a structural overview. Parts with mutually exclusive modes may need separate instances; each part's section below documents its configuration.
#SliderRoot
Coordinates the component's state and supplies context to its child parts.
use base_gpui::slider::SliderRoot;
SliderRoot::new()
.with_field_context(/* context: FieldContext */)
.id("example-id")
.name("name")
.default_value(/* default_value: SliderValues */)
.value(/* value: SliderValues */)
.min(0.0)
.max(0.0)
.step(0.0)
.large_step(0.0)
.min_steps_between_values(0.0)
.orientation(/* orientation: SliderOrientation */)
.thumb_collision_behavior(/* behavior: SliderThumbCollisionBehavior */)
.thumb_alignment(/* thumb_alignment: SliderThumbAlignment */)
.disabled(true)
.aria_label("aria label")
.format(0.0)
.on_value_change(|/* callback arguments */| { /* handle change */ })
.on_value_committed(|/* callback arguments */| { /* handle change */ })
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a SliderRoot with its default configuration. |
.with_field_context | pub fn with_field_context(mut self, context: FieldContext) -> Self
Sets the with field context configuration for this part. |
.child | pub fn child(mut self, child: impl Into<SliderChild>) -> Self
Adds one typed child to this part. |
.children | pub fn children(mut self, children: impl IntoIterator<Item = impl Into<SliderChild>>) -> Self
Adds multiple typed children in iteration order. |
.child_any | pub fn child_any(mut self, child: impl IntoElement) -> Self
Adds one arbitrary renderable child to this part. |
.id | pub fn id(mut self, id: impl Into<ElementId>) -> Self
Sets the stable GPUI element identity. Use a unique value when multiple instances can appear in the same view. |
.name | pub fn name(mut self, name: impl Into<SharedString>) -> Self
Sets the form field name used when serializing or submitting the value. |
.default_value | pub fn default_value(mut self, default_value: SliderValues) -> Self
Sets the initial value for uncontrolled state. Later user changes are retained by the component. |
.value | pub fn value(mut self, value: SliderValues) -> Self
Sets the current controlled value or the value represented by this part, depending on the part's role. |
.min | pub fn min(mut self, min: f64) -> Self
Sets the min configuration for this part. |
.max | pub fn max(mut self, max: f64) -> Self
Sets the max configuration for this part. |
.step | pub fn step(mut self, step: f64) -> Self
Sets the step configuration for this part. |
.large_step | pub fn large_step(mut self, large_step: f64) -> Self
Sets the large step configuration for this part. |
.min_steps_between_values | pub fn min_steps_between_values(mut self, min_steps_between_values: f64) -> Self
Sets the min steps between values configuration for this part. |
.orientation | pub fn orientation(mut self, orientation: SliderOrientation) -> Self
Sets the component's horizontal or vertical orientation and corresponding keyboard behavior. |
.thumb_collision_behavior | pub fn thumb_collision_behavior(mut self, behavior: SliderThumbCollisionBehavior) -> Self
Sets the thumb collision behavior configuration for this part. |
.thumb_alignment | pub fn thumb_alignment(mut self, thumb_alignment: SliderThumbAlignment) -> Self
Sets the thumb alignment configuration for this part. |
.disabled | pub fn disabled(mut self, disabled: bool) -> Self
When true, prevents user interaction with this part. |
.aria_label | pub fn aria_label(mut self, aria_label: impl Into<SharedString>) -> Self
Accessible label for the slider group, mirroring what |
.format | pub fn format(mut self, format: impl Fn(f64) -> SharedString + 'static) -> Self
Sets the format configuration for this part. |
.on_value_change | pub fn on_value_change(mut self, on_value_change: impl Fn(SliderValues, &mut SliderValueChangeDetails, &mut Window, &mut App) + 'static,) -> Self
Registers a callback invoked when value change occurs. |
.on_value_committed | pub fn on_value_committed(mut self, on_value_committed: impl Fn(SliderValues, SliderValueCommitDetails, &mut Window, &mut App) + 'static,) -> Self
Registers a callback invoked when value committed occurs. |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(SliderRootStyleState, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. SliderRoot also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#SliderControl
Public renderable part of the Slider Control component.
use base_gpui::slider::SliderControl;
SliderControl::new()
.with_slider_context(/* context: SliderContext */)
.map_children(/* map: impl FnOnce(Vec<SliderControlChild>) -> Vec<SliderControlChild>, */)
.id("example-id")
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a SliderControl with its default configuration. |
.with_slider_context | pub fn with_slider_context(mut self, context: SliderContext) -> Self
Sets the with slider context configuration for this part. |
.map_children | pub fn map_children(mut self, map: impl FnOnce(Vec<SliderControlChild>) -> Vec<SliderControlChild>,) -> Self
Sets the map children configuration for this part. |
.id | pub fn id(mut self, id: impl Into<ElementId>) -> Self
Sets the stable GPUI element identity. Use a unique value when multiple instances can appear in the same view. |
.child | pub fn child(mut self, child: impl Into<SliderControlChild>) -> Self
Adds one typed child to this part. |
.children | pub fn children(mut self, children: impl IntoIterator<Item = impl Into<SliderControlChild>>,) -> Self
Adds multiple typed children in iteration order. |
.child_any | pub fn child_any(mut self, child: impl IntoElement) -> Self
Adds one arbitrary renderable child to this part. |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(SliderControlStyleState, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. SliderControl also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#SliderIndicator
Visual representation of the component's current state or value.
use base_gpui::slider::SliderIndicator;
SliderIndicator::new()
.with_slider_context(/* context: SliderContext */)
.id("example-id")
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a SliderIndicator with its default configuration. |
.with_slider_context | pub fn with_slider_context(mut self, context: SliderContext) -> Self
Sets the with slider context configuration for this part. |
.id | pub fn id(mut self, id: impl Into<ElementId>) -> Self
Sets the stable GPUI element identity. Use a unique value when multiple instances can appear in the same view. |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(SliderIndicatorStyleState, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. SliderIndicator also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#SliderLabel
Provides a visible label and associated accessibility semantics.
use base_gpui::slider::SliderLabel;
SliderLabel::new()
.with_slider_context(/* context: SliderContext */)
.id("example-id")
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a SliderLabel with its default configuration. |
.with_slider_context | pub fn with_slider_context(mut self, context: SliderContext) -> Self
Sets the with slider context configuration for this part. |
.id | pub fn id(mut self, id: impl Into<ElementId>) -> Self
Sets the stable GPUI element identity. Use a unique value when multiple instances can appear in the same view. |
.child | pub fn child(mut self, child: impl IntoElement) -> Self
Base UI links this label to the root via |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(SliderLabelStyleState, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. SliderLabel also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#SliderThumb
Interactive or visual handle representing the current value.
use base_gpui::slider::SliderThumb;
SliderThumb::new()
.with_slider_context(/* context: SliderContext */)
.with_thumb_index(0)
.thumb_index()
.thumb_disabled()
.id("example-id")
.disabled(true)
.aria_label("aria label")
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a SliderThumb with its default configuration. |
.with_slider_context | pub fn with_slider_context(mut self, context: SliderContext) -> Self
Sets the with slider context configuration for this part. |
.with_thumb_index | pub fn with_thumb_index(mut self, index: usize) -> Self
Sets the with thumb index configuration for this part. |
.thumb_index | pub fn thumb_index(&self) -> Option<usize>Sets the thumb index configuration for this part. |
.thumb_disabled | pub fn thumb_disabled(&self) -> boolSets the thumb disabled configuration for this part. |
.id | pub fn id(mut self, id: impl Into<ElementId>) -> Self
Sets the stable GPUI element identity. Use a unique value when multiple instances can appear in the same view. |
.disabled | pub fn disabled(mut self, disabled: bool) -> Self
When true, prevents user interaction with this part. |
.aria_label | pub fn aria_label(mut self, aria_label: impl Into<SharedString>) -> Self
Accessible label for this thumb (e.g. "Minimum" / "Maximum" on a range slider). A plain string per thumb replaces Base UI's optional |
.child | pub fn child(mut self, child: impl IntoElement) -> Self
Adds one typed child to this part. |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(SliderThumbStyleState, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. SliderThumb also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#SliderTrack
Visual track containing the component's indicator or thumb.
use base_gpui::slider::SliderTrack;
SliderTrack::new()
.with_slider_context(/* context: SliderContext */)
.map_children(/* map: impl FnOnce(Vec<SliderTrackChild>) -> Vec<SliderTrackChild>, */)
.id("example-id")
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a SliderTrack with its default configuration. |
.with_slider_context | pub fn with_slider_context(mut self, context: SliderContext) -> Self
Sets the with slider context configuration for this part. |
.map_children | pub fn map_children(mut self, map: impl FnOnce(Vec<SliderTrackChild>) -> Vec<SliderTrackChild>,) -> Self
Sets the map children configuration for this part. |
.id | pub fn id(mut self, id: impl Into<ElementId>) -> Self
Sets the stable GPUI element identity. Use a unique value when multiple instances can appear in the same view. |
.child | pub fn child(mut self, child: impl Into<SliderTrackChild>) -> Self
Adds one typed child to this part. |
.children | pub fn children(mut self, children: impl IntoIterator<Item = impl Into<SliderTrackChild>>,) -> Self
Adds multiple typed children in iteration order. |
.child_any | pub fn child_any(mut self, child: impl IntoElement) -> Self
Adds one arbitrary renderable child to this part. |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(SliderTrackStyleState, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. SliderTrack also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#SliderValue
Displays or edits the component's current value.
use base_gpui::slider::SliderValue;
SliderValue::new()
.with_slider_context(/* context: SliderContext */)
.id("example-id")
.display(0.0)
.style_with_state(|/* callback arguments */| { /* handle change */ });
#Builders
| Builder | Signature & description |
|---|---|
.new | pub fn new() -> SelfCreates a SliderValue with its default configuration. |
.with_slider_context | pub fn with_slider_context(mut self, context: SliderContext) -> Self
Sets the with slider context configuration for this part. |
.id | pub fn id(mut self, id: impl Into<ElementId>) -> Self
Sets the stable GPUI element identity. Use a unique value when multiple instances can appear in the same view. |
.display | pub fn display(mut self, display: impl Fn(&[SharedString], &[f64]) -> SharedString + 'static,) -> Self
Sets the display configuration for this part. |
.style_with_state | pub fn style_with_state(mut self, style: impl Fn(SliderValueStyleState, Div) -> Div + 'static,) -> Self
Styles the part from its current behavioral state while preserving separation between behavior and visual design. SliderValue also supports the GPUI traits implemented in its source, such as standard styling or child composition. |
#Accessibility
Keyboard interaction and accessibility semantics are implemented by the component, independently of visual styling. Known limitations caused by missing GPUI accessibility primitives are documented in the module source and are not silently approximated.
#Stability
Base GPUI is pre-1.0. Builder names and state types may evolve as GPUI and this port mature.