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

# FormField

Data Entry`@rockshin/tao-ui`

[Examples](#examples)[API](#api)

Associates labels, help text, validation state, and controls.

## When to use

Use FormField to provide accessible labeling and status text around a single control.

**Recommended**

- Connect every input with a visible label.
- Keep validation copy specific and actionable.

**Avoid**

- Do not use the component outside its intended interaction model.

## Examples


### Basic usage
```tsx preview
import { FormField, Input } from '@rockshin/tao-ui';

function FormFieldExample() {
  return (
    <FormField
      label="Email"
      required
      description="Used for account notifications."
    >
      <Input placeholder="you@example.com" />
    </FormField>
  );
}

export default FormFieldExample;
```

### Description and error states
```tsx preview
import { FormField, Input, Stack } from '@rockshin/tao-ui';

function FormFieldStates() {
  return (
    <Stack gap="lg" style={{ maxWidth: 420 }}>
      <FormField label="Workspace name" description="Visible to all members.">
        <Input placeholder="Acme Design" />
      </FormField>
      <FormField
        label="Slug"
        required
        error="Use lowercase letters and hyphens only."
      >
        <Input value="Acme Team" error readOnly />
      </FormField>
    </Stack>
  );
}

export default FormFieldStates;
```

### Semantic parts
```tsx preview
import { FormField, Input } from '@rockshin/tao-ui';

function CustomizedFormField() {
  return (
    <FormField
      label="API token"
      description="Stored securely."
      styles={{
        label: { fontWeight: 600 },
        description: { maxWidth: 320 },
      }}
    >
      <Input type="password" value="secret-token" readOnly />
    </FormField>
  );
}

export default CustomizedFormField;
```

### Complete form composition
Compose layout, fields, and actions with native submission feedback.
```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>
  );
}
```

### Error feedback and recovery
Update errors with input while the field label remains associated with its control.
```tsx preview
import { useState } from 'react';
import { FormField, Input } from '@rockshin/tao-ui';
export default function Example() {
  const [value, setValue] = useState('');
  return (
    <FormField
      label="Project code"
      required
      error={value.length < 3 ? 'Enter at least 3 characters' : undefined}
    >
      <Input value={value} onChange={(e) => setValue(e.target.value)} />
    </FormField>
  );
}
```

### Explicit association
Use htmlFor and an input id when integrating existing form identifiers; useId avoids duplicates.
```tsx preview
import { useId } from 'react';
import { FormField, Input } from '@rockshin/tao-ui';
export default function Example() {
  const id = useId();
  return (
    <FormField
      label="Account email"
      htmlFor={id}
      description="Used for account notifications"
    >
      <Input id={id} type="email" />
    </FormField>
  );
}
```

## API


### [#](#formfield)FormField



| Property | Description | Type | Default Value |
| --- | --- | --- | --- |
| className | Additional css class | `string | undefined` | `-` |
| style | Additional style | `CSSProperties | undefined` | `-` |

