Introducing PrimeReact v11-alpha 🎉Discover Now

Fieldset

Fieldset is a container component with a legend and optional collapsible content.

Shipping Address
Name
Jane Cooper
Phone
(415) 555-0132
Address
1234 Elm Street, Apt 5B
San Francisco, CA 94102
preview

Installation#

npx shadcn@latest add https://v11.primereact.org/r/fieldset.json

Usage#

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

Examples#

Basic#

Invoice #1024
Design Service$120.00
Hosting$30.00
Total$150.00
basic-demo

Toggleable#

Use Fieldset.Trigger inside the legend to make the fieldset collapsible. The defaultOpen prop sets the initial state, and content visibility is animated by default.

Design Service$120.00
Hosting$30.00
Total$150.00
toggleable-demo

Controlled#

Control fieldset state from outside with the open and onOpenChange props.

Design Service$120.00
Hosting$30.00
Total$150.00
controlled-toggleable-demo

Indicator#

Fieldset.Indicator supports conditional rendering based on fieldset state. Use the match prop to render content only when the state matches.

<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>

Available values: open, closed. Without the match prop, the indicator renders in all states.

Match open / closed

Design Service$120.00
Hosting$30.00
Total$150.00

CSS-only with data attributes

Design Service$120.00
Hosting$30.00
Total$150.00
indicator-demo

Accessibility#

Screen Reader#

Fieldset uses the semantic fieldset element. For toggleable usage, the trigger button uses aria-controls to reference the content region and aria-expanded to reflect visibility state.

Keyboard Support#

KeyFunction
tabMoves focus to the next focusable element in the page tab sequence.
shift + tabMoves focus to the previous focusable element in the page tab sequence.
enterToggles the visibility of the content.
spaceToggles the visibility of the content.