# Field

Label, description, error, and control relationships for form fields.

Label, description, error, and control relationships for form fields.

```tsx
import { Field, Grid, Input } from "@zentara-co/zenos-ui";

function FieldExample() {
  return (
    <Grid columns={{ base: 1, md: 3 }} gap="4" className="w-full">
      <Field.Root>
        <Field.Label tooltip="Choose a unique public username." tooltipLabel="Username information">
          Username
        </Field.Label>
        <Field.Control render={<Input defaultValue="Matchalovvers69" />} />
        <Field.Description>Please choose an unique username</Field.Description>
      </Field.Root>
      <Field.Root required invalid>
        <Field.Label>Email Address</Field.Label>
        <Field.Control render={<Input defaultValue="allaroundyou!email.cok" />} />
        <Field.Error>Input a valid email address</Field.Error>
      </Field.Root>
      <Field.Root disabled>
        <Field.Label optional>Spouse</Field.Label>
        <Field.Control render={<Input placeholder="" />} />
      </Field.Root>
    </Grid>
  );
}
```

## Import

```tsx
import { Field, Input } from "@zentara-co/zenos-ui";
```

Field provides the semantic relationship around a control. It owns the label, supporting description, error message, and inherited form state; the rendered control continues to own its value and input behavior.

The field stack uses body-small labels, 4px spacing between label, control, and helper text, and 11px helper or error copy matching the design-system field spec.

## Label affordances

`Field.Label` supports optional `required` (inherits from `Field.Root`), `optional` for `(Optional)` copy, and `tooltip` with `tooltipLabel` for an accessible info trigger beside the label.

## Semantic states

Set `required`, `disabled`, or `invalid` on `Field.Root`. `Field.Control` passes those semantics to its composed control and builds the appropriate `aria-describedby` relationship from the mounted description and error.

```tsx
import { Field, Input, Stack } from "@zentara-co/zenos-ui";

function FieldSemanticStatesExample() {
  return (
    <Stack gap="5" className="w-full max-w-lg">
      <Field.Root required>
        <Field.Label>Security contact</Field.Label>
        <Field.Control render={<Input type="email" defaultValue="security@example.com" />} />
        <Field.Description>Required for incident and recovery notifications.</Field.Description>
      </Field.Root>
      <Field.Root disabled>
        <Field.Label>Organization ID</Field.Label>
        <Field.Control render={<Input defaultValue="org_01HZ9X" />} />
        <Field.Description>Managed by your organization.</Field.Description>
      </Field.Root>
      <Field.Root invalid>
        <Field.Label>Callback URL</Field.Label>
        <Field.Control render={<Input defaultValue="not-a-url" />} />
        <Field.Description>Use an HTTPS endpoint.</Field.Description>
        <Field.Error>Enter a complete URL beginning with https://.</Field.Error>
      </Field.Root>
    </Stack>
  );
}
```

## Native control

`Field.Control` renders an `input` by default, so native attributes remain available when a separate styled input is unnecessary. Supply a stable `id` to `Field.Root` when another part of the application needs to reference the control.

```tsx
import { Field } from "@zentara-co/zenos-ui";

function FieldNativeControlExample() {
  return (
    <Field.Root id="display-name" required className="w-full max-w-lg">
      <Field.Label>Display name</Field.Label>
      <Field.Control
        name="displayName"
        autoComplete="name"
        placeholder="Ada Lovelace"
        className="h-10 rounded-md border border-border bg-input px-3 text-foreground outline-none focus-visible:ring-2 focus-visible:ring-ring"
      />
      <Field.Description>This name is visible to other workspace members.</Field.Description>
    </Field.Root>
  );
}
```

```text
Field.Root
├── Field.Label
├── Field.Control
├── Field.Description
└── Field.Error
```

## Anatomy

```text
Field.Root
Field.Label
Field.Control
Field.Description
Field.Error
```

## API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| Root.id | string | — | Sets the control id and the base for generated supporting-text ids. |
| Root.invalid | boolean | false | Connects error semantics to the control. |
| Root.required | boolean | false | Marks and announces a required field. |
| Root.disabled | boolean | false | Disables composed controls. |
| Control.render | ReactElement \| function | — | Field.Control composes with a native or Zenos control. |
| Control.children | ReactElement | — | Shorthand for supplying a single composed control. |
| Label.required | boolean | — | Shows a required asterisk. Inherits from Field.Root when omitted. |
| Label.optional | boolean \| string | — | Shows optional copy beside the label. true renders (Optional). |
| Label.tooltip | ReactNode | — | Tooltip content for the info trigger beside the label. |
| Label.tooltipLabel | string | — | Accessible name for the info trigger. |
| Label.htmlFor | string | — | Overrides the generated label and control relationship. |
| Error.role | AriaRole | alert | Controls how the error announcement is exposed. |

Unless narrowed above, each DOM-rendering part also accepts its underlying native or Base UI props, including className, style, aria-*, and data-*.

## Accessibility

`Field.Label` targets the generated control id by default. Descriptions are announced with the control, while errors join that relationship only when the root is invalid. `Field.Error` uses `role="alert"` by default for newly surfaced errors. Keep labels visible and meaningful, and set `invalid` only after the application has determined that the current value is invalid.

Source: https://zenos-ui.pages.dev/components/field/