# Fieldset
A labelled group of fields, disabled as one.
Source page: https://dinachi.dev/docs/components/fieldset

## Installation
```bash
npx @dinachi/cli@latest add fieldset
```
Adds to your project:
- `components/ui/fieldset/fieldset.tsx`
- `components/ui/fieldset/index.ts`
Installs:
- `@base-ui/react` ^1.9.0

## Usage
```tsx
import { Field, FieldControl, FieldLabel } from "@/components/ui/field"
import { Fieldset, FieldsetLegend } from "@/components/ui/fieldset"

export function Shipping() {
  return (
    <Fieldset>
      <FieldsetLegend>Shipping address</FieldsetLegend>
      <Field name="street">
        <FieldLabel>Street</FieldLabel>
        <FieldControl />
      </Field>
      <Field name="city">
        <FieldLabel>City</FieldLabel>
        <FieldControl />
      </Field>
    </Fieldset>
  )
}
```

## Anatomy
```tsx
<Fieldset>
  <FieldsetLegend />
  <Field />
</Fieldset>
```
- `Fieldset`: The group, a bordered `<fieldset>`.
- `FieldsetLegend`: The group's name.

## Examples

### Default
A legend over a group of fields.
```tsx
import { Fieldset, FieldsetLegend } from '@/components/ui/fieldset';
import { Field, FieldLabel, FieldControl } from '@/components/ui/field';

export function Example() {
  return (
    <Fieldset className="w-full max-w-sm">
      <FieldsetLegend>Personal Information</FieldsetLegend>
      <Field>
        <FieldLabel>First Name</FieldLabel>
        <FieldControl placeholder="John" />
      </Field>
      <Field>
        <FieldLabel>Last Name</FieldLabel>
        <FieldControl placeholder="Doe" />
      </Field>
    </Fieldset>
  );
}
```

### Groups
Split a long form into labelled sections.
```tsx
import { Fieldset, FieldsetLegend } from '@/components/ui/fieldset';
import { Field, FieldLabel, FieldControl } from '@/components/ui/field';

export function Example() {
  return (
    <div className="w-full max-w-sm space-y-4">
      <Fieldset>
        <FieldsetLegend>Account Details</FieldsetLegend>
        <Field>
          <FieldLabel>Email</FieldLabel>
          <FieldControl type="email" placeholder="you@example.com" />
        </Field>
        <Field>
          <FieldLabel>Username</FieldLabel>
          <FieldControl placeholder="johndoe" />
        </Field>
      </Fieldset>
      <Fieldset>
        <FieldsetLegend>Address</FieldsetLegend>
        <Field>
          <FieldLabel>Street</FieldLabel>
          <FieldControl placeholder="123 Main St" />
        </Field>
        <Field>
          <FieldLabel>City</FieldLabel>
          <FieldControl placeholder="New York" />
        </Field>
      </Fieldset>
    </div>
  );
}
```

## Notes

### Agents
Not a control of its own. The agent reports the legend as `in` on each control inside, so two **City** fields stay distinct: one in **Shipping address**, one in **Billing address**.

## API reference

### Fieldset
The group, a bordered `<fieldset>`.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `disabled` **agent** | `boolean` | `false` | Disables every control inside, native inputs and Fields. |
| `render` | `ReactElement` | - | Swap the element, keep the behaviour. |

### FieldsetLegend
The group's name.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` **agent** | `ReactNode` | - | Also the container name the agent reports for each control inside. |

## Accessibility
- A native `<fieldset>`; the group and its disabled state are announced.
- `FieldsetLegend` is a freely styleable `<div>` that names the fieldset via aria-labelledby.
- Disabled, the browser disables native controls inside and every Field reads the state.

## Source
`components/ui/fieldset/fieldset.tsx`
```tsx
"use client"

import * as React from "react"
import { Fieldset as FieldsetPrimitive } from "@base-ui/react/fieldset"
import { cn } from "@/lib/utils"

const Fieldset = React.forwardRef<
  React.ComponentRef<typeof FieldsetPrimitive.Root>,
  React.ComponentPropsWithoutRef<typeof FieldsetPrimitive.Root>
>(({ className, ...props }, ref) => (
  <FieldsetPrimitive.Root
    ref={ref}
    data-slot="fieldset"
    className={cn("space-y-3 rounded-lg border p-4", className)}
    {...props}
  />
))
Fieldset.displayName = "Fieldset"

const FieldsetLegend = React.forwardRef<
  React.ComponentRef<typeof FieldsetPrimitive.Legend>,
  React.ComponentPropsWithoutRef<typeof FieldsetPrimitive.Legend>
>(({ className, ...props }, ref) => (
  <FieldsetPrimitive.Legend
    ref={ref}
    data-slot="fieldset-legend"
    className={cn("px-1 text-sm font-medium", className)}
    {...props}
  />
))
FieldsetLegend.displayName = "FieldsetLegend"

export { Fieldset, FieldsetLegend }
```
