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.
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.
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.
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.
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.
| Name | Type | Default | Description |
|---|---|---|---|
children | ReactNode | – | |
description | ReactNode | – | Help text after the group, announced on entering it through |
disabled | boolean | false | Native: disables every control inside, with no client code. |
error | ReactNode | – | The group's error, rendered through InlineError and joined to |
errorIcon | ReactNode | – | Replaces the internal error mark ( |
ids | {
description?: string | undefined;
error?: string | undefined;
} | – | Ids replacing the generated ones. |
legend | ReactNode | – | The group's name, a native |
render | RenderProp<FieldsetState> | – | Composition of the root; anything but a |
required | boolean | false | Draws an |
- Also takes every attribute of
<fieldset>exceptchildren;disabledis redeclared above. (Omit<ComponentPropsWithRef<"fieldset">, "children">)
render takes an element, or, in client code, a function of the props and this state (FieldsetState):
| Name | Type | Default | Description |
|---|---|---|---|
disabledrequired | boolean | – | |
invalidrequired | boolean | – | An error message is presented. |
requiredrequired | boolean | – |
Other exports
FieldsetPropstypeimport type { FieldsetProps } from '@nizivo/react/fieldset'The props of
Fieldset, listed above.FieldsetStatetypeimport 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.
| Slot | Rendered by | Data attributes |
|---|---|---|
fieldset.nz-fieldset | Fieldsetroot (takes render) |
|
fieldset-content.nz-fieldset-content | Fieldsetinner element (CSS only) | none |
fieldset-description.nz-fieldset-description | Fieldsetinner element (CSS only) | none |
fieldset-error.nz-fieldset-error | Fieldsetinner element (CSS only) | none |
fieldset-legend.nz-fieldset-legend | Fieldsetinner element (CSS only) | none |
fieldset-required.nz-fieldset-required | Fieldsetinner 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.
| Hook | Default | Read as |
|---|---|---|
--nz-fieldset-description-fg | --nz-text-tertiary |
|
--nz-fieldset-description-font | --nz-font-body-m |
|
--nz-fieldset-gap | --nz-space-3 |
|
--nz-fieldset-legend-fg |
|
|
--nz-fieldset-legend-font | --nz-font-label-m |
|
--nz-fieldset-legend-gap | --nz-space-2 |
|
--nz-fieldset-required-fg | --nz-text-critical |
|
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
Field
The label, help text and error around one form control. A server-safe shell; inside it, Nizivo controls pick up their id, name, flags and description wiring, and native validation messages show inline.
FileUpload
A dropzone over a native file input, with a list of the chosen files. Before any JavaScript runs, a click or a drop chooses files and a plain form submits them; hydrated, it checks each file against accept and maxSize and shows the upload state your code reports for each one.