Introducing PrimeReact v11-alpha 🎉Discover Now
styledPanel

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

Usage#

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

Examples#

Basic#

Groups related form elements under a toggleable legend.

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

API#

Sub-Components#

See Primitive API for FieldsetRoot, FieldsetLegend, FieldsetIndicator, FieldsetContent, FieldsetTitle, FieldsetTrigger component documentation.

Hooks#

See Headless API for useFieldset hook documentation.

Accessibility#

See Fieldset Primitive for WAI-ARIA compliance details and keyboard support.