Slider (슬라이더)
Slider는 연속된 범위 안에서 값을 고르게 해 주는 컴포넌트예요. 썸(thumb)을 드래그해서 값을 조정하고, 여러 개의 썸과 눈금, 라벨까지 지원해서 범위 선택에 폭넓게 활용할 수 있어요. 방향·정렬·폼 제출 방식도 상황에 맞게 조절할 수 있습니다.
출처: 문서
본문
<script lang="ts">
import { Slider } from "bits-ui";
import cn from "clsx";
let value = $state(50);
</script>
<div class="w-full md:max-w-[280px]">
<Slider.Root
type="single"
bind:value
class="relative flex w-full touch-none select-none items-center"
>
<span
class="bg-dark-10 relative h-2 w-full grow cursor-pointer overflow-hidden rounded-full"
>
<Slider.Range class="bg-foreground absolute h-full" />
</span>
<Slider.Thumb
index={0}
class={cn(
"border-border-input bg-background hover:border-dark-40 focus-visible:ring-foreground dark:bg-foreground dark:shadow-card data-active:border-dark-40 focus-visible:outline-hidden data-active:scale-[0.98] block size-[25px] cursor-pointer rounded-full border shadow-sm transition-colors focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50"
)}
/>
</Slider.Root>
</div>
구조
<script lang="ts">
import { Slider } from "bits-ui";
</script>
<Slider.Root>
<Slider.Range />
<Slider.Thumb />
<Slider.Tick />
</Slider.Root>
재사용 가능한 컴포넌트
Bits UI는 애플리케이션 전반에서 재사용할 수 있는 커스텀 슬라이더 컴포넌트를 만들 수 있는 프리미티브를 제공해요.
다음은 재사용 가능한 MySlider 컴포넌트를 만드는 예시예요.
MyMultiSlider.svelte
<script lang="ts">
import type { ComponentProps } from "svelte";
import { Slider, type WithoutChildren } from "bits-ui";
type Props = WithoutChildren<ComponentProps<typeof Slider.Root>>;
let {
value = $bindable(),
ref = $bindable(null),
...restProps
}: Props = $props();
</script>
<!--
Since we have to destructure the `value` to make it `$bindable`, we need to use `as any` here to avoid
type errors from the discriminated union of `"single" | "multiple"`.
(an unfortunate consequence of having to destructure bindable values)
-->
<Slider.Root bind:value bind:ref {...restProps as any}>
{#snippet children({ thumbs, ticks })}
<Slider.Range />
{#each thumbs as index}
<Slider.Thumb {index} />
{/each}
{#each ticks as index}
<Slider.Tick {index} />
{/each}
{/snippet}
</Slider.Root>
그다음에는 이렇게 만든 MySlider 컴포넌트를 애플리케이션에서 사용할 수 있어요:
<script lang="ts">
import MySlider from "$lib/components/MySlider.svelte";
let multiValue = $state([5, 10]);
let singleValue = $state(50);
</script>
<MySlider bind:value={multiValue} type="multiple" />
<MySlider bind:value={singleValue} type="single" />
value 상태 다루기
이번 절에서는 컴포넌트의 value 상태를 어떻게 관리하는지 다뤄요.
양방향 바인딩 (Two-Way Binding)
간단하고 자동적인 상태 동기화를 위해 bind:value를 사용해요:
<script lang="ts">
import { Slider } from "bits-ui";
let myValue = $state(0);
</script>
<button onclick={() => (myValue = 20)}> Set value to 20 </button>
<Slider.Root bind:value={myValue} type="single">
<!-- ... -->
</Slider.Root>
완전 제어 (Fully Controlled)
상태의 읽기와 쓰기를 완전히 통제하고 싶다면 Function Binding을 사용해요.
<script lang="ts">
import { Slider } from "bits-ui";
let myValue = $state(0);
function getValue() {
return myValue;
}
function setValue(newValue: number) {
myValue = newValue;
}
</script>
<Slider.Root type="single" bind:value={getValue, setValue}>
<!-- ... -->
</Slider.Root>
값 커밋 (Value Commit)
onValueCommit prop은 사용자가 썸 드래그를 끝내고 값이 바뀌었을 때 알림을 받게 해 줘요. 이 콜백은 사용자가 드래그를 멈출 때까지 기다렸다가 호출된다는 점에서 onValueChange와 달라요. onValueChange는 사용자가 드래그하는 동안 계속 호출됩니다.
<Slider.Root
onValueCommit={(v) => {
console.log("user is done sliding!", v);
}}
/>
RTL 지원
dir prop으로 슬라이더의 읽기 방향을 바꿀 수 있어요. 기본값은 "ltr"입니다.
<Slider.Root type="single" dir="rtl">
<!-- ... -->
</Slider.Root>
자동 정렬 (Auto Sort)
기본적으로 슬라이더는 값을 작은 것부터 큰 것 순으로 정렬해요. 그래서 작은 썸을 더 큰 값으로 드래그하면 그 썸의 값이 큰 값으로 갱신됩니다.
이 동작을 끄려면 autoSort prop을 false로 설정하면 돼요.
<Slider.Root type="multiple" autoSort={false}>
<!-- ... -->
</Slider.Root>
HTML 폼
사용자가 고를 수 있는 값이 거의 무한하다 보니, 슬라이더는 기본적으로 숨겨진 input 요소를 렌더링하지 않아요.
슬라이더 값(들)을 폼으로 어떻게 제출할지는 여러분이 직접 정해야 합니다.
다음은 그렇게 처리하는 예시예요:
<script lang="ts">
import MySlider from "$lib/components/MySlider.svelte";
let expectedIncome = $state([50, 100]);
let desiredIncome = $state(50);
</script>
<form method="POST">
<MySlider type="multiple" bind:value={expectedIncome} />
<input type="hidden" name="expectedIncomeStart" value={expectedIncome[0]} />
<input type="hidden" name="expectedIncomeEnd" value={expectedIncome[1]} />
<MySlider type="single" bind:value={desiredIncome} />
<input type="hidden" name="expectedIncomeEnd" value={desiredIncome} />
<button type="submit">Submit</button>
</form>
예제
다중 썸과 눈금
value prop에 값이 두 개 이상이면 슬라이더는 썸을 여러 개 렌더링해요. tickItems와 thumbItems 스니펫 props로 특정 간격마다 눈금과 썸을 그릴 수도 있습니다.
<script lang="ts">
import { Slider } from "bits-ui";
// we have two numbers in the array, so the slider will render two thumbs
let value = $state([5, 7]);
</script>
<Slider.Root type="multiple" min={0} max={10} step={1} bind:value>
{#snippet children({ tickItems, thumbItems })}
<Slider.Range />
{#each thumbItems as { index } (index)}
<Slider.Thumb {index} />
{/each}
{#each tickItems as { index } (index)}
<Slider.Tick {index} />
{/each}
{/snippet}
</Slider.Root>
렌더링될 눈금의 개수는 max 값을 step 값으로 나누면 간단히 구할 수 있어요.
코드 펼치기
<script lang="ts">
import { Slider } from "bits-ui";
let value = $state([5, 7]);
</script>
<div class="w-full md:max-w-[280px]">
<Slider.Root
step={1}
min={0}
max={10}
type="multiple"
bind:value
class="relative flex w-full touch-none select-none items-center"
>
{#snippet children({ tickItems, thumbs })}
<span
class="bg-dark-10 relative h-2 w-full grow cursor-pointer overflow-hidden rounded-full"
>
<Slider.Range class="bg-foreground absolute h-full" />
</span>
{#each thumbs as thumb (thumb)}
<Slider.Thumb
index={thumb}
class="border-border-input bg-background hover:border-dark-40 focus-visible:ring-foreground dark:bg-foreground dark:shadow-card data-active:border-dark-40 z-5 focus-visible:outline-hidden data-active:scale-[0.98] block size-[25px] cursor-pointer rounded-full border shadow-sm transition-colors focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50"
/>
{/each}
{#each tickItems as { index } (index)}
<Slider.Tick
{index}
class="dark:bg-background/20 bg-background z-1 h-2 w-[1px]"
/>
{/each}
{/snippet}
</Slider.Root>
</div>
단일 타입
슬라이더 핸들을 하나만 허용하려면 type prop을 "single"로 설정해요.
<Slider.Root type="single" />
코드 펼치기
<script lang="ts">
import { Slider } from "bits-ui";
import cn from "clsx";
let value = $state(50);
</script>
<div class="w-full md:max-w-[280px]">
<Slider.Root
type="single"
bind:value
class="relative flex w-full touch-none select-none items-center"
>
<span
class="bg-dark-10 relative h-2 w-full grow cursor-pointer overflow-hidden rounded-full"
>
<Slider.Range class="bg-foreground absolute h-full" />
</span>
<Slider.Thumb
index={0}
class={cn(
"border-border-input bg-background hover:border-dark-40 focus-visible:ring-foreground dark:bg-foreground dark:shadow-card data-active:border-dark-40 focus-visible:outline-hidden data-active:scale-[0.98] block size-[25px] cursor-pointer rounded-full border shadow-sm transition-colors focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50"
)}
/>
</Slider.Root>
</div>
다중 타입
슬라이더 핸들을 여러 개 허용하려면 type prop을 "multiple"로 설정해요.
<Slider.Root type="multiple" />
코드 펼치기
<script lang="ts">
import { Slider } from "bits-ui";
import cn from "clsx";
let value = $state([25, 75]);
</script>
<div class="w-full md:max-w-[280px]">
<Slider.Root
type="multiple"
bind:value
class="relative flex w-full touch-none select-none items-center"
>
{#snippet children({ thumbItems })}
<span
class="bg-dark-10 relative h-2 w-full grow cursor-pointer overflow-hidden rounded-full"
>
<Slider.Range class="bg-foreground absolute h-full" />
</span>
{#each thumbItems as { index } (index)}
<Slider.Thumb
{index}
class={cn(
"border-border-input bg-background hover:border-dark-40 focus-visible:ring-foreground dark:bg-foreground dark:shadow-card data-active:border-dark-40 focus-visible:outline-hidden data-active:scale-[0.98] block size-[25px] cursor-pointer rounded-full border shadow-sm transition-colors focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50"
)}
/>
{/each}
{/snippet}
</Slider.Root>
</div>
세로 방향
orientation prop으로 슬라이더 방향을 바꿀 수 있어요. 기본값은 "horizontal"입니다.
<Slider.Root type="single" orientation="vertical">
<!-- ... -->
</Slider.Root>
코드 펼치기
<script lang="ts">
import { Slider } from "bits-ui";
let value = $state(50);
</script>
<div class="flex h-[320px] w-full justify-center">
<Slider.Root
type="single"
step={1}
bind:value
orientation="vertical"
class="relative flex h-full touch-none select-none flex-col items-center"
trackPadding={3}
>
<span
class="bg-dark-10 relative h-full w-2 cursor-pointer overflow-hidden rounded-full"
>
<Slider.Range class="bg-foreground absolute w-full" />
</span>
<Slider.Thumb
index={0}
class="border-border-input bg-background hover:border-dark-40 focus-visible:ring-foreground dark:bg-foreground dark:shadow-card data-active:border-dark-40 z-5 focus-visible:outline-hidden data-active:scale-[0.98] block size-[25px] cursor-pointer rounded-full border shadow-sm transition-colors focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50"
/>
</Slider.Root>
</div>
눈금 라벨
tickItems 스니펫 prop을 Slider.TickLabel과 함께 쓰면 특정 간격마다 라벨을 렌더링할 수 있어요.
<Slider.Root type="single" step={[0, 4, 8, 16, 24]}>
{#snippet children({ tickItems })}
{#each tickItems as { value, index } (index)}
<Slider.Tick {index} />
<Slider.TickLabel {index} position="top">
{value}
</Slider.TickLabel>
{/each}
{/snippet}
</Slider.Root>
코드 펼치기
<script lang="ts">
import { Slider } from "bits-ui";
let value = $state([5, 7]);
</script>
<div class="w-full md:max-w-[280px]">
<Slider.Root
step={1}
min={0}
max={10}
type="multiple"
bind:value
class="relative flex w-full touch-none select-none items-center"
trackPadding={2}
>
{#snippet children({ tickItems, thumbItems })}
<span
class="bg-dark-10 relative h-2 w-full grow cursor-pointer overflow-hidden rounded-full"
>
<Slider.Range class="bg-foreground absolute h-full" />
</span>
{#each thumbItems as { index } (index)}
<Slider.Thumb
{index}
class="border-border-input bg-background hover:border-dark-40 focus-visible:ring-foreground dark:bg-foreground dark:shadow-card data-active:border-dark-40 z-5 focus-visible:outline-hidden data-active:scale-[0.98] block size-[25px] cursor-pointer rounded-full border shadow-sm transition-colors focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50"
/>
{/each}
{#each tickItems as { index, value } (index)}
<Slider.Tick
{index}
class="dark:bg-background/20 bg-background z-1 h-2 w-[1px]"
/>
<Slider.TickLabel
{index}
class="text-muted-foreground data-bounded:text-foreground mb-5 text-sm font-medium leading-none"
position="top"
>
{value}
</Slider.TickLabel>
{/each}
{/snippet}
</Slider.Root>
</div>
불연속 단계
step prop에 단일 값을 전달하는 대신, 슬라이더가 스냅할 불연속 값들의 배열을 전달할 수도 있어요.
<Slider.Root type="single" step={[0, 4, 8, 16, 24]}>
<!-- ... -->
</Slider.Root>
코드 펼치기
<script lang="ts">
import { Slider } from "bits-ui";
let fontSize = $state(16);
const fontSizes = [0, 4, 8, 16, 24];
</script>
<div class="w-full md:max-w-[320px]">
<Slider.Root
type="single"
step={fontSizes}
bind:value={fontSize}
class="relative flex w-full touch-none select-none items-center"
trackPadding={3}
>
{#snippet children({ tickItems })}
<span
class="bg-dark-10 relative h-2 w-full grow cursor-pointer overflow-hidden rounded-full"
>
<Slider.Range class="bg-foreground absolute h-full" />
</span>
<Slider.Thumb
index={0}
class="border-border-input bg-background hover:border-dark-40 focus-visible:ring-foreground dark:bg-foreground dark:shadow-card data-active:border-dark-40 z-5 focus-visible:outline-hidden data-active:scale-[0.98] block size-[25px] cursor-pointer rounded-full border shadow-sm transition-colors focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50"
/>
{#each tickItems as { index, value } (index)}
<Slider.Tick
{index}
class="dark:bg-background bg-background z-1 h-2 w-[1px]"
/>
<Slider.TickLabel
{index}
class="text-muted-foreground data-selected:text-foreground mb-5 text-sm font-medium leading-none"
>
{value}px
</Slider.TickLabel>
{/each}
{/snippet}
</Slider.Root>
</div>
<div class="flex h-[320px] w-full justify-center">
<Slider.Root
type="single"
step={fontSizes}
bind:value={fontSize}
orientation="vertical"
class="relative flex h-full touch-none select-none flex-col items-center"
trackPadding={3}
>
{#snippet children({ tickItems })}
<span
class="bg-dark-10 relative h-full w-2 cursor-pointer overflow-hidden rounded-full"
>
<Slider.Range class="bg-foreground absolute w-full" />
</span>
<Slider.Thumb
index={0}
class="border-border-input bg-background hover:border-dark-40 focus-visible:ring-foreground dark:bg-foreground dark:shadow-card data-active:border-dark-40 z-5 focus-visible:outline-hidden data-active:scale-[0.98] block size-[25px] cursor-pointer rounded-full border shadow-sm transition-colors focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50"
/>
{#each tickItems as { index, value } (index)}
<Slider.Tick {index} class="dark:bg-background z-1 h-[1px] w-4" />
<Slider.TickLabel
{index}
class="text-muted-foreground data-selected:text-foreground mr-5 text-sm font-medium leading-none"
>
{value}px
</Slider.TickLabel>
{/each}
{/snippet}
</Slider.Root>
</div>
썸 라벨
썸에 상대적으로 배치되는 라벨을 렌더링하려면 Slider.ThumbLabel 컴포넌트를 사용해요.
인덱스를 직접 지정하려면 이렇게 해요:
<Slider.Root type="multiple" autoSort={false} step={10} value={[10, 50]}>
<Slider.Range />
<Slider.Thumb index={0} />
<Slider.ThumbLabel index={0} position="top">Min</Slider.ThumbLabel>
<Slider.Thumb index={1} />
<Slider.ThumbLabel index={1} position="top">Max</Slider.ThumbLabel>
</Slider.Root>
또는 thumbItems 스니펫 prop으로 각 썸마다 라벨을 렌더링할 수 있어요:
<Slider.Root type="multiple" autoSort={false} step={10} value={[10, 50]}>
<Slider.Range />
{#snippet children({ thumbItems })}
{#each thumbItems as { index, value } (index)}
<Slider.Thumb {index} />
<Slider.ThumbLabel {index} position="top">
{index === 0 ? "Min" : "Max"}:{value}
</Slider.ThumbLabel>
{/each}
{/snippet}
</Slider.Root>
코드 펼치기
<script lang="ts">
import { Slider } from "bits-ui";
let value = $state([5, 7, 10]);
</script>
<div class="w-full md:max-w-[400px]">
<Slider.Root
step={1}
min={4}
max={11}
type="multiple"
bind:value
class="relative flex w-full touch-none select-none items-center"
trackPadding={2}
autoSort={false}
>
{#snippet children({ tickItems })}
<span
class="bg-dark-10 relative h-2 w-full grow cursor-pointer overflow-hidden rounded-full"
>
<Slider.Range class="bg-foreground absolute h-full" />
</span>
<Slider.Thumb
index={0}
class="border-border-input bg-background hover:border-dark-40 focus-visible:ring-foreground dark:bg-foreground dark:shadow-card data-active:border-dark-40 z-5 focus-visible:outline-hidden data-active:scale-[0.98] block size-[25px] cursor-pointer rounded-full border shadow-sm transition-colors focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50"
/>
<Slider.ThumbLabel
index={0}
class="bg-muted text-foreground mb-5 text-nowrap rounded-md px-2 py-1 text-sm"
>
Check in
</Slider.ThumbLabel>
<Slider.Thumb
index={1}
class="border-border-input bg-background hover:border-dark-40 focus-visible:ring-foreground dark:bg-foreground dark:shadow-card data-active:border-dark-40 z-5 focus-visible:outline-hidden data-active:scale-[0.98] block size-[25px] cursor-pointer rounded-full border shadow-sm transition-colors focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50"
/>
<Slider.ThumbLabel
index={1}
class="bg-muted text-foreground mb-5 text-nowrap rounded-md px-2 py-1 text-sm"
>
Dinner
</Slider.ThumbLabel>
<Slider.Thumb
index={2}
class="border-border-input bg-background hover:border-dark-40 focus-visible:ring-foreground dark:bg-foreground dark:shadow-card data-active:border-dark-40 z-5 focus-visible:outline-hidden data-active:scale-[0.98] block size-[25px] cursor-pointer rounded-full border shadow-sm transition-colors focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50"
/>
<Slider.ThumbLabel
index={2}
class="bg-muted text-foreground mb-5 text-nowrap rounded-md px-2 py-1 text-sm"
>
Sleep
</Slider.ThumbLabel>
{#each tickItems as { index, value } (index)}
<Slider.Tick
{index}
class="dark:bg-background/20 bg-background z-1 h-2 w-[1px]"
/>
<Slider.TickLabel
{index}
class="text-muted-foreground data-selected:text-foreground mt-5 text-xs font-medium leading-none"
position="bottom"
>
{value}pm
</Slider.TickLabel>
{/each}
{/snippet}
</Slider.Root>
</div>
API 참조
Slider.Root
나머지 슬라이더 컴포넌트들을 담고 있는 루트 슬라이더 컴포넌트예요.
| Property | Type | Description | Details |
|---|---|---|---|
type required |
enum - 'single' | 'multiple' |
The type of the slider. If set to 'multiple', the slider will allow multiple thumbs and the value will be an array of numbers.Default: —— undefined |
|
value $bindable |
number |
The current value of the slider. If the type is set to 'multiple', this should be an array of numbers and will default to an empty array.Default: 0 |
|
onValueChange |
function - (value: number) => void | (value: number[]) => void |
A callback function called when the value state of the slider changes.Default: —— undefined |
|
onValueCommit |
function - (value: number) => void | (value: number[]) => void |
A callback function called when the user finishes dragging the thumb and the value changes. This is different than the onValueChange callback because it waits until the user stops dragging before calling the callback, where the onValueChange callback is called immediately after the user starts dragging.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 - 'horizontal' | 'vertical' |
The orientation of the slider.Default: 'horizontal' |
|
step $bindable |
union - number[] | number |
The step value of the slider. If a single number is provided, the slider will step by that number and use that number to generate the ticks (e.g. step={1} will generate ticks at 0, 1, 2, 3, ...). If an array of numbers is provided, the slider will snap to those values (e.g. step={[0, 4, 8, 16, 24]}) and ticks will be generated at those values.Default: —— undefined |
|
dir |
enum - 'ltr' | 'rtl' |
The reading direction of the app.Default: 'ltr' |
|
autoSort |
boolean |
Whether to automatically sort the values in the array when moving thumbs past one another. This is only applicable to the 'multiple' type.Default: true |
|
thumbPositioning |
enum - 'exact' | 'contain' |
The positioning of the slider thumb. 'contain' will ensure that the thumb is always visible within the track, while 'exact' will ensure that the thumb is always at the same position relative to the track. For an SSR-friendly alternative to thumbPositioning='contain', use the trackPadding prop to set the padding between the thumbs/first ticks and the edges of the track.Default: 'contain' |
|
trackPadding |
number |
A percentage of the full track length to pad the start and end of the track. This is useful for creating a visual buffer between the thumbs or beginning/end ticks and the edges of the track. This is an SSR-friendly alternative to thumbPositioning='contain'.Default: —— undefined |
|
ref $bindable |
HTMLSpanElement |
The underlying DOM element being rendered. You can bind to this to get a reference to the element.Default: null |
|
children |
Snippet - type TickItem = { /** The value this tick represents */ value: number /** The index of this tick */ index: number } type ChildrenSnippetProps = { /** The items to iterate over and render */ tickItems: TickItem[] /** The currently active thumb */ thumbs: number[] /** * An array of ticks to render * @deprecated Use `tickItems` instead */ ticks: number[] } |
The children content to render.Default: —— undefined |
|
child |
Snippet - type TickItem = { /** The value this tick represents */ value: number /** The index of this tick */ index: number } type ChildSnippetProps = { /** The tick items to iterate over and render */ tickItems: TickItem[] /** The currently active thumb */ thumbs: number[] /** * An array of ticks to render * @deprecated Use `tickItems` instead */ ticks: number[] /** Props to apply to the root element */ props: Record<string, unknown> } |
Use render delegation to render your own element. See Child Snippet docs for more information.Default: —— undefined |
| Data Attribute | Value | Description | Details |
|---|---|---|---|
data-orientation |
enum - 'horizontal' | 'vertical' |
The orientation of the slider. | |
data-disabled |
'' |
Present when the slider is disabled. | |
data-slider-root |
'' |
Present on the root element. |
Slider.Range
슬라이더의 범위(range)를 나타내요.
| Property | Type | Description | Details |
|---|---|---|---|
ref $bindable |
HTMLSpanElement |
The underlying DOM element being rendered. You can bind to this to get a reference to the element.Default: null |
|
children |
Snippet |
The children content to render.Default: —— undefined |
|
child |
Snippet - type SnippetProps = { props: Record<string, unknown>; }; |
Use render delegation to render your own element. See Child Snippet docs for more information.Default: —— undefined |
| Data Attribute | Value | Description | Details |
|---|---|---|---|
data-orientation |
enum - 'horizontal' | 'vertical' |
The orientation of the slider. | |
data-disabled |
'' |
Present when the slider is disabled. | |
data-slider-range |
'' |
Present on the range elements. |
Slider.Thumb
슬라이더 위의 썸(thumb)이에요.
| Property | Type | Description | Details |
|---|---|---|---|
index required |
number |
The index of the value this thumb represents.Default: —— undefined |
|
disabled |
boolean |
Whether or not the thumb is disabled.Default: false |
|
ref $bindable |
HTMLSpanElement |
The underlying DOM element being rendered. You can bind to this to get a reference to the element.Default: null |
|
children |
Snippet |
The children content to render.Default: —— undefined |
|
child |
Snippet - type SnippetProps = { props: Record<string, unknown>; }; |
Use render delegation to render your own element. See Child Snippet docs for more information.Default: —— undefined |
| Data Attribute | Value | Description | Details |
|---|---|---|---|
data-orientation |
enum - 'horizontal' | 'vertical' |
The orientation of the slider. | |
data-disabled |
'' |
Present when either the thumb or the slider is disabled. | |
data-active |
'' |
Present when the thumb is active/grabbed. | |
data-slider-thumb |
'' |
Present on the thumb elements. |
Slider.ThumbLabel
슬라이더 썸에 붙는 라벨이에요.
| Property | Type | Description | Details |
|---|---|---|---|
index required |
number |
The index of the thumb this label represents.Default: —— undefined |
|
position |
enum - 'top' | 'bottom' | 'left' | 'right' |
The position of the label relative to the thumb.Default: '`'top'` for horizontal sliders and `'left'` for vertical sliders' |
|
ref $bindable |
HTMLSpanElement |
The underlying DOM element being rendered. You can bind to this to get a reference to the element.Default: null |
|
children |
Snippet |
The children content to render.Default: —— undefined |
|
child |
Snippet - type SnippetProps = { props: Record<string, unknown>; }; |
Use render delegation to render your own element. See Child Snippet docs for more information.Default: —— undefined |
| Data Attribute | Value | Description | Details |
|---|---|---|---|
data-orientation |
enum - 'horizontal' | 'vertical' |
The orientation of the slider. | |
data-disabled |
'' |
Present when either the thumb this label represents or the slider is disabled. | |
data-position |
enum - 'top' | 'bottom' | 'left' | 'right' |
The position of the label relative to the thumb. | |
data-active |
'' |
Present when the thumb this label represents is active. | |
data-value |
'' |
The value of the thumb this label represents. | |
data-slider-thumb-label |
'' |
Present on the thumb label elements. |
Slider.Tick
슬라이더 위의 눈금(tick) 표시예요.
| Property | Type | Description | Details |
|---|---|---|---|
index required |
number |
The index of the tick in the array of ticks provided by the ticks children snippet prop.Default: —— undefined |
|
ref $bindable |
HTMLSpanElement |
The underlying DOM element being rendered. You can bind to this to get a reference to the element.Default: null |
|
children |
Snippet |
The children content to render.Default: —— undefined |
|
child |
Snippet - type SnippetProps = { props: Record<string, unknown>; }; |
Use render delegation to render your own element. See Child Snippet docs for more information.Default: —— undefined |
| Data Attribute | Value | Description | Details |
|---|---|---|---|
data-orientation |
enum - 'horizontal' | 'vertical' |
The orientation of the slider. | |
data-disabled |
'' |
Present when the slider is disabled. | |
data-bounded |
'' |
Present when the tick is bounded (i.e. the tick is less than or equal to the current value). | |
data-value |
'' |
The value the tick represents. | |
data-selected |
'' |
Present when the tick is the same value as one of the thumbs. | |
data-slider-tick |
'' |
Present on the tick elements. |
Slider.TickLabel
슬라이더 눈금에 붙는 라벨이에요.
| Property | Type | Description | Details |
|---|---|---|---|
index required |
number |
The index of the tick in the array of ticks provided by the ticks children snippet prop.Default: —— undefined |
|
position |
enum - 'top' | 'bottom' | 'left' | 'right' |
The position of the tick label.Default: —— undefined |
|
ref $bindable |
HTMLSpanElement |
The underlying DOM element being rendered. You can bind to this to get a reference to the element.Default: null |
|
children |
Snippet |
The children content to render.Default: —— undefined |
|
child |
Snippet - type SnippetProps = { props: Record<string, unknown>; }; |
Use render delegation to render your own element. See Child Snippet docs for more information.Default: —— undefined |
| Data Attribute | Value | Description | Details |
|---|---|---|---|
data-orientation |
enum - 'horizontal' | 'vertical' |
The orientation of the slider. | |
data-disabled |
'' |
Present when the slider is disabled. | |
data-position |
enum - 'top' | 'bottom' | 'left' | 'right' |
The position of the tick label. | |
data-selected |
'' |
Present when the tick this label represents is the same value as one of the thumbs. | |
data-value |
'' |
The value of the tick this label represents. | |
data-bounded |
'' |
Present when the tick this label represents is bounded (i.e. the tick is less than or equal to the current value or within the range of a multiple slider). | |
data-slider-tick-label |
'' |
Present on the tick label elements. |
더 알아보기 (Learn more)
Slider는 범위 값을 다루기 때문에, 같은 범위 선택 계열인 Toggle Group이나 폼 제출과 연결해 쓰는 경우가 많아요. 값 상태를 bind:value로 관리하는 방식은 다른 컴포넌트와 동일하니, 상태 관리 패턴을 익혀 두면 여러 컴포넌트에 그대로 적용할 수 있습니다.