Fieldset
- How
- A native
<fieldset class=“sdc-fieldset”>with a<legend>and an optional.sdc-fieldset__desctied to it witharia-describedby.Fieldset.astrowrites it. - When
- Whenever two or more controls only make sense together: a set of Choice chips, a pair of date fields, a name split across two inputs.
- Where
- Inside a form, around the controls it names.
Why not a heading
Section titled “Why not a heading”A heading above a group of controls is read as a heading. It is not announced as the group’s name, so someone moving control to control hears “Call me, checkbox” with nothing saying what the question was. A legend is announced with each control in the group, which is the whole point of it.
The legend takes .sdc-display-3, the display face at
heading size, so it reads like the heading it replaces while still being a
legend element. The default browser border and padding are removed, which is
safe: none of the grouping behaviour lives in the border.
In code
Section titled “In code”src/components/ui/Fieldset.astro.
---import Fieldset from '../../components/ui/Fieldset.astro';---<Fieldset legend="How should people reach you?" desc="Pick as many as you like."> <div class="sdc-choice-set">…</div></Fieldset>| Prop | Type | Default | What it does |
|---|---|---|---|
legend |
string | required | The group’s name |
desc |
string | none | One line under the legend, tied with aria-describedby |
id |
string | from the legend | Only needed when desc is set and the legend is not unique |
Checks before you ship
Section titled “Checks before you ship”- The legend says what the group is asking, not what the page is about.
- A screen reader announces the legend with each control.
- There is no heading duplicating the legend directly above it.