Label — 폼 컨트롤을 위한 접근성 높은 라벨 컴포넌트
Label은 폼 컨트롤을 위한 접근성 있는 텍스트 라벨을 제공해요. htmlFor로 라벨을 폼 컨트롤의 id에 연결하면 스크린 리더 등 접근성 도구와 잘 연동됩니다.
출처: 문서
본문
Label은 폼 컨트롤을 위한 접근성 있는 텍스트 라벨(accessible text label)을 제공해요. htmlFor를 사용해 라벨을 폼 컨트롤의 id에 연결할 수 있어요.
사용법 (Usage)
import { Label } from '@primereact/ui/label';
<Label />
예시
기본 (Basic)
폼 컨트롤과 연결되는 접근성 있는 라벨 요소예요.
필수 표시 (Required)
required나 aria-required로 입력 시맨틱은 유지하면서, 라벨 콘텐츠에 필수(required) 표시를 넣을 수 있어요.
래퍼 (Wrapper)
Label이 폼 컨트롤을 감싸면 htmlFor 없이도 암시적으로 연결돼요. 카드 스타일의 선택형 옵션을 만들 때 유용해요.
비활성화 (Disabled)
컨트롤과 라벨이 형제(sibling) 관계이거나 컨테이너에 data-disabled가 있을 때, Label은 연결된 컨트롤의 비활성화 상태를 자동으로 반영해요.
접근성 (Accessibility)
스크린 리더 (Screen Reader)
Label은 네이티브 label 요소를 렌더링해요. htmlFor로 폼 컨트롤 id와 연결하거나, 폼 컨트롤을 라벨 안에 감싸면 돼요.
키보드 지원 (Keyboard Support)
이 컴포넌트는 대화형 요소를 포함하지 않아요.
Label API
Label 컴포넌트의 API 문서예요.
Label
Props
| Name | Type | Default | Description |
|---|---|---|---|
| ref | Ref<unknown> | null | The reference to the component instance. |
| pIf | boolean | true | Whether the component should be rendered. |
| style | CSSProperties \| ((instance?: LabelInstance) => undefined \| CSSProperties) | null | The style to apply to the component. |
| className | string \| ((instance?: LabelInstance) => undefined \| string) | null | The class name to apply to the component. |
| as | null \| string \| number \| bigint \| boolean \| ComponentClass<any, any> \| FunctionComponent<any> \| ReactElement<unknown, string \| JSXElementConstructor<any>> \| Iterable<ReactNode, any, any> \| ReactPortal \| Promise<AwaitedReactNode> | null | The component type to render. |
| asChild | boolean | false | Whether the component should be rendered as a child component. |
| instance | LabelInstance | null | The instance to pass to the component. |
| pt | SafeRecord<LabelPassThrough> | null | The pass-through props to pass to the component. |
| ptOptions | PassThroughOptions | null | The pass-through options to pass to the component. |
| unstyled | boolean | null | Whether the component should be rendered without classes. |
| dt | unknown | null | The design token to use for the component. |
| styles | StylesOptions<ComponentInstance> | null | The styles to use for the component. |
| render | (instance: LabelInstance) => ReactNode | null | The render function to render the component with instance access. |
| children | any | null | The children to render. |
Accepts React.ReactNode for static content or a render function (instance: I) => React.ReactNode for instance access.
Typed as any to avoid JSX type errors when used directly in templates. |
| [key: string] | any | null | |
| pt-{optionName}-* | - | null | Pass through attributes for customizing component. For more info, see Pass Through tab. |
State
Exposes
| Name | Type | Default | Description |
|---|---|---|---|
| rootProps | UseLabelRootProps | null | Pre-built data attribute props for the root element. |
Interfaces
| Label | Description | Data |
|---|---|---|
| PassThroughOptions | Defines passthrough(pt) options of Label component. | [object Object] |
Types
| Label | Description | Data |
|---|---|---|
| Instance | Instance of Label component. | [object Object] |
useLabel
Props
State
Exposes
Interfaces
Types
테마 (Theming)
CSS 클래스 (CSS Classes)
styled 모드에서 사용하는 클래스 이름 목록이에요.
| ClassName | Description |
|---|---|
| p-label | Class name of the root element |
디자인 토큰 (Design Tokens)
디자인 토큰 목록이에요.
| Token | CSS Variable | Description |
|---|---|---|
| label.gap | --p-label-gap | Gap of root |
| label.font.size | --p-label-font-size | Font size of root |
| label.font.weight | --p-label-font-weight | Font weight of root |
| label.text.color | --p-label-text-color | Text color of root |
| label.disabled.opacity | --p-label-disabled-opacity | Disabled opacity of root |