Skip to main content

Starwind UI v3.0 beta is now available! Read the migration guide

Slider Primitive

Slider is a Starwind Runtime primitive in the form-value-control contract family.

Anatomy

Use the Astro primitive adapter to render Slider anatomy with the Runtime wiring included.

---
import { Slider } from "@starwind-ui/astro/slider";
---
<Slider.Root>
<Slider.Label>Volume</Slider.Label>
<Slider.Control>
<Slider.Track>
<Slider.Indicator />
<Slider.Thumb />
</Slider.Track>
</Slider.Control>
</Slider.Root>

API Reference

Root

The main element that owns the Slider Runtime instance.

Default element
div
Discovery hook
data-sw-slider
Role
group

Props

Prop Type Default Toggle
value SliderValue -
Description
Controls the current Slider value.
Kind
control
Targets
-
Full type
SliderValue
defaultValue SliderValue 0
Description
Sets the initial Slider value for uncontrolled usage.
Kind
control
Targets
-
Full type
SliderValue
disabled boolean false
Description
Disables the Root part.
Kind
option
Targets
-
Full type
boolean
form string -
Description
Associates the control with a form element.
Kind
option
Targets
-
Full type
string
largeStep number 10
Description
Configures the large step option for the Root part.
Kind
option
Targets
-
Full type
number
max number 100
Description
Configures the max option for the Root part.
Kind
option
Targets
-
Full type
number
min number 0
Description
Configures the min option for the Root part.
Kind
option
Targets
-
Full type
number
minStepsBetweenValues number 0
Description
Configures the min steps between values option for the Root part.
Kind
option
Targets
-
Full type
number
name string -
Description
Sets the submitted form field name.
Kind
option
Targets
-
Full type
string
orientation SliderOrientation "horizontal"
Description
Sets the Slider orientation.
Kind
option
Targets
-
Full type
SliderOrientation
step number 1
Description
Configures the step option for the Root part.
Kind
option
Targets
-
Full type
number
onValueChange (value: SliderValue, details: SliderValueChangeDetails) => void -
Description
Runs when the Slider value changes.
Kind
callback
Targets
-
Full type
(value: SliderValue, details: SliderValueChangeDetails) => void
onValueCommitted (value: SliderValue, details: SliderValueCommitDetails) => void -
Description
Runs when on value committed changes for Slider.
Kind
callback
Targets
-
Full type
(value: SliderValue, details: SliderValueCommitDetails) => void

Events

Event Callback Value Toggle
valueChange onValueChange value: SliderValue
Description
Fires when the value changes for Slider.
DOM event
starwind:value-change
Details type
SliderValueChangeDetails
Timing
-
Cancelable
No
valueCommitted onValueCommitted value: SliderValue
Description
Fires when the user commits the value for Slider.
DOM event
starwind:value-committed
Details type
SliderValueCommitDetails
Timing
-
Cancelable
No

State

State Type Props Toggle
value SliderValue value / defaultValue
Description
Tracks the current Slider value.
Initial attribute
data-default-value
Runtime getter
getValue
Runtime setter
setValue
State control support
React supports controlled and default state with value and defaultValue props. Runtime/HTML reads initial state from data-default-value, emits starwind:value-change and starwind:value-committed, and updates with setValue. Astro adapters render initial/default state, but do not expose reactive controlled-state props for this state.

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-slider - Marks the Root part so Starwind Runtime can find it.
State
Attribute Value Description
data-value - Reflects the value state on the Root part.
Metadata
Attribute Value Description
data-default-value - Reflects the default value prop on the Root part.
data-disabled - Reflects the disabled prop on the Root part.
data-form - Reflects the form prop on the Root part.
data-large-step - Reflects the large step prop on the Root part.
data-max - Reflects the max prop on the Root part.
data-min - Reflects the min prop on the Root part.
data-min-steps-between-values - Reflects the min steps between values prop on the Root part.
data-name - Reflects the name prop on the Root part.
data-orientation - Reflects the orientation prop on the Root part.
data-step - Reflects the step prop on the Root part.

Control

Groups the interactive controls for Slider.

Default element
div
Discovery hook
data-sw-slider-control
Role
-

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-slider-control - Marks the Control part so Starwind Runtime can find it.

Track

The track that contains the Slider range.

Default element
div
Discovery hook
data-sw-slider-track
Role
-

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-slider-track - Marks the Track part so Starwind Runtime can find it.

Indicator

Visual state indicator rendered by Slider.

Default element
div
Discovery hook
data-sw-slider-indicator
Role
-

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-slider-indicator - Marks the Indicator part so Starwind Runtime can find it.

Label

Text label associated with Slider.

Default element
span
Discovery hook
data-sw-slider-label
Role
-

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-slider-label - Marks the Label part so Starwind Runtime can find it.

Thumb

The draggable thumb for Slider.

Default element
div
Discovery hook
data-sw-slider-thumb
Role
-

Props

Prop Type Default Toggle
index number -
Description
Sets the index attribute on the Thumb part.
Kind
attribute
Targets
thumb
Full type
number

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-slider-thumb - Marks the Thumb part so Starwind Runtime can find it.
Metadata
Attribute Value Description
data-index - Reflects the index prop on the Thumb part.

Input

The native input synchronized by Slider.

Default element
input
Discovery hook
data-sw-slider-input
Role
-

Data Attributes

Runtime hooks
Attribute Value Description
data-sw-slider-input - Marks the Input part so Starwind Runtime can find it.

Runtime API

Factory
createSlider
Import
@starwind-ui/runtime/slider
Root hook
root data-sw-slider
Option props
defaultValue, disabled, form, largeStep, max, min, minStepsBetweenValues, name, orientation, step, value

Option Lifecycles

OptionLifecycle
disabledsetter-backed
formsetter-backed
largeStepsetter-backed
maxsetter-backed
minsetter-backed
minStepsBetweenValuessetter-backed
namesetter-backed
orientationsetter-backed
stepsetter-backed
valuesetter-backed

Runtime Setters

Method Target Description
setValue state: value Updates the current Slider value from Runtime code.
setDisabled prop: disabled Updates whether Slider is disabled from Runtime code.
setName prop: name Updates the Slider form field name from Runtime code.
setOptions props: form, largeStep, max, min, minStepsBetweenValues, orientation, step Updates Runtime options after initialization.

Form Participation

FactValue
Form propsform, name, value
Hidden inputinput (range)
Field integrationYes
Component Relationship
Slider Direct primitive