본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

슬라이더

원문 보기 위키 갱신

슬라이더 (Slider)

range input처럼 동작하며 스타일링이 쉬운 고품질의 비스타일 React 슬라이더 컴포넌트예요. 레이블, 마커, 세로 방향, 폼 통합까지 지원해요.

출처: Base UI 슬라이더

본문

range input처럼 동작하며 스타일링이 쉬운 고품질의 비스타일 React 슬라이더 컴포넌트예요.

데모

Tailwind

이 예시는 Tailwind CSS로 컴포넌트를 구현하는 방법을 보여줘요.

/* index.tsx */
import { Slider } from '@base-ui/react/slider';

export default function ExampleSlider() {
  return (
    <Slider.Root defaultValue={25}>
      <Slider.Control className="flex w-56 touch-none items-center py-3 select-none">
        <Slider.Track className="h-1 w-full bg-neutral-200 select-none dark:bg-neutral-800">
          <Slider.Indicator className="bg-neutral-950 select-none dark:bg-white" />
          <Slider.Thumb
            aria-label="Volume"
            className="size-4 border border-neutral-950 bg-white select-none has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-offset-2 has-[:focus-visible]:outline-neutral-950 dark:has-[:focus-visible]:outline-white dark:border-white dark:bg-neutral-950"
          />
        </Slider.Track>
      </Slider.Control>
    </Slider.Root>
  );
}

CSS Modules

이 예시는 CSS Modules로 컴포넌트를 구현하는 방법을 보여줘요.

/* index.module.css */
.Control {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  width: 14rem;
  padding-block: 0.75rem;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.Track {
  width: 100%;
  height: 0.25rem;
  background-color: oklch(92.2% 0 0deg);
  -webkit-user-select: none;
  user-select: none;

  @media (prefers-color-scheme: dark) {
    background-color: oklch(26.9% 0 0deg);
  }
}

.Indicator {
  background-color: oklch(14.5% 0 0deg);
  -webkit-user-select: none;
  user-select: none;

  @media (prefers-color-scheme: dark) {
    background-color: white;
  }
}

.Thumb {
  box-sizing: border-box;
  width: 1rem;
  height: 1rem;
  border: 1px solid oklch(14.5% 0 0deg);
  background-color: white;
  -webkit-user-select: none;
  user-select: none;

  @media (prefers-color-scheme: dark) {
    border: 1px solid white;
    background-color: oklch(14.5% 0 0deg);
  }

  &:has(:focus-visible) {
    outline: 2px solid oklch(14.5% 0 0deg);
    outline-offset: 2px;

    @media (prefers-color-scheme: dark) {
      outline-color: white;
    }
  }
}
/* index.tsx */
import { Slider } from '@base-ui/react/slider';
import styles from './index.module.css';

export default function ExampleSlider() {
  return (
    <Slider.Root defaultValue={25}>
      <Slider.Control className={styles.Control}>
        <Slider.Track className={styles.Track}>
          <Slider.Indicator className={styles.Indicator} />
          <Slider.Thumb aria-label="Volume" className={styles.Thumb} />
        </Slider.Track>
      </Slider.Control>
    </Slider.Root>
  );
}

사용 가이드라인

  • 폼 컨트롤에는 접근 가능한 이름이 필요해요: <Slider.Label>을 선호하거나, 눈에 보이는 레이블이 없을 때 각 <Slider.Thumb>에 aria-label을 제공하세요. 슬라이더에 레이블 붙이기와 forms 가이드를 참고하세요.

구조 (Anatomy)

컴포넌트를 임포트하고 파트를 조립해요.

import { Slider } from '@base-ui/react/slider';

<Slider.Root>
  <Slider.Label />
  <Slider.Value />
  <Slider.Control>
    <Slider.Track>
      <Slider.Indicator />
      <Slider.Thumb />
    </Slider.Track>
  </Slider.Control>
</Slider.Root>;

예시

슬라이더에 레이블 붙이기

눈에 보이는 레이블이 없는 단일 썸 슬라이더(예: 볼륨 컨트롤)는 <Slider.Thumb>에 aria-label을 사용해 레이블을 붙일 수 있어요:

<Slider.Root>
  <Slider.Control>
    <Slider.Track>
      <Slider.Indicator />
      {/* @highlight */}
      <Slider.Thumb aria-label="Volume" />
    </Slider.Track>
  </Slider.Control>
</Slider.Root>

눈에 보이는 레이블은 <Slider.Label>로 만들 수 있어요:

<Slider.Root>
  {/* @highlight */}
  <Slider.Label>Volume</Slider.Label>
  <Slider.Control>
    <Slider.Track>
      <Slider.Indicator />
      <Slider.Thumb />
    </Slider.Track>
  </Slider.Control>
</Slider.Root>

눈에 보이는 레이블이 있는 다중 썸 range 슬라이더는 각 <Slider.Thumb>에 aria-label을 추가해 구분하세요:

<Slider.Root defaultValue={[25, 75]}>
  <Slider.Label>Price range</Slider.Label>
  <Slider.Control>
    <Slider.Track>
      <Slider.Indicator />
      {/* @highlight-start */}
      <Slider.Thumb index={0} aria-label="Minimum price" />
      <Slider.Thumb index={1} aria-label="Maximum price" />
      {/* @highlight-end */}
    </Slider.Track>
  </Slider.Control>
</Slider.Root>

Range 슬라이더

range 슬라이더를 만들려면:

  1. 값 배열을 전달하고 배열의 각 값마다 <Slider.Thumb>를 배치하세요
  2. 서버 사이드 렌더링을 위해 각 썸에 값 배열에서 자신의 값 인덱스에 해당하는 숫자 index를 지정하세요

포인터 상호작용 중 썸들이 충돌할 때 다르게 동작하도록 <Slider.Root>의 thumbCollisionBehavior prop으로 설정할 수 있어요.

데모

Tailwind

이 예시는 Tailwind CSS로 컴포넌트를 구현하는 방법을 보여줘요.

/* index.tsx */
import { Slider } from '@base-ui/react/slider';

export default function RangeSlider() {
  return (
    <Slider.Root defaultValue={[25, 45]}>
      <Slider.Control className="flex w-56 touch-none items-center py-3 select-none">
        <Slider.Track className="h-1 w-full bg-neutral-200 select-none dark:bg-neutral-800">
          <Slider.Indicator className="bg-neutral-950 select-none dark:bg-white" />
          <Slider.Thumb
            index={0}
            aria-label="Minimum value"
            className="size-4 border border-neutral-950 bg-white select-none has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-offset-2 has-[:focus-visible]:outline-neutral-950 dark:has-[:focus-visible]:outline-white dark:border-white dark:bg-neutral-950"
          />
          <Slider.Thumb
            index={1}
            aria-label="Maximum value"
            className="size-4 border border-neutral-950 bg-white select-none has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-offset-2 has-[:focus-visible]:outline-neutral-950 dark:has-[:focus-visible]:outline-white dark:border-white dark:bg-neutral-950"
          />
        </Slider.Track>
      </Slider.Control>
    </Slider.Root>
  );
}

CSS Modules

이 예시는 CSS Modules로 컴포넌트를 구현하는 방법을 보여줘요.

/* index.module.css */
.Control {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  width: 14rem;
  padding-block: 0.75rem;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.Track {
  width: 100%;
  height: 0.25rem;
  background-color: oklch(92.2% 0 0deg);
  -webkit-user-select: none;
  user-select: none;

  @media (prefers-color-scheme: dark) {
    background-color: oklch(26.9% 0 0deg);
  }
}

.Indicator {
  background-color: oklch(14.5% 0 0deg);
  -webkit-user-select: none;
  user-select: none;

  @media (prefers-color-scheme: dark) {
    background-color: white;
  }
}

.Thumb {
  box-sizing: border-box;
  width: 1rem;
  height: 1rem;
  border: 1px solid oklch(14.5% 0 0deg);
  background-color: white;
  -webkit-user-select: none;
  user-select: none;

  @media (prefers-color-scheme: dark) {
    border: 1px solid white;
    background-color: oklch(14.5% 0 0deg);
  }

  &:has(:focus-visible) {
    outline: 2px solid oklch(14.5% 0 0deg);
    outline-offset: 2px;

    @media (prefers-color-scheme: dark) {
      outline-color: white;
    }
  }
}
/* index.tsx */
import { Slider } from '@base-ui/react/slider';
import styles from './index.module.css';

export default function RangeSlider() {
  return (
    <Slider.Root defaultValue={[25, 45]}>
      <Slider.Control className={styles.Control}>
        <Slider.Track className={styles.Track}>
          <Slider.Indicator className={styles.Indicator} />
          <Slider.Thumb index={0} aria-label="Minimum value" className={styles.Thumb} />
          <Slider.Thumb index={1} aria-label="Maximum value" className={styles.Thumb} />
        </Slider.Track>
      </Slider.Control>
    </Slider.Root>
  );
}

단계 (Steps)

step prop으로 값을 주어진 증분의 배수에 스냅하고, largeStep으로 Page Up/Page Down 또는 Shift + Arrow Up/Arrow Down을 사용할 때의 증분을 제어해요.

데모

Tailwind

이 예시는 Tailwind CSS로 컴포넌트를 구현하는 방법을 보여줘요.

/* index.tsx */
import { Slider } from '@base-ui/react/slider';

export default function StepsSlider() {
  return (
    <Slider.Root
      className="grid w-56 grid-cols-2"
      defaultValue={400}
      min={100}
      max={900}
      step={100}
      largeStep={200}
    >
      <Slider.Label className="text-sm text-neutral-950 dark:text-white">
        Playback speed
      </Slider.Label>
      <Slider.Value className="text-end text-sm text-neutral-950 dark:text-white" />
      <Slider.Control className="col-span-2 flex touch-none items-center py-3 select-none">
        <Slider.Track className="h-1 w-full bg-neutral-200 select-none dark:bg-neutral-800">
          <Slider.Indicator className="bg-neutral-950 select-none dark:bg-white" />
          <Slider.Thumb className="size-4 border border-neutral-950 bg-white select-none has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-offset-2 has-[:focus-visible]:outline-neutral-950 dark:has-[:focus-visible]:outline-white dark:border-white dark:bg-neutral-950" />
        </Slider.Track>
      </Slider.Control>
    </Slider.Root>
  );
}

CSS Modules

이 예시는 CSS Modules로 컴포넌트를 구현하는 방법을 보여줘요.

/* index.module.css */
.Root {
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: 14rem;
}

.Label {
  font-size: 0.875rem;
  line-height: 1.25rem;
  color: oklch(14.5% 0 0deg);

  @media (prefers-color-scheme: dark) {
    color: white;
  }
}

.Value {
  font-size: 0.875rem;
  line-height: 1.25rem;
  text-align: end;
  color: oklch(14.5% 0 0deg);

  @media (prefers-color-scheme: dark) {
    color: white;
  }
}

.Control {
  box-sizing: border-box;
  display: flex;
  grid-column: span 2;
  align-items: center;
  padding-block: 0.75rem;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.Track {
  width: 100%;
  height: 0.25rem;
  background-color: oklch(92.2% 0 0deg);
  -webkit-user-select: none;
  user-select: none;

  @media (prefers-color-scheme: dark) {
    background-color: oklch(26.9% 0 0deg);
  }
}

.Indicator {
  background-color: oklch(14.5% 0 0deg);
  -webkit-user-select: none;
  user-select: none;

  @media (prefers-color-scheme: dark) {
    background-color: white;
  }
}

.Thumb {
  box-sizing: border-box;
  width: 1rem;
  height: 1rem;
  border: 1px solid oklch(14.5% 0 0deg);
  background-color: white;
  -webkit-user-select: none;
  user-select: none;

  @media (prefers-color-scheme: dark) {
    border: 1px solid white;
    background-color: oklch(14.5% 0 0deg);
  }

  &:has(:focus-visible) {
    outline: 2px solid oklch(14.5% 0 0deg);
    outline-offset: 2px;

    @media (prefers-color-scheme: dark) {
      outline-color: white;
    }
  }
}
/* index.tsx */
import { Slider } from '@base-ui/react/slider';
import styles from './index.module.css';

export default function StepsSlider() {
  return (
    <Slider.Root
      className={styles.Root}
      defaultValue={400}
      min={100}
      max={900}
      step={100}
      largeStep={200}
    >
      <Slider.Label className={styles.Label}>Font weight</Slider.Label>
      <Slider.Value className={styles.Value} />
      <Slider.Control className={styles.Control}>
        <Slider.Track className={styles.Track}>
          <Slider.Indicator className={styles.Indicator} />
          <Slider.Thumb className={styles.Thumb} />
        </Slider.Track>
      </Slider.Control>
    </Slider.Root>
  );
}

마커 (Marks)

자체 눈금(tick mark)을 렌더링하고, 각 마커를 값 범위의 백분율로 트랙을 따라 배치하세요.

데모

Tailwind

이 예시는 Tailwind CSS로 컴포넌트를 구현하는 방법을 보여줘요.

/* index.tsx */
import { Slider } from '@base-ui/react/slider';

const MIN = 0;
const MAX = 100;
const MARKS = [0, 25, 50, 75, 100];

export default function MarksSlider() {
  return (
    <Slider.Root className="w-56" defaultValue={40} min={MIN} max={MAX}>
      <Slider.Control className="flex touch-none items-center py-2.5 select-none">
        <Slider.Track className="h-1 w-full bg-neutral-200 select-none dark:bg-neutral-800">
          <Slider.Indicator className="bg-neutral-950 select-none dark:bg-white" />
          {MARKS.map((mark) => (
            <div
              key={mark}
              aria-hidden
              className="absolute top-1/2 h-2 w-px -translate-x-1/2 -translate-y-1/2 bg-neutral-950 dark:bg-white"
              style={{ left: `${valueToPercent(mark)}%` }}
            />
          ))}
          <Slider.Thumb
            aria-label="Volume"
            className="size-4 border border-neutral-950 bg-white select-none has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-offset-2 has-[:focus-visible]:outline-neutral-950 dark:has-[:focus-visible]:outline-white dark:border-white dark:bg-neutral-950"
          />
        </Slider.Track>
      </Slider.Control>
      <div className="relative h-4 select-none" aria-hidden>
        {MARKS.map((mark) => (
          <span
            key={mark}
            className="absolute -translate-x-1/2 text-xs whitespace-nowrap text-neutral-600 dark:text-neutral-400"
            style={{ left: `${valueToPercent(mark)}%` }}
          >
            {mark}
          </span>
        ))}
      </div>
    </Slider.Root>
  );
}

function valueToPercent(value: number) {
  return ((value - MIN) / (MAX - MIN)) * 100;
}

CSS Modules

이 예시는 CSS Modules로 컴포넌트를 구현하는 방법을 보여줘요.

/* index.module.css */
.Root {
  width: 14rem;
}

.Control {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  padding-block: 0.625rem;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.Track {
  width: 100%;
  height: 0.25rem;
  background-color: oklch(92.2% 0 0deg);
  -webkit-user-select: none;
  user-select: none;

  @media (prefers-color-scheme: dark) {
    background-color: oklch(26.9% 0 0deg);
  }
}

.Indicator {
  background-color: oklch(14.5% 0 0deg);
  -webkit-user-select: none;
  user-select: none;

  @media (prefers-color-scheme: dark) {
    background-color: white;
  }
}

.Thumb {
  box-sizing: border-box;
  width: 1rem;
  height: 1rem;
  border: 1px solid oklch(14.5% 0 0deg);
  background-color: white;
  -webkit-user-select: none;
  user-select: none;

  @media (prefers-color-scheme: dark) {
    border: 1px solid white;
    background-color: oklch(14.5% 0 0deg);
  }

  &:has(:focus-visible) {
    outline: 2px solid oklch(14.5% 0 0deg);
    outline-offset: 2px;

    @media (prefers-color-scheme: dark) {
      outline-color: white;
    }
  }
}

.Mark {
  position: absolute;
  top: 50%;
  width: 1px;
  height: 0.5rem;
  background-color: oklch(14.5% 0 0deg);
  transform: translate(-50%, -50%);

  @media (prefers-color-scheme: dark) {
    background-color: white;
  }
}

.MarkLabels {
  position: relative;
  height: 1rem;
  -webkit-user-select: none;
  user-select: none;
}

.MarkLabel {
  position: absolute;
  top: 0;
  font-size: 0.75rem;
  line-height: 1rem;
  color: oklch(43.9% 0 0deg);
  white-space: nowrap;
  transform: translateX(-50%);

  @media (prefers-color-scheme: dark) {
    color: oklch(70.8% 0 0deg);
  }
}
/* index.tsx */
import { Slider } from '@base-ui/react/slider';
import styles from './index.module.css';

const MIN = 0;
const MAX = 100;
const MARKS = [0, 25, 50, 75, 100];

export default function MarksSlider() {
  return (
    <Slider.Root className={styles.Root} defaultValue={40} min={MIN} max={MAX}>
      <Slider.Control className={styles.Control}>
        <Slider.Track className={styles.Track}>
          <Slider.Indicator className={styles.Indicator} />
          {MARKS.map((mark) => (
            <div
              key={mark}
              aria-hidden
              className={styles.Mark}
              style={{ left: `${valueToPercent(mark)}%` }}
            />
          ))}
          <Slider.Thumb aria-label="Volume" className={styles.Thumb} />
        </Slider.Track>
      </Slider.Control>
      <div className={styles.MarkLabels} aria-hidden>
        {MARKS.map((mark) => (
          <span
            key={mark}
            className={styles.MarkLabel}
            style={{ left: `${valueToPercent(mark)}%` }}
          >
            {mark}
          </span>
        ))}
      </div>
    </Slider.Root>
  );
}

function valueToPercent(value: number) {
  return ((value - MIN) / (MAX - MIN)) * 100;
}

마커는 값의 정밀도와 무관해요—step prop과 함께 사용해 썸이 각 마커에 스냅되게 하세요.

썸 정렬 (Thumb alignment)

thumbAlignment="edge"를 설정하면 값이 min이나 max일 때 썸을 안쪽으로 넣어 그 가장자리가 컨트롤의 가장자리와 정렬되게 해요. 기본 "center" 정렬처럼 컨트롤을 넘치지 않아요.

클라이언트 전용 대안 thumbAlignment="edge-client-only"는 번들 크기를 줄일 수 있지만 React 하이드레이션 이후에만 렌더링돼요.

데모

Tailwind

이 예시는 Tailwind CSS로 컴포넌트를 구현하는 방법을 보여줘요.

/* index.tsx */
import { Slider } from '@base-ui/react/slider';

export default function EdgeAlignedThumb() {
  return (
    <Slider.Root thumbAlignment="edge" defaultValue={25}>
      <Slider.Control className="flex w-56 touch-none items-center py-3 select-none">
        <Slider.Track className="h-1 w-full bg-neutral-200 select-none dark:bg-neutral-800">
          <Slider.Indicator className="bg-neutral-950 select-none dark:bg-white" />
          <Slider.Thumb
            aria-label="Volume"
            className="size-4 border border-neutral-950 bg-white select-none has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-offset-2 has-[:focus-visible]:outline-neutral-950 dark:has-[:focus-visible]:outline-white dark:border-white dark:bg-neutral-950"
          />
        </Slider.Track>
      </Slider.Control>
    </Slider.Root>
  );
}

CSS Modules

이 예시는 CSS Modules로 컴포넌트를 구현하는 방법을 보여줘요.

/* index.module.css */
.Control {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  width: 14rem;
  padding-block: 0.75rem;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.Track {
  width: 100%;
  height: 0.25rem;
  background-color: oklch(92.2% 0 0deg);
  -webkit-user-select: none;
  user-select: none;

  @media (prefers-color-scheme: dark) {
    background-color: oklch(26.9% 0 0deg);
  }
}

.Indicator {
  background-color: oklch(14.5% 0 0deg);
  -webkit-user-select: none;
  user-select: none;

  @media (prefers-color-scheme: dark) {
    background-color: white;
  }
}

.Thumb {
  box-sizing: border-box;
  width: 1rem;
  height: 1rem;
  border: 1px solid oklch(14.5% 0 0deg);
  background-color: white;
  -webkit-user-select: none;
  user-select: none;

  @media (prefers-color-scheme: dark) {
    border: 1px solid white;
    background-color: oklch(14.5% 0 0deg);
  }

  &:has(:focus-visible) {
    outline: 2px solid oklch(14.5% 0 0deg);
    outline-offset: 2px;

    @media (prefers-color-scheme: dark) {
      outline-color: white;
    }
  }
}
/* index.tsx */
import { Slider } from '@base-ui/react/slider';
import styles from './index.module.css';

export default function EdgeAlignedThumb() {
  return (
    <Slider.Root thumbAlignment="edge" defaultValue={25}>
      <Slider.Control className={styles.Control}>
        <Slider.Track className={styles.Track}>
          <Slider.Indicator className={styles.Indicator} />
          <Slider.Thumb aria-label="Volume" className={styles.Thumb} />
        </Slider.Track>
      </Slider.Control>
    </Slider.Root>
  );
}

세로 (Vertical)

<Slider.Root>에 orientation="vertical"을 설정하면 세로 슬라이더를 만들 수 있어요.

데모

Tailwind

이 예시는 Tailwind CSS로 컴포넌트를 구현하는 방법을 보여줘요.

/* index.tsx */
import { Slider } from '@base-ui/react/slider';

export default function VerticalSlider() {
  return (
    <Slider.Root orientation="vertical" defaultValue={35}>
      <Slider.Control className="flex touch-none select-none data-[orientation=vertical]:h-32 data-[orientation=vertical]:px-3">
        <Slider.Track className="bg-neutral-200 select-none dark:bg-neutral-800 data-[orientation=vertical]:h-full data-[orientation=vertical]:w-1">
          <Slider.Indicator className="bg-neutral-950 select-none dark:bg-white" />
          <Slider.Thumb
            aria-label="Volume"
            className="size-4 border border-neutral-950 bg-white select-none has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-offset-2 has-[:focus-visible]:outline-neutral-950 dark:has-[:focus-visible]:outline-white dark:border-white dark:bg-neutral-950"
          />
        </Slider.Track>
      </Slider.Control>
    </Slider.Root>
  );
}

CSS Modules

이 예시는 CSS Modules로 컴포넌트를 구현하는 방법을 보여줘요.

/* index.module.css */
.Control {
  box-sizing: border-box;
  display: flex;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;

  &[data-orientation='vertical'] {
    height: 8rem;
    padding-inline: 0.75rem;
  }
}

.Track {
  background-color: oklch(92.2% 0 0deg);
  -webkit-user-select: none;
  user-select: none;

  @media (prefers-color-scheme: dark) {
    background-color: oklch(26.9% 0 0deg);
  }

  &[data-orientation='vertical'] {
    height: 100%;
    width: 0.25rem;
  }
}

.Indicator {
  background-color: oklch(14.5% 0 0deg);
  -webkit-user-select: none;
  user-select: none;

  @media (prefers-color-scheme: dark) {
    background-color: white;
  }
}

.Thumb {
  box-sizing: border-box;
  width: 1rem;
  height: 1rem;
  border: 1px solid oklch(14.5% 0 0deg);
  background-color: white;
  -webkit-user-select: none;
  user-select: none;

  @media (prefers-color-scheme: dark) {
    border: 1px solid white;
    background-color: oklch(14.5% 0 0deg);
  }

  &:has(:focus-visible) {
    outline: 2px solid oklch(14.5% 0 0deg);
    outline-offset: 2px;

    @media (prefers-color-scheme: dark) {
      outline-color: white;
    }
  }
}
/* index.tsx */
import { Slider } from '@base-ui/react/slider';
import styles from './index.module.css';

export default function VerticalSlider() {
  return (
    <Slider.Root orientation="vertical" defaultValue={35}>
      <Slider.Control className={styles.Control}>
        <Slider.Track className={styles.Track}>
          <Slider.Indicator className={styles.Indicator} />
          <Slider.Thumb aria-label="Volume" className={styles.Thumb} />
        </Slider.Track>
      </Slider.Control>
    </Slider.Root>
  );
}

폼 통합 (Form integration)

폼에서 슬라이더를 사용하려면 슬라이더 name을 <Slider.Root>에 전달하세요:

<Form>
  {/* @highlight */}
  <Slider.Root name="volume">
    <Slider.Label>Volume</Slider.Label>
    <Slider.Control>
      <Slider.Track>
        <Slider.Indicator />
        <Slider.Thumb />
      </Slider.Track>
    </Slider.Control>
  </Slider.Root>
</Form>

폼에서 여러 썸을 가진 그룹 range 슬라이더의 경우 Fieldset이 공유되는 눈에 보이는 레이블을 제공할 수 있고, 각 썸은 자신의 aria-label을 유지해요:

<Field.Root>
  {/* @highlight-start */}
  <Fieldset.Root render={<Slider.Root defaultValue={[25, 75]} />}>
    <Fieldset.Legend>Price range</Fieldset.Legend>
    {/* @highlight-end */}
    <Slider.Control>
      <Slider.Track>
        <Slider.Indicator />
        {/* @highlight-start */}
        <Slider.Thumb index={0} aria-label="Minimum price" />
        <Slider.Thumb index={1} aria-label="Maximum price" />
        {/* @highlight-end */}
      </Slider.Track>
    </Slider.Control>
  </Fieldset.Root>
</Field.Root>

API 레퍼런스

Root

슬라이더의 모든 파트를 묶어요. <div> 요소를 렌더링해요.

Root Props:

Prop Type Default Description
name string - 폼이 제출될 때 필드를 식별해요.
defaultValue number | number[] - 처음 렌더링될 때 슬라이더의 비제어 값. 제어 슬라이더를 렌더링하려면 value prop을 사용하세요.
value number | number[] - 슬라이더의 값. range 슬라이더는 썸마다 하나의 값을 가진 배열을 제공하세요.
onValueChange ((value: number | number[], eventDetails: Slider.Root.ChangeEventDetails) => void) - 슬라이더 값이 변경될 때 호출되는 콜백 함수예요. 첫 번째 인자로 새 값을 받고, 발생한 이벤트는 eventDetails.event로 접근할 수 있어요. 값은 폼 통합을 위해 eventDetails.event.target.value에도 반영돼요. eventDetails.reason은 변경을 유발한 것을 나타내요: 'input-change' 숨겨진 range input이 change 이벤트를 발생시킬 때(예: 폼 통합)'track-press' 컨트롤 트랙을 눌렀을 때'drag' 썸을 드래그하는 동안'keyboard' 키보드 입력'none' 특정 상호작용 없이 변경이 트리거될 때
onValueCommitted ((value: number | number[], eventDetails: Slider.Root.CommitEventDetails) => void) - 값 변경이 커밋될 때 호출되는 콜백 함수예요. 값이 변경되지 않았거나 변경이 취소되면 호출되지 않아요. 주의: 이것은 change 이벤트가 아니라 일반(commit) 이벤트예요. eventDetails.reason이 커밋을 유발한 것을 나타내요: 'drag' 썸을 드래그하는 동안'track-press' 컨트롤 트랙을 눌렀을 때'keyboard' 키보드 입력'input-change' 숨겨진 range input이 change 이벤트를 발생시킬 때(예: 폼 통합)'none' 특정 상호작용 없이 커밋이 발생할 때
form string - 슬라이더 input을 소유하는 폼을 식별해요. 슬라이더가 폼 밖에 렌더링될 때 유용해요.
locale Intl.LocalesArgument - 값 형식화 시 Intl.NumberFormat이 사용하는 로케일. 기본값은 사용자 런타임 로케일이에요.
thumbAlignment 'center' | 'edge' | 'edge-client-only' 'center' 값이 min이나 max일 때 Slider.Control에 대한 썸(들)의 정렬 방식: center: 썸의 중심이 컨트롤 가장자리와 정렬돼요edge: 썸이 컨트롤 안쪽으로 들어가 그 가장자리가 컨트롤 가장자리와 정렬돼요edge-client-only: edge와 같지만 React 하이드레이션 후 클라이언트에서 렌더링되어 번들 크기를 줄여줘요
thumbCollisionBehavior 'push' | 'swap' | 'none' 'push' 포인터 상호작용 중 썸들이 충돌할 때의 동작을 제어해요. 'push' (기본): 썸들이 서로를 밀지만, 다시 드래그했을 때 이전 위치로 복원하지 않아요.'swap': 썸들이 서로를 지나칠 때 위치를 교환해요.'none': 썸들이 서로를 지나칠 수 없고, 초과 움직임은 무시돼요.
step number 1 슬라이더가 값을 단계적으로 이동할 수 있는 증분. ("discrete" 슬라이더) min prop이 유효 값의 기준점이 돼요. (max - min)이 step으로 균등하게 나누어지길 권장해요.
largeStep number 10 Page Up/Page Down 또는 Shift + Arrow Up/Arrow Down을 사용할 때 슬라이더가 값을 단계적으로 이동할 수 있는 증분.
minStepsBetweenValues number 0 range 슬라이더에서 값 사이의 최소 단계 수.
min number 0 슬라이더의 최소 허용 값. max와 같지 않아야 해요.
max number 100 슬라이더의 최대 허용 값. min과 같지 않아야 해요.
format Intl.NumberFormatOptions - 값을 형식화할 옵션.
disabled boolean false 슬라이더가 사용자 상호작용을 무시할지 여부.
orientation Orientation 'horizontal' 컴포넌트 방향.
className string | ((state: Slider.Root.State) => string | undefined) - 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태에 따라 클래스를 반환하는 함수.
style React.CSSProperties | ((state: Slider.Root.State) => React.CSSProperties | undefined) - 요소에 적용되는 스타일, 또는 컴포넌트 상태에 따라 스타일 객체를 반환하는 함수.
render ReactElement | ((props: HTMLProps, state: Slider.Root.State) => ReactElement) - 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요.

Root Data Attributes:

Attribute Type Description
data-dragging - 사용자가 드래그하는 동안 존재해요.
data-orientation 'horizontal' | 'vertical' 슬라이더의 방향을 나타내요.
data-disabled - 슬라이더가 비활성화되었을 때 존재해요.
data-valid - 슬라이더가 유효 상태일 때 존재해요 (Field.Root로 감싸졌을 때).
data-invalid - 슬라이더가 유효하지 않은 상태일 때 존재해요 (Field.Root로 감싸졌을 때).
data-dirty - 슬라이더 값이 변경되었을 때 존재해요 (Field.Root로 감싸졌을 때).
data-touched - 슬라이더가 터치되었을 때 존재해요 (Field.Root로 감싸졌을 때).
data-focused - 슬라이더가 포커스되었을 때 존재해요 (Field.Root로 감싸졌을 때).

Root.Props

Root props의 재내보내기예요.

Root.State

type SliderRootState = {
  /** The index of the active thumb. */
  activeThumbIndex: number;
  /** Whether the component should ignore user interaction. */
  disabled: boolean;
  /** Whether the thumb is currently being dragged. */
  dragging: boolean;
  /** The maximum value. */
  max: number;
  /** The minimum value. */
  min: number;
  /**
   * The minimum steps between values in a range slider.
   * @default 0
   */
  minStepsBetweenValues: number;
  /** The component orientation. */
  orientation: Orientation;
  /**
   * The step increment of the slider when incrementing or decrementing. It will snap
   * to multiples of this value. Decimal values are supported.
   * @default 1
   */
  step: number;
  /** The raw number value of the slider. */
  values: number[];
  /** Whether the field has been touched. */
  touched: boolean;
  /** Whether the field value has changed from its initial value. */
  dirty: boolean;
  /** Whether the field is valid. */
  valid: boolean | null;
  /** Whether the field has a value. */
  filled: boolean;
  /** Whether the field is focused. */
  focused: boolean;
};

Root.ChangeEventReason

type SliderRootChangeEventReason = 'input-change' | 'track-press' | 'drag' | 'keyboard' | 'none';

Root.ChangeEventDetails

type SliderRootChangeEventDetails = (
  | { reason: 'none'; event: Event }
  | { reason: 'input-change'; event: Event | InputEvent }
  | { reason: 'track-press'; event: PointerEvent | MouseEvent | TouchEvent }
  | { reason: 'drag'; event: PointerEvent | TouchEvent }
  | { reason: 'keyboard'; event: KeyboardEvent }
) & {
  /** Cancels Base UI from handling the event. */
  cancel: () => void;
  /** Allows the event to propagate in cases where Base UI will stop the propagation. */
  allowPropagation: () => void;
  /** Indicates whether the event has been canceled. */
  isCanceled: boolean;
  /** Indicates whether the event is allowed to propagate. */
  isPropagationAllowed: boolean;
  /** The element that triggered the event, if applicable. */
  trigger: Element | undefined;
  /** The index of the active thumb at the time of the change. */
  activeThumbIndex: number;
};

Root.CommitEventReason

type SliderRootCommitEventReason = 'input-change' | 'track-press' | 'drag' | 'keyboard' | 'none';

Root.CommitEventDetails

type SliderRootCommitEventDetails =
  | { reason: 'none'; event: Event }
  | { reason: 'input-change'; event: Event | InputEvent }
  | { reason: 'track-press'; event: PointerEvent | MouseEvent | TouchEvent }
  | { reason: 'drag'; event: PointerEvent | TouchEvent }
  | { reason: 'keyboard'; event: KeyboardEvent };

Value

슬라이더의 현재 값을 텍스트로 표시해요. <output> 요소를 렌더링해요.

Value Props:

Prop Type Default Description
children ((formattedValues: string[], values: number[]) => React.ReactNode) | null - -
className string | ((state: Slider.Value.State) => string | undefined) - 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태에 따라 클래스를 반환하는 함수.
style React.CSSProperties | ((state: Slider.Value.State) => React.CSSProperties | undefined) - 요소에 적용되는 스타일, 또는 컴포넌트 상태에 따라 스타일 객체를 반환하는 함수.
render ReactElement | ((props: HTMLProps, state: Slider.Value.State) => ReactElement) - 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요.

Value Data Attributes:

Attribute Type Description
data-dragging - 사용자가 드래그하는 동안 존재해요.
data-orientation 'horizontal' | 'vertical' 슬라이더의 방향을 나타내요.
data-disabled - 슬라이더가 비활성화되었을 때 존재해요.
data-valid - 슬라이더가 유효 상태일 때 존재해요 (Field.Root로 감싸졌을 때).
data-invalid - 슬라이더가 유효하지 않은 상태일 때 존재해요 (Field.Root로 감싸졌을 때).
data-dirty - 슬라이더 값이 변경되었을 때 존재해요 (Field.Root로 감싸졌을 때).
data-touched - 슬라이더가 터치되었을 때 존재해요 (Field.Root로 감싸졌을 때).
data-focused - 슬라이더가 포커스되었을 때 존재해요 (Field.Root로 감싸졌을 때).

Value.Props

Value props의 재내보내기예요.

Value.State

type SliderValueState = {
  /** The index of the active thumb. */
  activeThumbIndex: number;
  /** Whether the component should ignore user interaction. */
  disabled: boolean;
  /** Whether the thumb is currently being dragged. */
  dragging: boolean;
  /** The maximum value. */
  max: number;
  /** The minimum value. */
  min: number;
  /**
   * The minimum steps between values in a range slider.
   * @default 0
   */
  minStepsBetweenValues: number;
  /** The component orientation. */
  orientation: Orientation;
  /**
   * The step increment of the slider when incrementing or decrementing. It will snap
   * to multiples of this value. Decimal values are supported.
   * @default 1
   */
  step: number;
  /** The raw number value of the slider. */
  values: number[];
  /** Whether the field has been touched. */
  touched: boolean;
  /** Whether the field value has changed from its initial value. */
  dirty: boolean;
  /** Whether the field is valid. */
  valid: boolean | null;
  /** Whether the field has a value. */
  filled: boolean;
  /** Whether the field is focused. */
  focused: boolean;
};

Indicator

슬라이더의 현재 값을 시각화해요. <div> 요소를 렌더링해요.

Indicator Props:

Prop Type Default Description
className string | ((state: Slider.Indicator.State) => string | undefined) - 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태에 따라 클래스를 반환하는 함수.
style React.CSSProperties | ((state: Slider.Indicator.State) => React.CSSProperties | undefined) - 요소에 적용되는 스타일, 또는 컴포넌트 상태에 따라 스타일 객체를 반환하는 함수.
render ReactElement | ((props: HTMLProps, state: Slider.Indicator.State) => ReactElement) - 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요.

Indicator Data Attributes:

Attribute Type Description
data-dragging - 사용자가 드래그하는 동안 존재해요.
data-orientation 'horizontal' | 'vertical' 슬라이더의 방향을 나타내요.
data-disabled - 슬라이더가 비활성화되었을 때 존재해요.
data-valid - 슬라이더가 유효 상태일 때 존재해요 (Field.Root로 감싸졌을 때).
data-invalid - 슬라이더가 유효하지 않은 상태일 때 존재해요 (Field.Root로 감싸졌을 때).
data-dirty - 슬라이더 값이 변경되었을 때 존재해요 (Field.Root로 감싸졌을 때).
data-touched - 슬라이더가 터치되었을 때 존재해요 (Field.Root로 감싸졌을 때).
data-focused - 슬라이더가 포커스되었을 때 존재해요 (Field.Root로 감싸졌을 때).

Indicator.Props

Indicator props의 재내보내기예요.

Indicator.State

type SliderIndicatorState = {
  /** The index of the active thumb. */
  activeThumbIndex: number;
  /** Whether the component should ignore user interaction. */
  disabled: boolean;
  /** Whether the thumb is currently being dragged. */
  dragging: boolean;
  /** The maximum value. */
  max: number;
  /** The minimum value. */
  min: number;
  /**
   * The minimum steps between values in a range slider.
   * @default 0
   */
  minStepsBetweenValues: number;
  /** The component orientation. */
  orientation: Orientation;
  /**
   * The step increment of the slider when incrementing or decrementing. It will snap
   * to multiples of this value. Decimal values are supported.
   * @default 1
   */
  step: number;
  /** The raw number value of the slider. */
  values: number[];
  /** Whether the field has been touched. */
  touched: boolean;
  /** Whether the field value has changed from its initial value. */
  dirty: boolean;
  /** Whether the field is valid. */
  valid: boolean | null;
  /** Whether the field has a value. */
  filled: boolean;
  /** Whether the field is focused. */
  focused: boolean;
};

Track

슬라이더 인디케이터를 담고 슬라이더의 전체 범위를 나타내요. <div> 요소를 렌더링해요.

Track Props:

Prop Type Default Description
className string | ((state: Slider.Track.State) => string | undefined) - 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태에 따라 클래스를 반환하는 함수.
style React.CSSProperties | ((state: Slider.Track.State) => React.CSSProperties | undefined) - 요소에 적용되는 스타일, 또는 컴포넌트 상태에 따라 스타일 객체를 반환하는 함수.
render ReactElement | ((props: HTMLProps, state: Slider.Track.State) => ReactElement) - 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요.

Track Data Attributes:

Attribute Type Description
data-dragging - 사용자가 드래그하는 동안 존재해요.
data-orientation 'horizontal' | 'vertical' 슬라이더의 방향을 나타내요.
data-disabled - 슬라이더가 비활성화되었을 때 존재해요.
data-valid - 슬라이더가 유효 상태일 때 존재해요 (Field.Root로 감싸졌을 때).
data-invalid - 슬라이더가 유효하지 않은 상태일 때 존재해요 (Field.Root로 감싸졌을 때).
data-dirty - 슬라이더 값이 변경되었을 때 존재해요 (Field.Root로 감싸졌을 때).
data-touched - 슬라이더가 터치되었을 때 존재해요 (Field.Root로 감싸졌을 때).
data-focused - 슬라이더가 포커스되었을 때 존재해요 (Field.Root로 감싸졌을 때).

Track.Props

Track props의 재내보내기예요.

Track.State

type SliderTrackState = {
  /** The index of the active thumb. */
  activeThumbIndex: number;
  /** Whether the component should ignore user interaction. */
  disabled: boolean;
  /** Whether the thumb is currently being dragged. */
  dragging: boolean;
  /** The maximum value. */
  max: number;
  /** The minimum value. */
  min: number;
  /**
   * The minimum steps between values in a range slider.
   * @default 0
   */
  minStepsBetweenValues: number;
  /** The component orientation. */
  orientation: Orientation;
  /**
   * The step increment of the slider when incrementing or decrementing. It will snap
   * to multiples of this value. Decimal values are supported.
   * @default 1
   */
  step: number;
  /** The raw number value of the slider. */
  values: number[];
  /** Whether the field has been touched. */
  touched: boolean;
  /** Whether the field value has changed from its initial value. */
  dirty: boolean;
  /** Whether the field is valid. */
  valid: boolean | null;
  /** Whether the field has a value. */
  filled: boolean;
  /** Whether the field is focused. */
  focused: boolean;
};

Thumb

인디케이터 끝에 있는 슬라이더의 드래그 가능한 부분이에요. <div> 요소와 중첩된 <input type="range">를 렌더링해요.

Thumb Props:

Prop Type Default Description
aria-valuetext string - input의 aria-valuetext 속성으로 전달되는 문자열 값. getAriaValueText가 제공되면 무시돼요.
getAriaLabel ((index: number) => string) | null - input의 aria-label 속성에 대한 문자열 값을 반환하는 함수.
getAriaValueText ((formattedValue: string, value: number, index: number) => string) | null - input의 aria-valuetext 속성에 대한 문자열 값을 반환하는 함수. 스크린 리더 사용자에게 중요해요.
index number - 값이 value 또는 defaultValue 배열에 있을 때 자신의 값 인덱스에 해당하는 썸의 인덱스. 다중 썸 range 슬라이더의 서버 사이드 렌더링을 지원하려면 이 prop이 필요해요.
onBlur React.FocusEventHandler<HTMLInputElement> - input에 전달되는 blur 핸들러.
onFocus React.FocusEventHandler<HTMLInputElement> - input에 전달되는 focus 핸들러.
onKeyDown React.KeyboardEventHandler<HTMLInputElement> - input에 전달되는 keydown 핸들러.
tabIndex number - input에 전달되는 선택적 tab index 속성.
disabled boolean false 썸이 사용자 상호작용을 무시할지 여부.
inputRef React.Ref<HTMLInputElement> - 중첩된 input 요소에 접근하는 ref.
className string | ((state: Slider.Thumb.State) => string | undefined) - 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태에 따라 클래스를 반환하는 함수.
style React.CSSProperties | ((state: Slider.Thumb.State) => React.CSSProperties | undefined) - 요소에 적용되는 스타일, 또는 컴포넌트 상태에 따라 스타일 객체를 반환하는 함수.
render ReactElement | ((props: HTMLProps, state: Slider.Thumb.State) => ReactElement) - 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요.

index Prop Example:

<Slider.Root value={[10, 20]}>
  <Slider.Thumb index={0} />
  <Slider.Thumb index={1} />
</Slider.Root>

Thumb Data Attributes:

Attribute Type Description
data-dragging - 사용자가 드래그하는 동안 존재해요.
data-orientation 'horizontal' | 'vertical' 슬라이더의 방향을 나타내요.
data-disabled - 슬라이더가 비활성화되었을 때 존재해요.
data-valid - 슬라이더가 유효 상태일 때 존재해요 (Field.Root로 감싸졌을 때).
data-invalid - 슬라이더가 유효하지 않은 상태일 때 존재해요 (Field.Root로 감싸졌을 때).
data-dirty - 슬라이더 값이 변경되었을 때 존재해요 (Field.Root로 감싸졌을 때).
data-touched - 슬라이더가 터치되었을 때 존재해요 (Field.Root로 감싸졌을 때).
data-focused - 슬라이더가 포커스되었을 때 존재해요 (Field.Root로 감싸졌을 때).
data-index - range 슬라이더에서 썸의 인덱스를 나타내요.

Thumb.Props

Thumb props의 재내보내기예요.

Thumb.State

type SliderThumbState = {
  /** The index of the active thumb. */
  activeThumbIndex: number;
  /** Whether the component should ignore user interaction. */
  disabled: boolean;
  /** Whether the thumb is currently being dragged. */
  dragging: boolean;
  /** The maximum value. */
  max: number;
  /** The minimum value. */
  min: number;
  /**
   * The minimum steps between values in a range slider.
   * @default 0
   */
  minStepsBetweenValues: number;
  /** The component orientation. */
  orientation: Orientation;
  /**
   * The step increment of the slider when incrementing or decrementing. It will snap
   * to multiples of this value. Decimal values are supported.
   * @default 1
   */
  step: number;
  /** The raw number value of the slider. */
  values: number[];
  /** Whether the field has been touched. */
  touched: boolean;
  /** Whether the field value has changed from its initial value. */
  dirty: boolean;
  /** Whether the field is valid. */
  valid: boolean | null;
  /** Whether the field has a value. */
  filled: boolean;
  /** Whether the field is focused. */
  focused: boolean;
};

Control

슬라이더의 클릭 가능하고 상호작용적인 부분이에요. <div> 요소를 렌더링해요.

Control Props:

Prop Type Default Description
className string | ((state: Slider.Control.State) => string | undefined) - 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태에 따라 클래스를 반환하는 함수.
style React.CSSProperties | ((state: Slider.Control.State) => React.CSSProperties | undefined) - 요소에 적용되는 스타일, 또는 컴포넌트 상태에 따라 스타일 객체를 반환하는 함수.
render ReactElement | ((props: HTMLProps, state: Slider.Control.State) => ReactElement) - 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요.

Control Data Attributes:

Attribute Type Description
data-dragging - 사용자가 드래그하는 동안 존재해요.
data-orientation 'horizontal' | 'vertical' 슬라이더의 방향을 나타내요.
data-disabled - 슬라이더가 비활성화되었을 때 존재해요.
data-valid - 슬라이더가 유효 상태일 때 존재해요 (Field.Root로 감싸졌을 때).
data-invalid - 슬라이더가 유효하지 않은 상태일 때 존재해요 (Field.Root로 감싸졌을 때).
data-dirty - 슬라이더 값이 변경되었을 때 존재해요 (Field.Root로 감싸졌을 때).
data-touched - 슬라이더가 터치되었을 때 존재해요 (Field.Root로 감싸졌을 때).
data-focused - 슬라이더가 포커스되었을 때 존재해요 (Field.Root로 감싸졌을 때).

Control.Props

Control props의 재내보내기예요.

Control.State

type SliderControlState = {
  /** The index of the active thumb. */
  activeThumbIndex: number;
  /** Whether the component should ignore user interaction. */
  disabled: boolean;
  /** Whether the thumb is currently being dragged. */
  dragging: boolean;
  /** The maximum value. */
  max: number;
  /** The minimum value. */
  min: number;
  /**
   * The minimum steps between values in a range slider.
   * @default 0
   */
  minStepsBetweenValues: number;
  /** The component orientation. */
  orientation: Orientation;
  /**
   * The step increment of the slider when incrementing or decrementing. It will snap
   * to multiples of this value. Decimal values are supported.
   * @default 1
   */
  step: number;
  /** The raw number value of the slider. */
  values: number[];
  /** Whether the field has been touched. */
  touched: boolean;
  /** Whether the field value has changed from its initial value. */
  dirty: boolean;
  /** Whether the field is valid. */
  valid: boolean | null;
  /** Whether the field has a value. */
  filled: boolean;
  /** Whether the field is focused. */
  focused: boolean;
};

Label

슬라이더 썸들과 자동으로 연결되는 접근 가능한 레이블이에요. <div> 요소를 렌더링해요.

Label Props:

Prop Type Default Description
className string | ((state: Slider.Root.State) => string | undefined) - 요소에 적용되는 CSS 클래스, 또는 컴포넌트 상태에 따라 클래스를 반환하는 함수.
style React.CSSProperties | ((state: Slider.Root.State) => React.CSSProperties | undefined) - 요소에 적용되는 스타일, 또는 컴포넌트 상태에 따라 스타일 객체를 반환하는 함수.
render ReactElement | ((props: HTMLProps, state: Slider.Root.State) => ReactElement) - 컴포넌트의 HTML 요소를 다른 태그로 대체하거나 다른 컴포넌트와 합성할 수 있게 해줘요. ReactElement 또는 렌더링할 요소를 반환하는 함수를 받아요.

Label.Props

Label props의 재내보내기예요.

Label.State

type SliderLabelState = {
  /** The index of the active thumb. */
  activeThumbIndex: number;
  /** Whether the component should ignore user interaction. */
  disabled: boolean;
  /** Whether the thumb is currently being dragged. */
  dragging: boolean;
  /** The maximum value. */
  max: number;
  /** The minimum value. */
  min: number;
  /**
   * The minimum steps between values in a range slider.
   * @default 0
   */
  minStepsBetweenValues: number;
  /** The component orientation. */
  orientation: Orientation;
  /**
   * The step increment of the slider when incrementing or decrementing. It will snap
   * to multiples of this value. Decimal values are supported.
   * @default 1
   */
  step: number;
  /** The raw number value of the slider. */
  values: number[];
  /** Whether the field has been touched. */
  touched: boolean;
  /** Whether the field value has changed from its initial value. */
  dirty: boolean;
  /** Whether the field is valid. */
  valid: boolean | null;
  /** Whether the field has a value. */
  filled: boolean;
  /** Whether the field is focused. */
  focused: boolean;
};

추가 타입 (Additional Types)

SliderRootChangeEventCustomProperties

type SliderRootChangeEventCustomProperties = {
  /** The index of the active thumb at the time of the change. */
  activeThumbIndex: number;
};

ThumbMetadata

type ThumbMetadata = { inputId: string | undefined };

External Types

Orientation

type Orientation = 'horizontal' | 'vertical';

내보내기 그룹 (Export Groups)

  • Slider.Root: Slider.Root, Slider.Root.State, Slider.Root.Props, Slider.Root.ChangeEventReason, Slider.Root.ChangeEventDetails, Slider.Root.CommitEventReason, Slider.Root.CommitEventDetails
  • Slider.Label: Slider.Label, Slider.Label.State, Slider.Label.Props
  • Slider.Value: Slider.Value, Slider.Value.State, Slider.Value.Props
  • Slider.Control: Slider.Control, Slider.Control.State, Slider.Control.Props
  • Slider.Track: Slider.Track, Slider.Track.State, Slider.Track.Props
  • Slider.Thumb: Slider.Thumb, Slider.Thumb.State, Slider.Thumb.Props
  • Slider.Indicator: Slider.Indicator, Slider.Indicator.State, Slider.Indicator.Props
  • Default: SliderRootState, SliderRootProps, SliderRootChangeEventCustomProperties, SliderRootChangeEventReason, SliderRootChangeEventDetails, SliderRootCommitEventReason, SliderRootCommitEventDetails, SliderLabelState, SliderLabelProps, SliderValueState, SliderValueProps, SliderControlState, SliderControlProps, SliderTrackState, SliderTrackProps, ThumbMetadata, SliderThumbState, SliderThumbProps, SliderIndicatorState, SliderIndicatorProps

Canonical Types

Canonical: Alias 매핑 — Canonical의 네임스페이스가 이미 임포트되어 있으면 Canonical을, 아니면 Alias를 사용하세요.

  • Slider.Root.State: SliderRootState
  • Slider.Root.Props: SliderRootProps
  • Slider.Root.ChangeEventReason: SliderRootChangeEventReason
  • Slider.Root.ChangeEventDetails: SliderRootChangeEventDetails
  • Slider.Root.CommitEventReason: SliderRootCommitEventReason
  • Slider.Root.CommitEventDetails: SliderRootCommitEventDetails
  • Slider.Label.State: SliderLabelState
  • Slider.Label.Props: SliderLabelProps
  • Slider.Value.State: SliderValueState
  • Slider.Value.Props: SliderValueProps
  • Slider.Control.State: SliderControlState
  • Slider.Control.Props: SliderControlProps
  • Slider.Track.State: SliderTrackState
  • Slider.Track.Props: SliderTrackProps
  • Slider.Thumb.State: SliderThumbState
  • Slider.Thumb.Props: SliderThumbProps
  • Slider.Indicator.State: SliderIndicatorState
  • Slider.Indicator.Props: SliderIndicatorProps

더 알아보기 (Learn more)