Slider

A draggable control for picking a value from a range.

EXAMPLEwasm · webgpu

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.

Source

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

BuilderSignature & description
.newpub fn new() -> Self

Creates a SliderRoot with its default configuration.

.with_field_contextpub fn with_field_context(mut self, context: FieldContext) -> Self
  • context: FieldContext

Sets the with field context configuration for this part.

.childpub fn child(mut self, child: impl Into<SliderChild>) -> Self
  • child: impl Into<SliderChild>

Adds one typed child to this part.

.childrenpub fn children(mut self, children: impl IntoIterator<Item = impl Into<SliderChild>>) -> Self
  • children: impl IntoIterator<Item = impl Into<SliderChild>>

Adds multiple typed children in iteration order.

.child_anypub fn child_any(mut self, child: impl IntoElement) -> Self
  • child: impl IntoElement

Adds one arbitrary renderable child to this part.

.idpub fn id(mut self, id: impl Into<ElementId>) -> Self
  • id: impl Into<ElementId>

Sets the stable GPUI element identity. Use a unique value when multiple instances can appear in the same view.

.namepub fn name(mut self, name: impl Into<SharedString>) -> Self
  • name: impl Into<SharedString>

Sets the form field name used when serializing or submitting the value.

.default_valuepub fn default_value(mut self, default_value: SliderValues) -> Self
  • default_value: SliderValues

Sets the initial value for uncontrolled state. Later user changes are retained by the component.

.valuepub fn value(mut self, value: SliderValues) -> Self
  • value: SliderValues

Sets the current controlled value or the value represented by this part, depending on the part's role.

.minpub fn min(mut self, min: f64) -> Self
  • min: f64

Sets the min configuration for this part.

.maxpub fn max(mut self, max: f64) -> Self
  • max: f64

Sets the max configuration for this part.

.steppub fn step(mut self, step: f64) -> Self
  • step: f64

Sets the step configuration for this part.

.large_steppub fn large_step(mut self, large_step: f64) -> Self
  • large_step: f64

Sets the large step configuration for this part.

.min_steps_between_valuespub fn min_steps_between_values(mut self, min_steps_between_values: f64) -> Self
  • min_steps_between_values: f64

Sets the min steps between values configuration for this part.

.orientationpub fn orientation(mut self, orientation: SliderOrientation) -> Self
  • orientation: SliderOrientation

Sets the component's horizontal or vertical orientation and corresponding keyboard behavior.

.thumb_collision_behaviorpub fn thumb_collision_behavior(mut self, behavior: SliderThumbCollisionBehavior) -> Self
  • behavior: SliderThumbCollisionBehavior

Sets the thumb collision behavior configuration for this part.

.thumb_alignmentpub fn thumb_alignment(mut self, thumb_alignment: SliderThumbAlignment) -> Self
  • thumb_alignment: SliderThumbAlignment

Sets the thumb alignment configuration for this part.

.disabledpub fn disabled(mut self, disabled: bool) -> Self
  • disabled: bool

When true, prevents user interaction with this part.

.aria_labelpub fn aria_label(mut self, aria_label: impl Into<SharedString>) -> Self
  • aria_label: impl Into<SharedString>

Accessible label for the slider group, mirroring what SliderLabel displays. Base UI links the label by id via aria-labelledby; gpui has no id-reference builder, so the text is supplied literally. Callers who set this should render the visible SliderLabel text with Text::new_inaccessible(...) to avoid double-announcing.

.formatpub fn format(mut self, format: impl Fn(f64) -> SharedString + 'static) -> Self
  • format: impl Fn(f64) -> SharedString + 'static

Sets the format configuration for this part.

.on_value_changepub fn on_value_change(mut self, on_value_change: impl Fn(SliderValues, &mut SliderValueChangeDetails, &mut Window, &mut App) + 'static,) -> Self
  • on_value_change: impl Fn(SliderValues, &mut SliderValueChangeDetails, &mut Window, &mut App) + 'static

Registers a callback invoked when value change occurs.

.on_value_committedpub fn on_value_committed(mut self, on_value_committed: impl Fn(SliderValues, SliderValueCommitDetails, &mut Window, &mut App) + 'static,) -> Self
  • on_value_committed: impl Fn(SliderValues, SliderValueCommitDetails, &mut Window, &mut App) + 'static

Registers a callback invoked when value committed occurs.

.style_with_statepub fn style_with_state(mut self, style: impl Fn(SliderRootStyleState, Div) -> Div + 'static,) -> Self
  • style: impl Fn(SliderRootStyleState, Div) -> Div + 'static,

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.

Source

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

BuilderSignature & description
.newpub fn new() -> Self

Creates a SliderControl with its default configuration.

.with_slider_contextpub fn with_slider_context(mut self, context: SliderContext) -> Self
  • context: SliderContext

Sets the with slider context configuration for this part.

.map_childrenpub fn map_children(mut self, map: impl FnOnce(Vec<SliderControlChild>) -> Vec<SliderControlChild>,) -> Self
  • map: impl FnOnce(Vec<SliderControlChild>) -> Vec<SliderControlChild>,

Sets the map children configuration for this part.

.idpub fn id(mut self, id: impl Into<ElementId>) -> Self
  • id: impl Into<ElementId>

Sets the stable GPUI element identity. Use a unique value when multiple instances can appear in the same view.

.childpub fn child(mut self, child: impl Into<SliderControlChild>) -> Self
  • child: impl Into<SliderControlChild>

Adds one typed child to this part.

.childrenpub fn children(mut self, children: impl IntoIterator<Item = impl Into<SliderControlChild>>,) -> Self
  • children: impl IntoIterator<Item = impl Into<SliderControlChild>>

Adds multiple typed children in iteration order.

.child_anypub fn child_any(mut self, child: impl IntoElement) -> Self
  • child: impl IntoElement

Adds one arbitrary renderable child to this part.

.style_with_statepub fn style_with_state(mut self, style: impl Fn(SliderControlStyleState, Div) -> Div + 'static,) -> Self
  • style: impl Fn(SliderControlStyleState, Div) -> Div + 'static,

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.

Source

use base_gpui::slider::SliderIndicator;

SliderIndicator::new()
    .with_slider_context(/* context: SliderContext */)
    .id("example-id")
    .style_with_state(|/* callback arguments */| { /* handle change */ });

#Builders

BuilderSignature & description
.newpub fn new() -> Self

Creates a SliderIndicator with its default configuration.

.with_slider_contextpub fn with_slider_context(mut self, context: SliderContext) -> Self
  • context: SliderContext

Sets the with slider context configuration for this part.

.idpub fn id(mut self, id: impl Into<ElementId>) -> Self
  • id: impl Into<ElementId>

Sets the stable GPUI element identity. Use a unique value when multiple instances can appear in the same view.

.style_with_statepub fn style_with_state(mut self, style: impl Fn(SliderIndicatorStyleState, Div) -> Div + 'static,) -> Self
  • style: impl Fn(SliderIndicatorStyleState, Div) -> Div + 'static,

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.

Source

use base_gpui::slider::SliderLabel;

SliderLabel::new()
    .with_slider_context(/* context: SliderContext */)
    .id("example-id")
    .style_with_state(|/* callback arguments */| { /* handle change */ });

#Builders

BuilderSignature & description
.newpub fn new() -> Self

Creates a SliderLabel with its default configuration.

.with_slider_contextpub fn with_slider_context(mut self, context: SliderContext) -> Self
  • context: SliderContext

Sets the with slider context configuration for this part.

.idpub fn id(mut self, id: impl Into<ElementId>) -> Self
  • id: impl Into<ElementId>

Sets the stable GPUI element identity. Use a unique value when multiple instances can appear in the same view.

.childpub fn child(mut self, child: impl IntoElement) -> Self
  • child: impl IntoElement

Base UI links this label to the root via aria-labelledby; gpui has no id-reference builder, so the label text is instead supplied to SliderRoot::aria_label(...). Once that is set, pass the visible label text here as Text::new_inaccessible(...) so it is not announced twice.

.style_with_statepub fn style_with_state(mut self, style: impl Fn(SliderLabelStyleState, Div) -> Div + 'static,) -> Self
  • style: impl Fn(SliderLabelStyleState, Div) -> Div + 'static,

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.

Source

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

BuilderSignature & description
.newpub fn new() -> Self

Creates a SliderThumb with its default configuration.

.with_slider_contextpub fn with_slider_context(mut self, context: SliderContext) -> Self
  • context: SliderContext

Sets the with slider context configuration for this part.

.with_thumb_indexpub fn with_thumb_index(mut self, index: usize) -> Self
  • index: usize

Sets the with thumb index configuration for this part.

.thumb_indexpub fn thumb_index(&self) -> Option<usize>

Sets the thumb index configuration for this part.

.thumb_disabledpub fn thumb_disabled(&self) -> bool

Sets the thumb disabled configuration for this part.

.idpub fn id(mut self, id: impl Into<ElementId>) -> Self
  • id: impl Into<ElementId>

Sets the stable GPUI element identity. Use a unique value when multiple instances can appear in the same view.

.disabledpub fn disabled(mut self, disabled: bool) -> Self
  • disabled: bool

When true, prevents user interaction with this part.

.aria_labelpub fn aria_label(mut self, aria_label: impl Into<SharedString>) -> Self
  • aria_label: impl Into<SharedString>

Accessible label for this thumb (e.g. "Minimum" / "Maximum" on a range slider). A plain string per thumb replaces Base UI's optional getAriaLabel(index) closure.

.childpub fn child(mut self, child: impl IntoElement) -> Self
  • child: impl IntoElement

Adds one typed child to this part.

.style_with_statepub fn style_with_state(mut self, style: impl Fn(SliderThumbStyleState, Div) -> Div + 'static,) -> Self
  • style: impl Fn(SliderThumbStyleState, Div) -> Div + 'static,

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.

Source

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

BuilderSignature & description
.newpub fn new() -> Self

Creates a SliderTrack with its default configuration.

.with_slider_contextpub fn with_slider_context(mut self, context: SliderContext) -> Self
  • context: SliderContext

Sets the with slider context configuration for this part.

.map_childrenpub fn map_children(mut self, map: impl FnOnce(Vec<SliderTrackChild>) -> Vec<SliderTrackChild>,) -> Self
  • map: impl FnOnce(Vec<SliderTrackChild>) -> Vec<SliderTrackChild>,

Sets the map children configuration for this part.

.idpub fn id(mut self, id: impl Into<ElementId>) -> Self
  • id: impl Into<ElementId>

Sets the stable GPUI element identity. Use a unique value when multiple instances can appear in the same view.

.childpub fn child(mut self, child: impl Into<SliderTrackChild>) -> Self
  • child: impl Into<SliderTrackChild>

Adds one typed child to this part.

.childrenpub fn children(mut self, children: impl IntoIterator<Item = impl Into<SliderTrackChild>>,) -> Self
  • children: impl IntoIterator<Item = impl Into<SliderTrackChild>>

Adds multiple typed children in iteration order.

.child_anypub fn child_any(mut self, child: impl IntoElement) -> Self
  • child: impl IntoElement

Adds one arbitrary renderable child to this part.

.style_with_statepub fn style_with_state(mut self, style: impl Fn(SliderTrackStyleState, Div) -> Div + 'static,) -> Self
  • style: impl Fn(SliderTrackStyleState, Div) -> Div + 'static,

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.

Source

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

BuilderSignature & description
.newpub fn new() -> Self

Creates a SliderValue with its default configuration.

.with_slider_contextpub fn with_slider_context(mut self, context: SliderContext) -> Self
  • context: SliderContext

Sets the with slider context configuration for this part.

.idpub fn id(mut self, id: impl Into<ElementId>) -> Self
  • id: impl Into<ElementId>

Sets the stable GPUI element identity. Use a unique value when multiple instances can appear in the same view.

.displaypub fn display(mut self, display: impl Fn(&[SharedString], &[f64]) -> SharedString + 'static,) -> Self
  • display: impl Fn(&[SharedString], &[f64]) -> SharedString + 'static,

Sets the display configuration for this part.

.style_with_statepub fn style_with_state(mut self, style: impl Fn(SliderValueStyleState, Div) -> Div + 'static,) -> Self
  • style: impl Fn(SliderValueStyleState, Div) -> Div + 'static,

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.