# Fieldset

A native fieldset and legend with linked help, error, requirement copy, and consumer-owned controls.

Access: pro. Category: Forms. Kind: primitive.

## When to use

- Use it when a product interface needs a native fieldset and legend with linked help, error, requirement copy, and consumer-owned controls.
- Choose it when the host application can supply the required state and keep business logic outside the presentation component.

## Alternatives

- Choose form-field instead when a labeled email field with validation and help text is the actual interface need, rather than fieldset.

## Setup for agents

Use React 19 and TypeScript. Initialize shadcn for your framework, then merge this exact entry into components.json:

```json
{
  "registries": {
    "@tidal-pro": {
      "url": "https://tidalui.com/r/pro/{name}.json",
      "headers": {
        "Authorization": "Bearer ${TIDALUI_TOKEN}"
      }
    }
  }
}
```

The namespace must be named **@tidal-pro** because transitive Pro dependencies use that namespace. Obtain an agent key from your active Pro account at https://tidalui.com/account. Keep TIDALUI_TOKEN in your local environment, never in components.json, client code, Git or logs.

```sh
export TIDALUI_TOKEN='your-private-agent-key'
npx shadcn@latest add @tidal-pro/waitlist-form
npx shadcn@latest add https://tidalui.com/r/tidal-button.json
```

Free command: `npx shadcn@latest add https://tidalui.com/r/<name>.json`.
Pro command: `npx shadcn@latest add @tidal-pro/<name>`.

Import the base stylesheet and every stylesheet listed on the installed item's metadata. For example:

```tsx
import "./components/ui/tidal.css";
import "./components/ui/hero-section.css";
// Place installed components inside this wrapper:
<div className="tidal-scope" data-theme="dark">...</div>
```

Omit data-theme for the default light theme. Put the attribute on the same tidal-scope element for dark mode. Every component installs the shared free tidal-base dependency. After upgrading, run `npx shadcn@latest add https://tidalui.com/r/tidal-base.json --overwrite` to receive current tokens. Review local modifications before overwriting.

Vite: Use React + TypeScript. Map @/* to ./src/* in paths and Vite resolve.alias. Import tidal.css and each component stylesheet in your application entry.

Next.js 15 App Router: Next.js App Router: import tidal.css and component CSS in app/layout.tsx. Interactive examples belong in a client component with "use client". Map @/* to ./* or ./src/* to match your project.

TypeScript 6: use paths without baseUrl:

```json
{
  "compilerOptions": {
    "paths": {
      "@/*": [
        "./src/*"
      ]
    }
  }
}
```

Pro registry requests are server/CLI-only. Use the same-origin account interface in a browser; cross-origin Authorization preflights are intentionally unsupported.


## Install Fieldset

```sh
npx shadcn@latest add @tidal-pro/fieldset
```

Stylesheets: `components/ui/tidal.css`, `components/ui/fieldset.css`.

## Minimal example

```tsx
import"./components/ui/tidal.css";
import"./components/ui/fieldset.css";
import{TidalFieldset}from"./components/ui/fieldset";
export default()=><div className="tidal-scope"><TidalFieldset children={"value"} legend={"value"}/></div>;
```

## Structured props

- `TidalFieldset.children: ReactNode`: Required children value accepted by this exported component.
- `TidalFieldset.legend: ReactNode`: Required legend value accepted by this exported component.
- `TidalFieldset.aria-disabled?: Booleanish | undefined`: Accessible disabled supplied by the consumer.
- `TidalFieldset.aria-invalid?: boolean | "true" | "false" | "grammar" | "spelling" | undefined`: Accessible invalid supplied by the consumer.
- `TidalFieldset.contentProps?: Omit<HTMLAttributes<HTMLDivElement>, "children"> | undefined`: Optional content props value accepted by this exported component.
- `TidalFieldset.description?: ReactNode`: Optional description value accepted by this exported component.
- `TidalFieldset.disabled?: boolean | undefined` (default false): Optional disabled value accepted by this exported component.
- `TidalFieldset.error?: ReactNode`: Optional error value accepted by this exported component.
- `TidalFieldset.requirement?: ReactNode`: Optional requirement value accepted by this exported component.

## Complete usage example

[Source](https://tidalui.com/examples/fieldset.tsx) | [Manifest](https://tidalui.com/examples/fieldset.json). Install the listed additional dependencies. Consumer fixture: TypeScript pass; Vite pass. This fixture check is distinct from the actual shadcn install receipt.

```tsx
"use client";

import "./components/ui/tidal.css";

import { useId, useRef, useState, type FormEvent } from "react";

import { TidalFieldset } from "./components/ui/fieldset";

import "./components/ui/fieldset.css";



const tidalExampleStyles = ".tidal-scope .fieldset-demo {\n  container: fieldset-demo / inline-size;\n  width: min(100%, 560px);\n  min-width: 0;\n  color: var(--t-ink);\n}\n\n.tidal-scope .fieldset-demo form {\n  display: grid;\n  gap: 22px;\n}\n\n.tidal-scope .fieldset-demo-footer {\n  display: flex;\n  align-items: center;\n  justify-content: space-between;\n  gap: 14px;\n  min-width: 0;\n}\n\n.tidal-scope .fieldset-demo-footer > p {\n  min-width: 0;\n  margin: 0;\n  color: var(--t-muted);\n  font-size: 11px;\n  line-height: 1.55;\n  overflow-wrap: anywhere;\n}\n\n.tidal-scope .fieldset-demo-footer > div {\n  display: flex;\n  flex: none;\n  gap: 8px;\n}\n\n.tidal-scope .fieldset-demo-footer button {\n  min-height: 44px;\n  padding: 9px 14px;\n  border: 1px solid var(--t-border);\n  border-radius: var(--t-radius-control);\n  background: var(--t-surface);\n  color: var(--t-ink);\n  font: inherit;\n  font-size: 12px;\n  font-weight: 640;\n  cursor: pointer;\n  transition:\n    color 140ms,\n    background-color 140ms,\n    transform 140ms var(--t-ease-out);\n}\n\n.tidal-scope .fieldset-demo-footer button[type=\"submit\"] {\n  border-color: var(--t-ink);\n  background: var(--t-ink);\n  color: var(--t-surface);\n}\n\n.tidal-scope .fieldset-demo-footer button:hover {\n  border-color: var(--t-ink);\n}\n\n.tidal-scope .fieldset-demo-footer button[type=\"submit\"]:hover {\n  background: var(--t-surface);\n  color: var(--t-ink);\n}\n\n.tidal-scope .fieldset-demo-footer button:active {\n  transform: scale(0.98);\n}\n\n.tidal-scope .fieldset-demo-footer button:focus-visible {\n  outline: 2px solid var(--t-accent);\n  outline-offset: 3px;\n}\n\n@container fieldset-demo (max-width: 420px) {\n  .tidal-scope .fieldset-demo-footer {\n    align-items: stretch;\n    flex-direction: column;\n  }\n\n  .tidal-scope .fieldset-demo-footer > div {\n    display: grid;\n    grid-template-columns: repeat(2, minmax(0, 1fr));\n  }\n}\n\n@container fieldset-demo (max-width: 280px) {\n  .tidal-scope .fieldset-demo-footer > div {\n    grid-template-columns: minmax(0, 1fr);\n  }\n}\n\n@media (prefers-reduced-motion: reduce) {\n  \n  .tidal-scope .fieldset-demo-footer button {\n    transition: none;\n  }\n\n  \n  .tidal-scope .fieldset-demo-footer button:active {\n    transform: none;\n  }\n}";

export function FieldsetDemo() {
  const generatedId = useId().replace(/:/g, "");
  const fieldsetRef = useRef<HTMLFieldSetElement>(null);
  const firstRadioRef = useRef<HTMLInputElement>(null);
  const [day, setDay] = useState("");
  const [includeCompleted, setIncludeCompleted] = useState(false);
  const [error, setError] = useState("");
  const [status, setStatus] = useState(
    "Choose a day for the fictional review summary.",
  );

  function submitSample(event: FormEvent<HTMLFormElement>) {
    event.preventDefault();
    if (!day) {
      setError("Choose Monday or Friday.");
      firstRadioRef.current?.focus({ preventScroll: true });
      return;
    }
    setError("");
    setStatus(
      `Local summary preview: ${day}${includeCompleted ? ", including completed work" : ""}.`,
    );
  }

  return (
    <section className="fieldset-demo" aria-label="Fieldset preview">
      <form
        onSubmit={submitSample}
        onReset={() => {
          setDay("");
          setIncludeCompleted(false);
          setError("");
          setStatus("The local sample was reset.");
        }}
        noValidate
      >
        <TidalFieldset
          ref={fieldsetRef}
          legend="Weekly review"
          requirement="Choose one"
          description="Group related controls under one native legend."
          error={error || undefined}
          contentProps={{ className: "fieldset-demo-options" }}
        >
          <label>
            <input
              ref={firstRadioRef}
              type="radio"
              name={`${generatedId}-review-day`}
              value="Monday"
              required
              checked={day === "Monday"}
              onChange={(event) => {
                setDay(event.currentTarget.value);
                setError("");
                setStatus("The sample review day changed locally.");
              }}
            />
            <span>
              <strong>Monday</strong>
              <small>Start the week with active work.</small>
            </span>
          </label>
          <label>
            <input
              type="radio"
              name={`${generatedId}-review-day`}
              value="Friday"
              required
              checked={day === "Friday"}
              onChange={(event) => {
                setDay(event.currentTarget.value);
                setError("");
                setStatus("The sample review day changed locally.");
              }}
            />
            <span>
              <strong>Friday</strong>
              <small>Close the week with a short recap.</small>
            </span>
          </label>
          <label data-kind="checkbox">
            <input
              type="checkbox"
              name="include-completed"
              checked={includeCompleted}
              onChange={(event) => {
                setIncludeCompleted(event.currentTarget.checked);
                setStatus("The local sample options changed.");
              }}
            />
            <span>Include completed work</span>
          </label>
        </TidalFieldset>

        <div className="fieldset-demo-footer">
          <p role="status" aria-live="polite">
            {status}
          </p>
          <div>
            <button type="reset">Reset</button>
            <button type="submit">Review sample</button>
          </div>
        </div>
      </form>
    </section>
  );
}

export default function AgentExample() {
  return (
    <div className="tidal-scope" data-theme="light" dir="ltr">
      <style>{tidalExampleStyles}</style>
      <FieldsetDemo />
    </div>
  );
}

```

## Gotchas

- Keep field state, validation results, submission, and persistence in the host form workflow.

## Theme and accessibility

{"tokens":["--t-accent","--t-border","--t-border-strong","--t-canvas","--t-danger","--t-display","--t-ease-out","--t-ease-spring","--t-faint","--t-font","--t-ink","--t-line","--t-muted","--t-primary","--t-primary-contrast","--t-radius-card","--t-radius-control","--t-radius-overlay","--t-radius-panel","--t-ring","--t-shadow-lg","--t-shadow-soft","--t-soft","--t-subtle","--t-surface","--t-wash"],"darkMode":true}

{"aria":"The component wires labels and relationships from consumer-provided visible text or ARIA props; preserve those labels in production.","notes":"Verify focus visibility, text alternatives, contrast, and reduced motion in the final composition."}

Extends native fieldset attributes except component-owned children, disabled, and disabled/invalid ARIA mirrors; the forwarded ref targets the fieldset. Required legend and children accept ReactNode content. Optional requirement, description, and error ReactNode values preserve numeric zero; description/error receive linked IDs that compose with external aria-describedby. Error or native aria-invalid=true/string true resolves group invalid presentation. Native disabled and aria-disabled=true resolve the fieldset disabled attribute, so browsers propagate disabled behavior to descendant form controls; explicit aria-disabled=false is preserved. Optional contentProps forwards native div attributes/className around the child controls. Requirement is visible copy only and does not invent native constraint validation; consumers put required on the applicable input/select controls. Native fieldset name/form attributes remain available. Consumers own child values, validation, submission, requests, storage, and accepted focus changes.
