Chip
엔터티(개체)를 표현하기 위한 복합 구성(compound composition)을 가진 스타일 없는 칩 컴포넌트예요.
출처: 문서
본문
특징 (Features)
- 다섯 개의 서브 컴포넌트(
Root,Start,Label,End,Remove)를 가진 복합 컴포넌트 API - 내장된 가시성 상태 — 제거되면 칩이 스스로 숨겨져요
- 닫힘(dismissal) 이벤트에 반응하는
onRemove콜백 - 키보드 지원(Enter, Backspace)이 있는
Remove서브 컴포넌트
사용법 (Usage)
import { Chip } from 'primereact/chip';
<Chip.Root>
<Chip.Start />
<Chip.Label />
<Chip.End>
<Chip.Remove />
</Chip.End>
</Chip.Root>
동작 (Behavior)
다형 렌더링 (Polymorphic Rendering)
어떤 서브 컴포넌트든 as를 사용해 렌더링되는 HTML 요소를 바꿀 수 있어요.
<Chip.Root as="span">
<Chip.Label as="span">Tag</Chip.Label>
</Chip.Root>
기본 요소: Root=div, Start=div, Label=div, End=div, Remove=span.
렌더 함수 자식 (Render Function Children)
서브 컴포넌트는 자식으로 렌더 함수를 받아 컴포넌트 인스턴스에 접근할 수 있게 해줘요.
<Chip.Label>{(instance) => <span>{instance.chip?.state.visible ? 'Visible' : 'Hidden'}</span>}</Chip.Label>
Pass Through
<DocPTViewer name="chip-pt" components={['ChipRoot']} />
API
ChipRoot
| Attribute | Value |
|---|---|
data-scope |
chip |
data-part |
root |
| Label | Type | Description |
|---|---|---|
| root | ChipRootPassThroughType<HTMLAttributes> | Used to pass attributes to the root's DOM element. |
| label | ChipRootPassThroughType<HTMLAttributes> | Used to pass attributes to the label's DOM element. |
| remove | ChipRootPassThroughType<HTMLAttributes> | Used to pass attributes to the remove's DOM element. |
| start | ChipRootPassThroughType<HTMLAttributes> | Used to pass attributes to the start's DOM element. |
| end | ChipRootPassThroughType<HTMLAttributes> | Used to pass attributes to the end's DOM element. |
ChipStart
| Label | Type | Description |
|---|---|---|
| root | ChipStartPassThroughType<HTMLAttributes> | Used to pass attributes to the root's DOM element. |
ChipLabel
| Label | Type | Description |
|---|---|---|
| root | ChipLabelPassThroughType<HTMLAttributes> | Used to pass attributes to the root's DOM element. |
ChipEnd
| Label | Type | Description |
|---|---|---|
| root | ChipEndPassThroughType<HTMLAttributes> | Used to pass attributes to the root's DOM element. |
ChipRemove
| Label | Type | Description |
|---|---|---|
| root | ChipRemovePassThroughType<HTMLAttributes> | Used to pass attributes to the root's DOM element. |
접근성 (Accessibility)
스크린 리더 (Screen Reader)
Chip은 기본 접근 가능한 이름으로 label 콘텐츠를 사용해요. 덮어쓰려면 Chip.Root에 aria-label 또는 aria-labelledby를 제공하세요. 제거 가능한 칩은 tabIndex="0"을 가진 포커스 가능한 remove 요소가 있어요.
키보드 지원 (Keyboard Support)
| Key | Function |
|---|---|
enter |
Hides removable chip |
backspace |
Hides removable chip |