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

Slider

원문 보기 위키 갱신

복합 구성(compound composition)을 가진 스타일 없고 접근 가능한 슬라이더 컴포넌트예요.

출처: 문서

본문

특징 (Features)

  • 네 개의 서브 컴포넌트(Root, Track, Range, Handle)를 가진 복합 컴포넌트 API
  • 여러 핸들의 단일 값 및 범위(range) 모드
  • 가로 및 세로 방향
  • 구성 가능한 스텝 크기와 최소 핸들 간격

사용법 (Usage)

import { Slider } from 'primereact/slider';
<Slider.Root>
    <Slider.Track>
        <Slider.Range />
    </Slider.Track>
    <Slider.Handle />
</Slider.Root>

동작 (Behavior)

다형 렌더링 (Polymorphic Rendering)

어떤 서브 컴포넌트든 as를 사용해 렌더링되는 HTML 요소를 바꿀 수 있어요.

<Slider.Root as="div">
    <Slider.Track as="div">
        <Slider.Range as="div" />
    </Slider.Track>
    <Slider.Handle as="div" />
</Slider.Root>

기본 요소: Root=span, Track=span, Range=span, Handle=span.

렌더 함수 자식 (Render Function Children)

Handle은 자식으로 렌더 함수를 받아 컴포넌트 인스턴스에 접근할 수 있게 해줘요. 인스턴스는 slider(state.value와 state.isDragging을 가진 루트 인스턴스)를 노출해요.

<Slider.Handle>{(instance) => <span>{instance.slider?.getHandleValue(0)}</span>}</Slider.Handle>

Pass Through

<DocPTViewer name="slider-pt" components={['SliderRoot']} />

API

SliderRoot

Attribute Value
data-orientation "horizontal" or "vertical"
data-disabled Present when disabled
data-dragging Present when dragging
Label Type Description
root SliderRootPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.
range SliderRootPassThroughType<HTMLAttributes> Used to pass attributes to the range's DOM element.
handle SliderRootPassThroughType<HTMLAttributes> Used to pass attributes to the handle's DOM element.

SliderTrack

Attribute Value
data-orientation "horizontal" or "vertical"
data-disabled Present when disabled
data-dragging Present when dragging
Label Type Description
root SliderTrackPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

SliderRange

Attribute Value
data-orientation "horizontal" or "vertical"
data-disabled Present when disabled
data-dragging Present when dragging
Label Type Description
root SliderRangePassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

SliderHandle

Attribute Value
data-index Handle index number
data-orientation "horizontal" or "vertical"
data-disabled Present when disabled
data-dragging Present when dragging
Label Type Description
root SliderHandlePassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

접근성 (Accessibility)

스크린 리더 (Screen Reader)

Slider 컴포넌트는 내부적으로 slider 역할을 가진 네이티브 range 입력을 사용해요. 이 입력은 aria-orientation, aria-valuemin, aria-valuemax, aria-valuenow 속성을 포함해요. 컴포넌트를 설명하는 값은 Handle의 aria-labelledby와 aria-label props으로 정의할 수 있어요.

<span id="slider_label">Volume</span>
<Slider.Root>
    <Slider.Track>
        <Slider.Range />
    </Slider.Track>
    <Slider.Handle aria-labelledby="slider_label" />
</Slider.Root>

<Slider.Root>
    <Slider.Track>
        <Slider.Range />
    </Slider.Track>
    <Slider.Handle aria-label="Volume" />
</Slider.Root>

키보드 지원 (Keyboard Support)

Key Function
tab Moves focus to the slider.
left arrow / up arrow Decrements the value.
right arrow / down arrow Increments the value.
home Set the minimum value.
end Set the maximum value.
page up Increments the value by 10 steps.
page down Decrements the value by 10 steps.

더 알아보기 (Learn more)