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

Fieldset

원문 보기 위키 갱신

Fieldset은 범례(legend)와 선택적으로 접을 수 있는(collapsible) 콘텐츠를 가진 컨테이너 컴포넌트예요. 관련 항목들을 하나로 묶어 보여줄 때 유용하죠.

출처: 문서

본문

Fieldset은 범례와 선택적으로 접을 수 있는 콘텐츠를 가진 컨테이너 컴포넌트예요.

설치 (Installation)

Shadcn CLI Manual ```bash npx shadcn@latest add https://primereact.dev/r/fieldset.json ``` 프로젝트에 다음 코드를 복사해서 붙여넣으세요. 가져오기(import) 경로를 프로젝트 설정에 맞게 업데이트하세요.

사용법 (Usage)

import { Fieldset, FieldsetContent, FieldsetLegend, FieldsetTitle } from '@/components/ui/fieldset';
<Fieldset>
    <FieldsetLegend>
        <FieldsetTitle>Legend</FieldsetTitle>
    </FieldsetLegend>
    <FieldsetContent />
</Fieldset>

예시 (Examples)

기본 (Basic)

접기 가능 (Toggleable)

범례 안에서 Fieldset.Trigger를 사용하면 fieldset을 접을 수 있게 만들어요. defaultOpen prop이 초기 상태를 설정하며, 콘텐츠 가시성은 기본적으로 애니메이션 처리돼요.

제어 (Controlled)

open과 onOpenChange prop으로 fieldset 상태를 외부에서 제어해요.

표시자 (Indicator)

Fieldset.Indicator는 fieldset 상태에 따른 조건부 렌더링을 지원해요. match prop을 사용하면 상태가 일치할 때만 콘텐츠를 렌더링할 수 있어요.

<Fieldset.Legend>
    <Fieldset.Trigger>
        <Fieldset.Title>Header</Fieldset.Title>
        <Fieldset.Indicator match="open">
            <Minus />
        </Fieldset.Indicator>
        <Fieldset.Indicator match="closed">
            <Plus />
        </Fieldset.Indicator>
    </Fieldset.Trigger>
</Fieldset.Legend>

사용 가능한 값은 open, closed예요. match prop이 없으면 indicator는 모든 상태에서 렌더링돼요.

접근성 (Accessibility)

화면 낭독기 (Screen Reader)

Fieldset은 의미론적(semantic) fieldset 요소를 사용해요. 접기 가능한 용도에서는 트리거 버튼이 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)