# Field

> Accessible form field container pairing labels, descriptions, and spring-animated validation errors with controls.

Canonical URL: https://taut-ui.com/docs/components/field

```tsx
import {
  Field,
  FieldDescription,
  FieldLabel,
} from "@/components/ui/field";
import { Input } from "@/components/ui/input";

export default function Particle() {
  return (
    <Field>
      <FieldLabel>Workspace URL</FieldLabel>
      <Input placeholder="taut-studio" />
      <FieldDescription>
        Your team will access projects at taut.app/taut-studio.
      </FieldDescription>
    </Field>
  );
}
```

## Installation [#installation]

**CLI**

```bash
npx shadcn@latest add https://taut-ui.com/r/field.json
```

**Manual**

- Install the following dependencies:

```bash
npm install @base-ui/react
```

- Copy and paste the following code into your project.

```tsx title="components/ui/field.tsx"
"use client";

import { Field as FieldPrimitive } from "@base-ui/react/field";
import type React from "react";
import { cn } from "@/lib/utils";

export function Field({
  className,
  ...props
}: FieldPrimitive.Root.Props): React.ReactElement {
  return (
    <FieldPrimitive.Root
      className={cn(
        "group/field flex w-full flex-col items-start gap-1.5 has-[>[data-slot=field-label]>[data-slot=checkbox]]:gap-1",
        className,
      )}
      data-slot="field"
      {...props}
    />
  );
}

export function FieldLabel({
  className,
  ...props
}: FieldPrimitive.Label.Props): React.ReactElement {
  return (
    <FieldPrimitive.Label
      className={cn(
        "inline-flex select-none items-center gap-2.5 font-medium text-foreground text-sm leading-5 has-data-[slot=checkbox]:cursor-pointer has-data-[slot=radio]:cursor-pointer has-data-[slot=switch]:cursor-pointer has-[+[data-shape=pill]]:px-1 data-disabled:pointer-events-none data-disabled:opacity-38 group-data-invalid/field:text-destructive",
        className,
      )}
      data-slot="field-label"
      {...props}
    />
  );
}

export function FieldItem({
  className,
  ...props
}: FieldPrimitive.Item.Props): React.ReactElement {
  return (
    <FieldPrimitive.Item
      className={cn("flex items-center gap-2.5", className)}
      data-slot="field-item"
      {...props}
    />
  );
}

export function FieldDescription({
  className,
  ...props
}: FieldPrimitive.Description.Props): React.ReactElement {
  return (
    <FieldPrimitive.Description
      className={cn(
        "in-[[data-slot=field]:has(>[data-slot=field-label]>[data-slot=checkbox])]:px-0 px-1 in-[[data-slot=field]:has(>[data-slot=field-label]>[data-slot=checkbox])]:ps-7 text-muted-foreground text-xs leading-4 group-has-data-[slot=field-error]/field:hidden data-disabled:opacity-38 group-data-disabled/field:opacity-38 [&>a:hover]:underline [&>a]:text-primary [&>a]:underline-offset-4",
        className,
      )}
      data-slot="field-description"
      {...props}
    />
  );
}

export function FieldError({
  className,
  ...props
}: FieldPrimitive.Error.Props): React.ReactElement {
  return (
    <FieldPrimitive.Error
      className={cn(
        "starting:-translate-y-1 in-[[data-slot=field]:has(>[data-slot=field-label]>[data-slot=checkbox])]:px-0 px-1 in-[[data-slot=field]:has(>[data-slot=field-label]>[data-slot=checkbox])]:ps-7 text-destructive text-xs leading-4 starting:opacity-0 [transition-duration:350ms,150ms] [transition-property:translate,opacity] [transition-timing-function:linear(0,0.5_8%,0.9_20%,1.02_34%,1_60%,1),ease] motion-reduce:transition-none",
        className,
      )}
      data-slot="field-error"
      {...props}
    />
  );
}

export const FieldControl: typeof FieldPrimitive.Control =
  FieldPrimitive.Control;
export const FieldValidity: typeof FieldPrimitive.Validity =
  FieldPrimitive.Validity;

export { FieldPrimitive };
```

- Update the import paths to match your project setup.

## Usage [#usage]

```tsx
import {
  Field,
  FieldDescription,
  FieldError,
  FieldLabel,
} from "@/components/ui/field"
import { Input } from "@/components/ui/input"
```

```tsx
<Field name="email">
  <FieldLabel>Email</FieldLabel>
  <Input required type="email" />
  <FieldDescription>We will never share your email.</FieldDescription>
  <FieldError />
</Field>
```

## Examples [#examples]

### Validation Error [#validation-error]

```tsx
import {
  Field,
  FieldDescription,
  FieldError,
  FieldLabel,
} from "@/components/ui/field";
import { Input } from "@/components/ui/input";

export default function Particle() {
  return (
    <Field invalid>
      <FieldLabel>Work email</FieldLabel>
      <Input defaultValue="lucas@invalid" type="email" />
      <FieldDescription>Use your company email address.</FieldDescription>
      <FieldError match>Please enter a valid email address.</FieldError>
    </Field>
  );
}
```

### Disabled [#disabled]

```tsx
import {
  Field,
  FieldDescription,
  FieldLabel,
} from "@/components/ui/field";
import { Input } from "@/components/ui/input";

export default function Particle() {
  return (
    <Field disabled>
      <FieldLabel>Organization ID</FieldLabel>
      <Input defaultValue="org_01J8K9M2N4P6" />
      <FieldDescription>
        Managed automatically by your workspace administrator.
      </FieldDescription>
    </Field>
  );
}
```

### With Checkbox [#with-checkbox]

```tsx
import { Checkbox } from "@/components/ui/checkbox";
import {
  Field,
  FieldDescription,
  FieldLabel,
} from "@/components/ui/field";

export default function Particle() {
  return (
    <Field>
      <FieldLabel>
        <Checkbox defaultChecked />
        Send release notes
      </FieldLabel>
      <FieldDescription>
        Receive a weekly summary when new components ship.
      </FieldDescription>
    </Field>
  );
}
```

## API Reference [#api-reference]

### Field [#field]

Wraps Base UI `Field.Root`. Connects label, description, error, and control IDs automatically.

| Prop       | Type      | Default | Description                                        |
| ---------- | --------- | ------- | -------------------------------------------------- |
| `name`     | `string`  | -       | Field identifier used for `Form` error mapping     |
| `disabled` | `boolean` | `false` | Disables the field and all descendant controls     |
| `invalid`  | `boolean` | `false` | Forces invalid visual styling across child slots   |
| `validate` | `(value: unknown) => string \| string[] \| null` | - | Custom validation function |

### FieldLabel / FieldDescription / FieldError / FieldItem / FieldControl / FieldValidity [#fieldlabel--fielddescription--fielderror--fielditem--fieldcontrol--fieldvalidity]

Composable primitives from `@base-ui/react/field`. `FieldDescription` automatically hides when a `FieldError` is active.
