Field

Arrange labels and messages freely. Your app owns validation; Field connects the result to the control.

$ npx @beaket/ui add field

Used only for account notifications.

Source
"use client";

import { Field } from "@/components/ui/field";
import { Input } from "@/components/ui/input";

export default function Example() {
  return (
    <Field label="Email" hint="Used only for account notifications." className="max-w-sm">
      {(id) => <Input id={id} type="email" placeholder="you@example.com" />}
    </Field>
  );
}

Examples

All States

Used only for account notifications.

Enter a valid email address.

This value cannot be changed.

Source
"use client";

import { Field } from "@/components/ui/field";
import { Input } from "@/components/ui/input";

export default function Example() {
  return (
    <div className="max-w-sm space-y-8">
      <Field invalid>
        <Field.Label>Email</Field.Label>
        <Field.Control>
          <Input type="email" defaultValue="not-an-email" />
        </Field.Control>
        <div className="space-y-1">
          <Field.Hint>Used only for account notifications.</Field.Hint>
          <Field.Error>Enter a valid email address.</Field.Error>
        </div>
      </Field>
      <Field label="Account ID" hint="This value cannot be changed.">
        {(id) => <Input id={id} readOnly defaultValue="account_42" />}
      </Field>
    </div>
  );
}

Props

NameTypeDefaultDescription
asChildboolean | undefined——
controlIdstring | undefined—ID for the control and its label, not the root container. Set custom IDs here rather than on the slotted control.
invalidboolean | undefined—Validation belongs to the app; this only announces and displays its result.
labelReactNode—Optional sugar over Label, Control, Hint and Error.
hintReactNode——
errorReactNode——
Label.asChildboolean——
Hint.asChildboolean——
Error.asChildboolean——