GooseUI

Components

Field

New

Wraps a control with a label, a hint and an error. The error is hidden until the browser marks the control :user-invalid (the user touched it and left a bad value), so there is no state and no JavaScript. Parts are linked with ids and aria-describedby. Server component.

Browser Support

Baseline Widely available
2 features
Details
:user-valid and :user-invalid

Shows the error and the red border only after the user touched the field. Without it the error never appears; native validation still blocks the submit

Your browser:
:has()

Lets the group react to its control: the red label and the visible error

Your browser:

Preview

We send the receipt here.

Installation

npx shadcn@latest add @gooseui/field
pnpm dlx shadcn@latest add @gooseui/field
yarn dlx shadcn@latest add @gooseui/field
bunx --bun shadcn@latest add @gooseui/field

Usage

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

export default function Example() {
  return (
    <Field>
      <FieldLabel htmlFor="email">Email</FieldLabel>
      <Input id="email" type="email" required aria-describedby="email-hint" />
      <FieldDescription id="email-hint">We send the receipt here.</FieldDescription>
      <FieldError>Enter a valid email</FieldError>
    </Field>
  )
}

Examples

Horizontal

orientation="horizontal" puts the control and the label in a row: for checkboxes and switches.

<Field orientation="horizontal">
  <Checkbox id="terms" required />
  <FieldLabel htmlFor="terms">I accept the terms</FieldLabel>
</Field>

Error from the server

invalid forces the error. Add aria-invalid on the control and its id to aria-describedby.

<Field invalid>
  <FieldLabel htmlFor="username">Username</FieldLabel>
  <Input id="username" aria-invalid="true" aria-describedby="username-error" />
  <FieldError id="username-error">This username is taken</FieldError>
</Field>

Group with a legend

FieldSet and FieldLegend make a <fieldset> for related fields; FieldGroup spaces the fields.

Account
<FieldSet>
  <FieldLegend>Account</FieldLegend>
  <FieldGroup>
    <Field>…</Field>
    <Field>…</Field>
  </FieldGroup>
</FieldSet>

Props

PropTypeDefaultDescription
orientation"vertical" | "horizontal""vertical"Control and label stacked or in a row
invalidbooleanfalseForces the invalid state and shows FieldError
classNamestring-Additional CSS classes

Parts

PartElementDescription
FielddivWrapper, role="group", holds the invalid state
FieldLabellabelLabel from the registry; red when invalid, adds * for required controls
FieldDescriptionpHint under the control; reference it in aria-describedby
FieldErrorpError text, role="alert"; visible only when invalid
FieldGroupdivColumn of fields with a gap
FieldSet / FieldLegendfieldset / legend<fieldset> and <legend> for related fields