# Fieldset

> A native fieldset that names a group of related form controls.

```tsx title="hero.tsx"
import { Checkbox } from '@langgenius/dify-ui/checkbox'
import { CheckboxGroup } from '@langgenius/dify-ui/checkbox-group'
import { Field, FieldDescription, FieldItem, FieldLabel } from '@langgenius/dify-ui/field'
import { Fieldset, FieldsetLegend } from '@langgenius/dify-ui/fieldset'

const scopes = [
  {
    label: 'Run apps',
    value: 'apps:run',
    description: 'Invoke published workflows and chatflows.',
  },
  {
    label: 'Read conversations',
    value: 'conversations:read',
    description: 'List messages, annotations and feedback logs.',
  },
  {
    label: 'Manage knowledge',
    value: 'datasets:write',
    description: 'Upload documents and edit indexed chunks.',
  },
]

export function FieldsetHeroDemo() {
  return (
    <Field name="scopes" className="w-full max-w-96">
      <Fieldset render={<CheckboxGroup defaultValue={['apps:run']} />} className="grid gap-3">
        <FieldsetLegend className="pb-0.5">API key scopes</FieldsetLegend>
        {scopes.map((scope) => (
          <FieldItem key={scope.value} className="grid-cols-[auto_1fr] gap-x-2.5 gap-y-0">
            <Checkbox value={scope.value} className="mt-1" />
            <FieldLabel>{scope.label}</FieldLabel>
            <FieldDescription className="col-start-2">{scope.description}</FieldDescription>
          </FieldItem>
        ))}
      </Fieldset>
    </Field>
  )
}
```

## Usage guidelines

- Use `Fieldset` when one question is answered by several controls: a checkbox or radio group, a multi-thumb slider, or a section of related inputs. A single control uses [`Field`](/components/field.md) alone.
- Name the group with `FieldsetLegend`, and keep a label on every control in it. For checkbox and radio options, wrap each option in a `FieldItem` with its own `FieldLabel`.
- Render the group primitive through `render`, as in `render={<CheckboxGroup />}`, so the group element carries the legend name. Pass `value`, `defaultValue` and change handlers to the group primitive; set `disabled` on the outer `Field` to disable the whole grouped field and its labels, or on a `FieldItem` to disable one option.
- Every `Radio` belongs to a `RadioGroup`. Do not render a standalone `Radio`.
- Wrap a checkbox or radio group in a `Field` with a `name` when the group is one form value. The `Field` submits the selected values and carries the group's `validate` and `FieldError`; see [Form](/components/form.md) for the flow.

## Anatomy

```tsx
import { Checkbox } from '@langgenius/dify-ui/checkbox'
import { CheckboxGroup } from '@langgenius/dify-ui/checkbox-group'
import { Field, FieldItem, FieldLabel } from '@langgenius/dify-ui/field'
import { Fieldset, FieldsetLegend } from '@langgenius/dify-ui/fieldset'
```

```tsx
<Field>
  <Fieldset render={<CheckboxGroup />}>
    <FieldsetLegend />
    <FieldItem>
      <FieldLabel>
        <Checkbox />
      </FieldLabel>
    </FieldItem>
  </Fieldset>
</Field>
```

A section of separate inputs uses `Fieldset` without `render` and without an outer `Field`; each input keeps its own `Field`.

## Examples

### Radio options with descriptions

A `FieldItem` scopes a label and a description to one option, so each radio is named by its label and described by its own text. Arrow keys move the selection inside the `RadioGroup`.

```tsx title="radio-group.tsx"
import { Field, FieldDescription, FieldItem, FieldLabel } from '@langgenius/dify-ui/field'
import { Fieldset, FieldsetLegend } from '@langgenius/dify-ui/fieldset'
import { Radio, RadioGroup } from '@langgenius/dify-ui/radio-group'

const retrievalModes = [
  {
    value: 'vector',
    label: 'Vector search',
    description: 'Finds chunks with a similar meaning to the query.',
  },
  {
    value: 'full-text',
    label: 'Full-text search',
    description: 'Matches the exact keywords in the query.',
  },
  {
    value: 'hybrid',
    label: 'Hybrid search',
    description: 'Runs both and reranks the combined results.',
  },
]

export function FieldsetRadioGroupDemo() {
  return (
    <Field name="retrievalMode" className="w-full max-w-96">
      <Fieldset
        render={<RadioGroup defaultValue="hybrid" />}
        className="flex-col items-stretch gap-3"
      >
        <FieldsetLegend className="pb-0.5">Retrieval setting</FieldsetLegend>
        {retrievalModes.map((mode) => (
          <FieldItem key={mode.value} className="grid-cols-[auto_1fr] gap-x-2.5 gap-y-0">
            <Radio value={mode.value} className="mt-1" />
            <FieldLabel>{mode.label}</FieldLabel>
            <FieldDescription className="col-start-2">{mode.description}</FieldDescription>
          </FieldItem>
        ))}
      </Fieldset>
    </Field>
  )
}
```

### Section of related inputs

A plain `Fieldset` groups separate fields under one legend. Each input keeps its own `Field`, label and error.

```tsx title="section.tsx"
import { Field, FieldError, FieldLabel } from '@langgenius/dify-ui/field'
import { Fieldset, FieldsetLegend } from '@langgenius/dify-ui/fieldset'
import { Input } from '@langgenius/dify-ui/input'

export function FieldsetSectionDemo() {
  return (
    <Fieldset className="grid w-full max-w-md grid-cols-1 items-start gap-3.5 sm:grid-cols-[1fr_8rem]">
      <FieldsetLegend className="sm:col-span-2">HTTP proxy</FieldsetLegend>
      <Field name="proxyHost" validationMode="onBlur">
        <FieldLabel>Host</FieldLabel>
        <Input
          required
          defaultValue="proxy.internal.example.com"
          placeholder="proxy.example.com"
          autoComplete="off"
          autoCapitalize="none"
          autoCorrect="off"
          spellCheck={false}
        />
        <FieldError match="valueMissing">Enter a host.</FieldError>
      </Field>
      <Field
        name="proxyPort"
        validationMode="onBlur"
        validate={(value) => {
          const raw = typeof value === 'string' ? value.trim() : ''
          if (!raw) return 'Enter a port.'
          if (!/^\d+$/.test(raw)) return 'Use digits only.'
          const port = Number(raw)
          if (port < 1 || port > 65535) return 'Use a port from 1 to 65535.'
          return null
        }}
      >
        <FieldLabel>Port</FieldLabel>
        <Input inputMode="numeric" defaultValue="3128" placeholder="e.g. 8080" autoComplete="off" />
        <FieldError />
      </Field>
    </Fieldset>
  )
}
```

### Disabled group

Set `disabled` on the outer `Field` so the group, its options and their labels all enter the disabled state. A `FieldDescription` in the outer `Field` explains why and describes every option.

```tsx title="disabled.tsx"
import { Field, FieldDescription, FieldItem, FieldLabel } from '@langgenius/dify-ui/field'
import { Fieldset, FieldsetLegend } from '@langgenius/dify-ui/fieldset'
import { Radio, RadioGroup } from '@langgenius/dify-ui/radio-group'

export function FieldsetDisabledDemo() {
  return (
    <Field name="indexingTechnique" disabled className="w-full max-w-96 gap-2.5">
      <Fieldset
        render={<RadioGroup defaultValue="economical" />}
        className="flex-col items-start gap-2.5"
      >
        <FieldsetLegend>Index method</FieldsetLegend>
        <FieldItem>
          <FieldLabel className="flex items-center gap-2">
            <Radio value="high-quality" />
            High quality
          </FieldLabel>
        </FieldItem>
        <FieldItem>
          <FieldLabel className="flex items-center gap-2">
            <Radio value="economical" />
            Economical
          </FieldLabel>
        </FieldItem>
      </Fieldset>
      <FieldDescription>
        The index method is fixed once a document is embedded with the economical method.
      </FieldDescription>
    </Field>
  )
}
```

## API reference

### Fieldset

Groups a shared legend with related form controls such as checkbox groups or radio groups. Renders a `<fieldset>` element.

Provides group semantics and labeling; pass interactive state such as `disabled` and `value` to the underlying group primitive.

Inherits `className`, `render`, `style` from [Base UI Fieldset.Root](https://base-ui.com/react/components/fieldset#root).

**Data attributes**

| Attribute       | Description                                           |
| --------------- | ----------------------------------------------------- |
| `data-disabled` | Whether the component should ignore user interaction. |

### FieldsetLegend

An accessible label that is automatically associated with the fieldset. Renders a `<div>` element.

Inherits `className`, `render`, `style` from [Base UI Fieldset.Legend](https://base-ui.com/react/components/fieldset#legend).

**Data attributes**

| Attribute       | Description                            |
| --------------- | -------------------------------------- |
| `data-disabled` | Present when the fieldset is disabled. |
