> For AI agents: the complete documentation index is available at https://rickyshin93.github.io/tao-ui/zh/llms.txt, the full documentation bundle is available at https://rickyshin93.github.io/tao-ui/zh/llms-full.txt.

# FormSection

数据录入`@rockshin/tao-ui`

[代码演示](#代码演示)[API](#api)

使用标题和说明组织一组相关表单字段。

## 何时使用

复杂表单需要按用户可理解的主题分组时使用 FormSection。

**推荐**

- 区段标题使用用户语言。
- 说明只补充区段目的，不重复字段标签。

**避免**

- 不要为每个单独字段创建区段。

## 代码演示


### 基础用法
```tsx preview
import { FormField, FormSection, Input } from '@rockshin/tao-ui';

function FormSectionExample() {
  return (
    <FormSection title="Profile" description="Information shown to teammates.">
      <FormField label="Display name">
        <Input placeholder="Rihua Chen" />
      </FormField>
      <FormField label="Role">
        <Input placeholder="Product engineer" />
      </FormField>
    </FormSection>
  );
}

export default FormSectionExample;
```

### 多组字段
```tsx preview
import { FormField, FormSection, Input, Stack } from '@rockshin/tao-ui';

function FormSectionGroups() {
  return (
    <Stack gap="lg">
      <FormSection title="Identity" description="How teammates recognize you.">
        <FormField label="Display name">
          <Input placeholder="Rihua Chen" />
        </FormField>
      </FormSection>
      <FormSection
        title="Contact"
        description="Where account notices are sent."
      >
        <FormField label="Email">
          <Input placeholder="you@example.com" />
        </FormField>
      </FormSection>
    </Stack>
  );
}

export default FormSectionGroups;
```

### 语义部件
```tsx preview
import { FormSection } from '@rockshin/tao-ui';

function CustomizedFormSection() {
  return (
    <FormSection
      title="Advanced"
      description="Settings for experienced users."
      styles={{
        root: { maxWidth: 520 },
        title: { fontWeight: 600 },
        body: { paddingTop: 12 },
      }}
    >
      Advanced configuration belongs here.
    </FormSection>
  );
}

export default CustomizedFormSection;
```

### 完整表单组合
组合布局、字段与操作区，用原生提交展示保存结果。
```tsx preview
import { useState } from 'react';
import {
  FormLayout,
  FormSection,
  FormField,
  FormActions,
  Input,
  Textarea,
  Button,
} from '@rockshin/tao-ui';
export default function Example() {
  const [saved, setSaved] = useState('');
  return (
    <form
      onSubmit={(e) => {
        e.preventDefault();
        setSaved(String(new FormData(e.currentTarget).get('name')));
      }}
      onReset={() => setSaved('')}
    >
      <FormLayout>
        <FormSection title="Profile" description="Public workspace information">
          <FormField label="Display name" required>
            <Input name="name" required defaultValue="Alex" />
          </FormField>
          <FormField label="Bio" description="A short introduction">
            <Textarea name="bio" autoSize />
          </FormField>
        </FormSection>
        <FormActions>
          <Button type="reset">Reset</Button>
          <Button type="submit" variant="primary">
            Save
          </Button>
        </FormActions>
        <output aria-live="polite">
          {saved ? `Saved ${saved}` : 'No changes saved'}
        </output>
      </FormLayout>
    </form>
  );
}
```

### 可选说明
标题可独立使用；有必要补充上下文时再显示 description。
```tsx preview
import { FormSection, FormLayout, Input } from '@rockshin/tao-ui';
export default function Example() {
  return (
    <FormLayout>
      <FormSection title="Contact">
        <Input aria-label="Contact address" />
      </FormSection>
      <FormSection
        title="Internal notes"
        description="Visible to workspace members only"
      >
        <Input aria-label="Internal notes" />
      </FormSection>
    </FormLayout>
  );
}
```

### 分组外观
通过 header 与 body 语义部件调整分组样式。
```tsx preview
import { FormSection, FormField, Input } from '@rockshin/tao-ui';
export default function Example() {
  return (
    <FormSection
      title="Billing"
      styles={{
        root: {
          border: '1px solid var(--tao-color-border)',
          borderRadius: 6,
          padding: 16,
        },
        body: { paddingTop: 8 },
      }}
    >
      <FormField label="Company">
        <Input />
      </FormField>
    </FormSection>
  );
}
```

## API


### [#](#formsection)FormSection



| 属性 | 说明 | 类型 | 默认值 |
| --- | --- | --- | --- |
| className | 节点类名 | `string | undefined` | `-` |
| style | 节点样式 | `CSSProperties | undefined` | `-` |

