Fieldset
A group of fields that belong together under one name: an address, a contact, a set of options. It is the native fieldset, so screen readers announce the name when the focus enters the group, and one attribute disables everything inside. For a single control use the field.
Install
npx shadcn@latest add https://thrumui.dev/r/fieldset.jsonAdds components/ui/fieldset.tsx and installs @base-ui/react@1.9.0. Nothing else in your project changes.
import { Fieldset } from "@/components/ui/fieldset";Props
| Prop | Type | Default | Description |
|---|---|---|---|
Fieldset: disabled | boolean | Default false | Disables every control inside the group, native or not, and dims the labels of the fields in it. |
Fieldset: className | string | – | Extra classes for the group, merged last. It is a column with a 16 pixel gap and no frame, and fills its container. |
Fieldset: ...props | ComponentProps<"fieldset"> | – | Every other fieldset attribute, such as name and form. |
FieldsetLegend | ComponentProps<"div"> | – | The group's name, 16 pixels and semibold. It is a div linked to the fieldset with aria-labelledby. |
FieldsetDescription | ComponentProps<"p"> | – | One or two sentences under the legend in the muted text colour. Place it right after the legend. It is linked to the fieldset with aria-describedby. |
Motion and sound
Motion
- The fieldset does not move.
Sound
Silent. This component makes no sound.
Accessibility
- It is a native fieldset element with the group role. The legend names it, and the description describes it while one is in the page.
- A screen reader announces the name and the description once, when the focus enters the group, then each control's own label.
- The legend is a div, not a legend element, so it can sit in the group's column like any block. The link to the fieldset is the same.
- disabled is the native attribute: the browser takes every control inside out of the tab order and out of the submitted form.
- The legend and the description stay at full contrast in a disabled group. Only the controls and their labels dim.
- Long legends and descriptions wrap. Nothing is cut off at 160 pixels wide.
| Keys | Action |
|---|---|
| Tab | Move through the controls in the group. The group itself takes no focus. Controls in a disabled group are skipped. |
Source
"use client";
import { createContext, useContext, useId, useState, type ComponentProps } from "react";
import { Fieldset as FieldsetPrimitive } from "@base-ui/react/fieldset";
import { cn } from "@/lib/utils";
type Description = { id: string; mount: () => () => void };
const DescriptionContext = createContext<Description | null>(null);
/**
* A group of fields that belong together: an address, a set of options. It is a native `<fieldset>`, named by its legend.
* `disabled` switches off every control inside it at once.
*/
export function Fieldset({ className, "aria-describedby": describedBy, ...props }: FieldsetPrimitive.Root.Props) {
const id = useId();
// The group is described by its description only while one is in the page: an id that points at nothing is an error.
const [described, setDescribed] = useState(false);
const [mount] = useState(() => () => {
setDescribed(true);
return () => setDescribed(false);
});
return (
<DescriptionContext value={{ id, mount }}>
<FieldsetPrimitive.Root
data-slot="fieldset"
aria-describedby={[describedBy, described && id].filter(Boolean).join(" ") || undefined}
// A native fieldset is as wide as its widest child unless it is told otherwise.
className={cn("flex w-full min-w-0 flex-col gap-4 border-0 p-0", className)}
{...props}
/>
</DescriptionContext>
);
}
/** The group's name. A `<div>` linked to the fieldset, so it can be laid out like any block, which a native `<legend>` cannot. */
export function FieldsetLegend({ className, ...props }: FieldsetPrimitive.Legend.Props) {
return <FieldsetPrimitive.Legend data-slot="fieldset-legend" className={cn("text-base leading-5 font-semibold text-foreground [overflow-wrap:anywhere]", className)} {...props} />;
}
/** One or two sentences under the legend. Screen readers read them after the group's name. */
export function FieldsetDescription({ className, ...props }: Omit<ComponentProps<"p">, "id" | "ref">) {
const description = useContext(DescriptionContext);
return (
<p
id={description?.id}
ref={description?.mount}
data-slot="fieldset-description"
// Pulled up to the legend: the two read as one heading, 4 pixels apart.
className={cn("-mt-3 text-sm text-muted-foreground [overflow-wrap:anywhere]", className)}
{...props}
/>
);
}Files and dependencies
- Adds
components/ui/fieldset.tsx- Packages
@base-ui/react@1.9.0- Brings along
- Nothing
Changelog
- 1.0.0 · 2026-12-03First release.