Slider
Allows users to select a value from a continuous range by sliding a handle.
<script lang="ts">
import { Slider } from "$lib";
let value = [50];
</script>
<div class="w-full md:max-w-[75%]">
<Slider.Root
bind:value
class="relative flex w-full touch-none select-none items-center"
>
<span
class="relative h-2 w-full grow overflow-hidden rounded-full bg-dark-10"
>
<Slider.Range class="absolute h-full bg-foreground" />
</span>
<Slider.Thumb
class="block rounded-full border bg-background shadow transition-colors sq-[27px] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-foreground focus-visible:ring-offset-2 active:scale-98 disabled:pointer-events-none disabled:opacity-50"
/>
</Slider.Root>
</div>
<script lang="ts">
import { Slider } from "$lib";
let value = [50];
</script>
<div class="w-full md:max-w-[75%]">
<Slider.Root
bind:value
class="relative flex w-full touch-none select-none items-center"
>
<span
class="relative h-2 w-full grow overflow-hidden rounded-full bg-dark-10"
>
<Slider.Range class="absolute h-full bg-foreground" />
</span>
<Slider.Thumb
class="block rounded-full border bg-background shadow transition-colors sq-[27px] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-foreground focus-visible:ring-offset-2 active:scale-98 disabled:pointer-events-none disabled:opacity-50"
/>
</Slider.Root>
</div>
Structure
<script lang="ts">
import { Slider } from "bits-ui";
</script>
<Slider.Root>
<Slider.Range />
<Slider.Thumb />
<Slider.Input />
</Slider.Root>
<script lang="ts">
import { Slider } from "bits-ui";
</script>
<Slider.Root>
<Slider.Range />
<Slider.Thumb />
<Slider.Input />
</Slider.Root>
Component API
The root slider component which contains the remaining slider components.
Property | Type | Description |
---|---|---|
value | number[] | The current value of the slider. Default:
[] |
onValueChange | function | A callback function called when the value state of the slider changes. Default:
—— undefined |
disabled | boolean | Whether or not the switch is disabled. Default:
false |
max | number | The maximum value of the slider. Default:
100 |
min | number | The minimum value of the slider. Default:
0 |
orientation | enum | The orientation of the slider. Default:
"horizontal" |
step | number | The step value of the slider. Default:
1 |
asChild | boolean | Whether to use render delegation with this component or not. Default:
false |
Slot Property | Type | Description |
---|---|---|
builder | object | The builder attributes and actions to apply to the element if using the |
attrs | object | Additional attributes to apply to the element if using the |
ticks | number | The number of ticks to display on the slider. |
Data Attribute | Value | Description |
---|---|---|
data-orientation | enum | The orientation of the slider. |
data-slider-root | —— | Present on the root element. |
The range of the slider.
Property | Type | Description |
---|---|---|
asChild | boolean | Whether to use render delegation with this component or not. Default:
false |
Slot Property | Type | Description |
---|---|---|
builder | object | The builder attributes and actions to apply to the element if using the |
attrs | object | Additional attributes to apply to the element if using the |
Data Attribute | Value | Description |
---|---|---|
data-slider-range | —— | Present on the range elements. |
A thumb on the slider.
Property | Type | Description |
---|---|---|
asChild | boolean | Whether to use render delegation with this component or not. Default:
false |
Slot Property | Type | Description |
---|---|---|
builder | object | The builder attributes and actions to apply to the element if using the |
attrs | object | Additional attributes to apply to the element if using the |
Data Attribute | Value | Description |
---|---|---|
data-slider-thumb | —— | Present on the thumb elements. |
A tick mark on the slider.
Property | Type | Description |
---|---|---|
asChild | boolean | Whether to use render delegation with this component or not. Default:
false |
Slot Property | Type | Description |
---|---|---|
builder | object | The builder attributes and actions to apply to the element if using the |
attrs | object | Additional attributes to apply to the element if using the |
Data Attribute | Value | Description |
---|---|---|
data-bounded | —— | Present when the tick is bounded. |
data-slider-tick | —— | Present on the tick elements. |
🚧 UNDER CONSTRUCTION 🚧