# Field

> Wraps one control with its label, description and error, and wires the ARIA attributes between them.

Status: stable. Category: Forms.

```ts
import { Field, FieldContext } from '@glyphui/ui'
```

Exports: `Field`, `FieldContext`, `useFieldControl`, `fieldStyles`.

## Notes

- Glyph controls call useFieldControl, so id, required, disabled and aria attributes flow from Field automatically.
- Use useFieldControl in your own controls to get the same wiring.

## Field props

| Prop | Type | Default | Description |
|---|---|---|---|
| `controlId` | `string` |  | Id for the control. Generated when omitted. |
| `description` | `ReactNode` |  |  |
| `disabled` | `boolean` |  |  |
| `error` | `ReactNode` |  | Error message. Marks the control invalid and is announced to screen readers. |
| `label` | `ReactNode` |  |  |
| `labelAction` | `ReactNode` |  | Shown at the end of the label row, outside the label, so it is not part of the control's accessible name. For example a "Forgot password?" link. |
| `orientation` | `"horizontal" \| "vertical"` |  |  |
| `required` | `boolean` |  |  |

## Example: Label and description

```tsx
import { Field, Input } from '@glyphui/ui'

export default function Example() {
  return (
    <Field
      label="Display name"
      description="Shown on your profile and in comments."
      className="max-w-sm"
    >
      <Input defaultValue="Ada Lovelace" />
    </Field>
  )
}
```

## Example: Error

Marks the control aria-invalid and links the message with aria-describedby.

```tsx
import { Field, Input } from '@glyphui/ui'

export default function Example() {
  return (
    <Field
      label="Email"
      required
      description="We send receipts here."
      error="Enter an email address like name@company.com"
      className="max-w-sm"
    >
      <Input type="email" defaultValue="ada@" />
    </Field>
  )
}
```

## Example: Horizontal

Control first, text beside it. For checkboxes and switches.

```tsx
import { Checkbox, Field, Switch } from '@glyphui/ui'

export default function Example() {
  return (
    <div className="grid max-w-sm gap-4">
      <Field
        orientation="horizontal"
        label="Email me about mentions"
        description="At most one email a day."
      >
        <Switch defaultChecked />
      </Field>
      <Field orientation="horizontal" label="I accept the terms of service">
        <Checkbox />
      </Field>
    </div>
  )
}
```

Live page: https://glyphui.xyz/components/field
