Search docs

Fieldset

Groups related form controls under a legend.

There is no WAI-ARIA APG pattern for fieldsets. Fieldset renders the native <fieldset> and <legend> elements, so the group gets role="group" and is named by its legend.

Shipping method
import { component$, useStyles$ } from '@builder.io/qwik';
import { Fieldset } from '@leve-ui/fieldset';
import styles from './default.css?inline';

export default component$(() => {
  useStyles$(styles);

  return (
    <Fieldset.Root class="fieldset-default">
      <Fieldset.Legend class="fieldset-default-legend">Shipping method</Fieldset.Legend>
      <label class="fieldset-default-option">
        <input class="fieldset-default-radio" type="radio" name="shipping" value="standard" />{' '}
        Standard
      </label>
      <label class="fieldset-default-option">
        <input class="fieldset-default-radio" type="radio" name="shipping" value="express" />{' '}
        Express
      </label>
    </Fieldset.Root>
  );
});

Installation#

Install the individual package, or use @leve-ui/core to get every component at once:

pnpm add @leve-ui/fieldset

Anatomy#

import { Fieldset } from '@leve-ui/fieldset'; // or '@leve-ui/core'

<Fieldset.Root>
  <Fieldset.Legend />
</Fieldset.Root>
PartElementDescription
Fieldset.Root<fieldset>Groups the form controls.
Fieldset.Legend<legend>The label of the group. Place it as the first child of the Root.

Examples#

Disabled#

disabled on the Root disables every form control inside it, like the native <fieldset disabled>. The leve-ui controls inside it (Checkbox, Switch, Radio Group, Toggle, Toggle Group and Field) are disabled too: they render data-disabled and ignore clicks. As in HTML, controls inside the Legend are not disabled by its own Fieldset, and a nested Fieldset is disabled when an ancestor is.

Notifications

API Reference#

Root#

No props of its own. Accepts all <fieldset> attributes.

Data attributeValue
data-leve-fieldsetAlways present
data-disabledPresent when disabled

All props, including disabled, are passed to the native <fieldset>.

Legend#

No props of its own. Accepts all <legend> attributes.

Data attributeValue
data-leve-fieldset-legendAlways present
data-disabledPresent when the Root is disabled

Accessibility#

  • The native <fieldset> has the implicit role="group", and Fieldset.Legend gives the group its accessible name.
  • When the Root is disabled, the controls inside it are disabled and skipped by Tab: native controls by the browser, leve-ui controls through the Fieldset.
  • Fieldset has no keyboard interaction of its own.