Skip to content

Fieldset

Groups fields or choices that answer one question and gives the group a name, so the form reads in parts.

import { Fieldset } from '@sypnia/ui/react'

On this page
  1. A group of choices
  2. Fields about one thing
  3. Parts of a form
  4. When to use it
  5. For everyone
  6. Props

A group of choices

The legend starts the sentence; each option finishes it.

This key can
Code
import { Checkbox, Fieldset } from '@sypnia/ui/react';

export default function Choices() {
  return (
    <Fieldset legend="This key can">
      <Checkbox label="Read rows" defaultChecked />
      <Checkbox label="Add and change rows" defaultChecked />
      <Checkbox label="Delete rows" />
      <Checkbox label="Change tables and columns" description="Give this only to keys that run on your own servers." />
    </Fieldset>
  );
}

Fields about one thing

Four fields of one connection, two by two.

Database to import from
Code
import { Field, Fieldset, FormGrid, Input, PasswordInput } from '@sypnia/ui/react';

// Several fields that describe one thing: the database to import from.
export default function Fields() {
  return (
    <Fieldset legend="Database to import from">
      <FormGrid>
        <Field label="Host"><Input machine defaultValue="db.northwind.io" /></Field>
        <Field label="Port"><Input machine type="number" defaultValue={5432} /></Field>
        <Field label="User"><Input machine autoComplete="off" defaultValue="readonly" /></Field>
        <Field label="Password"><PasswordInput autoComplete="off" /></Field>
      </FormGrid>
    </Fieldset>
  );
}

Parts of a form

Two named parts, one under the other.

The member
What they can do
Code
import { Field, Fieldset, Input, Radio } from '@sypnia/ui/react';

// A form in two named parts. Screen readers say the part's name when focus enters it.
export default function Sections() {
  return (
    <div className="sy-stack">
      <Fieldset legend="The member">
        <Field label="Email"><Input type="email" placeholder="diego@northwind.io" /></Field>
      </Fieldset>
      <Fieldset legend="What they can do">
        <Radio name="member-role" value="editor" label="Editor" description="Changes data and tables." defaultChecked />
        <Radio name="member-role" value="viewer" label="Viewer" description="Reads data." />
      </Fieldset>
    </div>
  );
}

When to use it

Use it when

  • A set of Radio or Checkbox: the legend is the question they answer.
  • Several fields describe one thing: an address, a connection.
  • A long form has parts worth naming.

Do not use it when

  • There is a single field: a Field already has its label.
  • The group needs a border, a title with actions or a footer: that is a Panel.
  • You would nest one inside another: screen readers repeat every legend, which gets long quickly.

For everyone

  • It is the native fieldset with its legend: screen readers say the legend when focus enters the group.
  • Keep the legend short. It is repeated before the first control of the group.

Props

FieldsetTypeDefault
legendrequired ReactNode
className string
  1. A group of choices
  2. Fields about one thing
  3. Parts of a form
  4. When to use it
  5. For everyone
  6. Props

    Search pages, sections and terms