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

Knob — 손잡이 (원형 다이얼)

원문 보기 위키 갱신

SVG 기반 렌더링으로 숫자 입력을 제공하는 스타일 없는 원형 다이얼 컴포넌트예요.

출처: 문서

본문

레이아웃과 스타일링을 완전히 제어하며 완전히 커스텀한 원형 다이얼 컨트롤을 만들어 보세요.

기능 (Features)

  • 네 개의 하위 컴포넌트를 갖춘 복합 컴포넌트 API: Root, Range, Value, Text
  • 계산된 패스가 있는 SVG 기반 호(arc) 렌더링
  • 마우스 드래그, 터치 드래그, 클릭으로 값 설정 상호작용
  • 전체 키보드 탐색(화살표, Home, End, PageUp, PageDown)
  • 구성 가능한 min, max, step, size, stroke width

사용법 (Usage)

import { Knob } from 'primereact/knob';
<Knob.Root>
    <Knob.Range />
    <Knob.Value />
    <Knob.Text />
</Knob.Root>

동작 (Behavior)

다형성 렌더링 (Polymorphic Rendering)

어느 하위 컴포넌트에서든 as를 사용해 렌더링되는 요소를 바꿀 수 있어요.

<Knob.Root as="section"></Knob.Root>

기본 요소: Root=div, Range=path, Value=path, Text=text. SVG 컨테이너는 Root가 자동으로 렌더링해요.

렌더 함수 children (Render Function Children)

Knob.Text는 children으로 렌더 함수를 받아 커스텀 값 포맷팅을 위해 컴포넌트 인스턴스에 접근할 수 있게 해줘요.

<Knob.Text>{(instance) => <>{instance.knob?.state.value}%</>}</Knob.Text>

패스 스루 (Pass Through)

<DocPTViewer name="knob-pt" components={['KnobRoot']} />

API

KnobRoot

Attribute Value
data-scope "knob"
data-part "root"
data-disabled Present when disabled
data-readonly Present when read-only
Label Type Description
root KnobRootPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.
svg KnobRootPassThroughType<HTMLAttributes> Used to pass attributes to the svg's DOM element.
range KnobRootPassThroughType<HTMLAttributes> Used to pass attributes to the range's DOM element.
value KnobRootPassThroughType<HTMLAttributes> Used to pass attributes to the value's DOM element.
text KnobRootPassThroughType<HTMLAttributes> Used to pass attributes to the text's DOM element.

KnobRange

Attribute Value
data-scope "knob"
data-part "range"
Label Type Description
root KnobRangePassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

KnobValue

Attribute Value
data-scope "knob"
data-part "value"
Label Type Description
root KnobValuePassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

KnobText

Attribute Value
data-scope "knob"
data-part "text"
Label Type Description
root KnobTextPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

접근성 (Accessibility)

스크린 리더 (Screen Reader)

Knob은 role="slider"가 있는 SVG 요소를 렌더링하고 현재 상태를 전달하기 위해 aria-valuemin, aria-valuemax, aria-valuenow를 설정해요. ariaLabel 또는 ariaLabelledby로 접근 가능한 이름을 제공해요. 비활성화 또는 읽기 전용일 때는 각각 aria-disabled와 aria-readonly 상태가 적용돼요.

<Knob.Root ariaLabel="Volume" defaultValue={50}></Knob.Root>

이미 보이는 라벨을 렌더링하고 있다면 ariaLabelledby로 연결해요.

<span id="volume-label">Volume</span>
<Knob.Root ariaLabelledby="volume-label" defaultValue={50}></Knob.Root>

키보드 지원 (Keyboard Support)

Key Function
tab Moves focus to the knob.
left/down arrow Decrements the value.
right/up arrow Increments the value.
home Sets the value to min.
end Sets the value to max.
page up Increments the value by 10.
page down Decrements the value by 10.

더 알아보기 (Learn more)