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

Fieldset

원문 보기 위키 갱신

의미론적 legend와 선택적 접이식(collapsible) 콘텐츠를 가진 스타일 없고 접근 가능한 fieldset 컴포넌트예요.

출처: 문서

본문

특징 (Features)

  • 여섯 개의 서브 컴포넌트(Root, Legend, Title, Trigger, Indicator, Content)를 가진 복합 컴포넌트 API
  • 네이티브 폼 그룹핑을 위한 의미론적 fieldset/legend HTML 구조

사용법 (Usage)

import { Fieldset } from 'primereact/fieldset';
<Fieldset.Root>
    <Fieldset.Legend>
        <Fieldset.Trigger>
            <Fieldset.Indicator />
            <Fieldset.Title />
        </Fieldset.Trigger>
    </Fieldset.Legend>
    <Fieldset.Content />
</Fieldset.Root>

동작 (Behavior)

모션 애니메이션 (Motion Animation)

열기/닫기 애니메이션을 구성하려면 Root에서 motionProps를 사용하세요.

<Fieldset.Root motionProps={{ name: 'p-collapsible', cssVarPrefix: 'fieldset-content', hideStrategy: 'none' }}>...</Fieldset.Root>

애니메이션 단계, CSS 변수, 숨김 전략에 대해서는 Motion을 참고하세요.

다형 렌더링 (Polymorphic Rendering)

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

<Fieldset.Root as="div">
    <Fieldset.Legend as="div">
        <Fieldset.Title as="h3">...</Fieldset.Title>
    </Fieldset.Legend>
    <Fieldset.Content as="section">...</Fieldset.Content>
</Fieldset.Root>

기본 요소: Root=fieldset, Legend=legend, Title=span, Trigger=button, Content=div, Indicator=span.

렌더 함수 자식 (Render Function Children)

Content는 자식으로 렌더 함수를 받아 컴포넌트 인스턴스에 접근할 수 있게 해줘요. 인스턴스는 fieldset(루트 인스턴스)과 motion(애니메이션 상태)을 노출해요.

<Fieldset.Content>{(instance) => <div>Fieldset is {instance.fieldset?.state.open ? 'open' : 'closed'}</div>}</Fieldset.Content>

Pass Through

<DocPTViewer name="fieldset-pt" components={['FieldsetRoot']} />

API

FieldsetRoot

Attribute Value
data-scope "fieldset"
data-part "root"
data-open Present when expanded
data-closed Present when collapsed
data-disabled Present when disabled
Label Type Description
root FieldsetRootPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.
legend FieldsetRootPassThroughType<HTMLAttributes> Used to pass attributes to the legend's DOM element.
title FieldsetRootPassThroughType<HTMLAttributes> Used to pass attributes to the title's DOM element.
trigger FieldsetRootPassThroughType<HTMLAttributes> Used to pass attributes to the trigger's DOM element.
content FieldsetRootPassThroughType<HTMLAttributes> Used to pass attributes to the content's DOM element.
contentOuter FieldsetRootPassThroughType<HTMLAttributes> Used to pass attributes to the content outer wrapper's DOM element.
contentInner FieldsetRootPassThroughType<HTMLAttributes> Used to pass attributes to the content inner wrapper's DOM element.
indicator FieldsetRootPassThroughType<HTMLAttributes> Used to pass attributes to the indicator's DOM element.

FieldsetLegend

Label Type Description
root FieldsetLegendPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

FieldsetTitle

Label Type Description
root FieldsetTitlePassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

FieldsetTrigger

Attribute Value
data-scope "fieldset"
data-part "trigger"
data-content-open Present when content open
data-content-closed Present when content closed
Label Type Description
root FieldsetTriggerPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

FieldsetIndicator

Attribute Value
data-scope "fieldset"
data-part "indicator"
data-open Present when expanded
data-closed Present when collapsed
Label Type Description
root FieldsetIndicatorPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

FieldsetContent

Attribute Value
data-scope "fieldset"
data-part "content"
data-open Present when expanded
data-closed Present when collapsed
Label Type Description
root FieldsetContentPassThroughType<HTMLAttributes> Used to pass attributes to the root's DOM element.

접근성 (Accessibility)

스크린 리더 (Screen Reader)

Fieldset은 제목에 legend를 사용하는 의미론적 fieldset 요소를 사용해요. 이 네이티브 구조는 추가 ARIA 역할 없이 접근 가능한 그룹핑을 제공해요. 토글 가능한 사용에서는 트리거 버튼이 aria-controls로 콘텐츠 영역을 참조하고 aria-expanded로 가시성 상태를 반영해요.

키보드 지원 (Keyboard Support)

Key Function
tab Moves focus to the next focusable element in the page tab sequence.
shift + tab Moves focus to the previous focusable element in the page tab sequence.
enter Toggles the visibility of the content.
space Toggles the visibility of the content.

더 알아보기 (Learn more)