Skip to content
Nizivo UI

Fieldset

A native fieldset and legend for related controls, such as a row of switches or checkboxes, with a shared description and error. Disabling it disables every control inside, with no client code.

Server component, no client JS

Import

import { Fieldset } from '@nizivo/react/fieldset';

// Once per app (Getting started), after
// @nizivo/tokens/tokens.css and @nizivo/react/css/base.css and @nizivo/react/css/inline-error.css
import '@nizivo/react/css/fieldset.css';

Static or interactive

Server. It ships no client JavaScript when a Server Component renders it, in every Next.js build mode; its code is bundled only when a client component (a 'use client' file) imports it. disabled is the native attribute, so it disables the controls inside with no script; the controls themselves ship their own code (a Checkbox or a Switch is client kind). How to choose.

In a client app (a Vite or React Router single-page app, or a 'use client' file) it is an ordinary React component: event handlers, refs and state work as usual. In a client app.

Examples

Basic

A checkbox group: the legend names it, the description is read on entering it.

Notify me about
Emails go to the store owner.
import type { JSX } from 'react';
import { Checkbox } from '@nizivo/react/checkbox';
import { Fieldset } from '@nizivo/react/fieldset';

export function FieldsetExample(): JSX.Element {
  return (
    <Fieldset legend="Notify me about" description="Emails go to the store owner.">
      <Checkbox name="notify" value="orders" defaultChecked>
        New orders
      </Checkbox>
      <Checkbox name="notify" value="stock">
        Low stock
      </Checkbox>
    </Fieldset>
  );
}

Error

An error returned by the server for the whole group, joined to the group's description.

Sales channels
Choose at least one channel.
import type { JSX } from 'react';
import { Checkbox } from '@nizivo/react/checkbox';
import { Fieldset } from '@nizivo/react/fieldset';

export function FieldsetErrorExample(): JSX.Element {
  return (
    <Fieldset legend="Sales channels" required error="Choose at least one channel.">
      <Checkbox name="channel" value="online">
        Online store
      </Checkbox>
      <Checkbox name="channel" value="pos">
        Point of sale
      </Checkbox>
    </Fieldset>
  );
}

Disabled

Disabled: the native fieldset disables every control inside, with no client code.

Wholesale
Available on the Plus plan.
import type { JSX } from 'react';
import { Checkbox } from '@nizivo/react/checkbox';
import { Fieldset } from '@nizivo/react/fieldset';

export function FieldsetDisabledExample(): JSX.Element {
  return (
    <Fieldset legend="Wholesale" description="Available on the Plus plan." disabled>
      <Checkbox name="wholesale" value="tiers">
        Tiered prices
      </Checkbox>
      <Checkbox name="wholesale" value="net30">
        Net 30 invoices
      </Checkbox>
    </Fieldset>
  );
}

Props

Server component Renders data-slot="fieldset" with the class nz-fieldset. Props: FieldsetProps. Source: src/fieldset/fieldset.tsx.

NameTypeDefaultDescription
childrenReactNode–
descriptionReactNode–

Help text after the group, announced on entering it through aria-describedby.

disabledbooleanfalse

Native: disables every control inside, with no client code.

errorReactNode–

The group's error, rendered through InlineError and joined to aria-describedby; sets data-invalid. Not a live region (§16.5). null, false and '' present no error.

errorIconReactNode–

Replaces the internal error mark (circle-x). Decorative.

ids{ description?: string | undefined; error?: string | undefined; }–

Ids replacing the generated ones.

legendReactNode–

The group's name, a native <legend>.

renderRenderProp<FieldsetState>–

Composition of the root; anything but a <fieldset> loses native disabled.

requiredbooleanfalse

Draws an aria-hidden mark after the legend; the controls inside carry required.

  • Also takes every attribute of <fieldset> except children; disabled is redeclared above. (Omit<ComponentPropsWithRef<"fieldset">, "children">)

render takes an element, or, in client code, a function of the props and this state (FieldsetState):

NameTypeDefaultDescription
disabledrequiredboolean–
invalidrequiredboolean–

An error message is presented.

requiredrequiredboolean–

Other exports

FieldsetProps type

import type { FieldsetProps } from '@nizivo/react/fieldset'

The props of Fieldset, listed above.

FieldsetState type

import type { FieldsetState } from '@nizivo/react/fieldset'

The render state of Fieldset, listed above.

Data attributes and slots

Style parts by class (.nz-<slot>) and state by data attribute. Attribute meanings come from contracts/vocabulary.json.

SlotRendered byData attributes
fieldset
.nz-fieldset
Fieldset
root (takes render)
  • data-disabled (present or absent) ← disabled
    Mirrors the disabled attribute
  • data-invalid (present or absent)
    An error message is currently presented (not "fails constraints"); always the Field's own state, never the engine's
  • data-required (present or absent) ← required
    Mirrors the required attribute
fieldset-content
.nz-fieldset-content
Fieldset
inner element (CSS only)
none
fieldset-description
.nz-fieldset-description
Fieldset
inner element (CSS only)
none
fieldset-error
.nz-fieldset-error
Fieldset
inner element (CSS only)
none
fieldset-legend
.nz-fieldset-legend
Fieldset
inner element (CSS only)
none
fieldset-required
.nz-fieldset-required
Fieldset
inner element (CSS only)
none

CSS hooks

Set a hook on the component's class or any ancestor to restyle it without specificity games; leave it unset for the default shown.

HookDefaultRead as
--nz-fieldset-description-fg--nz-text-tertiary
  • color on .nz-fieldset-description
--nz-fieldset-description-font--nz-font-body-m
  • font on .nz-fieldset-description
--nz-fieldset-gap--nz-space-3
  • gap on .nz-fieldset-content
--nz-fieldset-legend-fg
  • default: var(--nz-text-primary)
  • default: var(--nz-text-disabled)
  • color on .nz-fieldset-legend
--nz-fieldset-legend-font--nz-font-label-m
  • font on .nz-fieldset-legend
--nz-fieldset-legend-gap--nz-space-2
  • margin-block-start on .nz-fieldset-legend + .nz-fieldset-content
--nz-fieldset-required-fg--nz-text-critical
  • color on .nz-fieldset-required

Layers: nz.components. Classes: .nz-fieldset, .nz-fieldset-content, .nz-fieldset-description, .nz-fieldset-legend, .nz-fieldset-required.

Tokens this stylesheet reads (9)

--nz-font-body-m, --nz-font-label-m, --nz-space-0-5, --nz-space-2, --nz-space-3, --nz-text-critical, --nz-text-disabled, --nz-text-primary, --nz-text-tertiary

Accessibility

Nothing in this component takes focus or keyboard input.

Keyboard

None.

Figma

Node ids from design/component-map.json, which nz gen writes from component.json. The links open the Nizivo Figma library, which may ask you to sign in.

  • Canonical: none
  • Ghost masters: none

On this page