Components

Field

Accessible React form fields built on shadcn/ui: Field, FieldLabel, FieldDescription, FieldError, FieldSet and FieldGroup lay out labels, hints and validation errors for any input, with invalid and disabled states, horizontal and responsive layouts and selectable choice cards — plus Motion blocks for errors that grow open, fields that shake on a failed submit and a complete sign-up form validated without a form library.

  • Drop-in shadcn API
  • Works with any validation library
  • Choice cards
  • Responsive layout
  • Motion blocks

At least 8 characters.

Installation

$ npx shadcn@latest add https://duskui.com/r/field.json

Adds components/ui/field.tsx and the DuskUI components/ui/label.tsx it builds on. Same parts and data-slot attributes as shadcn/ui, so existing forms keep working.

Usage

profile-form.tsx
import { Field, FieldDescription, FieldError, FieldLabel } from "@/components/ui/field"
import { Input } from "@/components/ui/input"

export function UsernameField({ error }: { error?: string }) {
  return (
    <Field data-invalid={!!error || undefined}>
      <FieldLabel htmlFor="username">Username</FieldLabel>
      <Input
        id="username"
        aria-invalid={!!error || undefined}
        aria-describedby="username-hint username-error"
      />
      <FieldDescription id="username-hint">Your public handle.</FieldDescription>
      <FieldError id="username-error">{error}</FieldError>
    </Field>
  )
}

Examples

Label, description & error

data-invalid eases the label to red while the hint stays readable; data-disabled dims label and hint together. FieldError renders nothing when empty and fades in when it appears.

Your public handle. You can change it later.

Managed by your organization.

Fieldset, separator & orientation

Group related controls in a FieldSet with a FieldLegend. Use orientation="horizontal" for checkboxes and switches, and "responsive" to switch from stacked to a row once the FieldGroup is wide enough (a container query, not a viewport breakpoint).

Notifications

Choose what lands in your inbox.

Pause notifications from 10pm to 8am.

Row on wide screens, stacked on narrow ones.

Choice cards

Wrap a horizontal Field in a FieldLabel and the whole card becomes the hit area. Its border turns mint while its switch or checkbox is on.

Workspace features

Blocks

Ready-made variations composed from the base component with Motion. Each installs on its own and pulls in its dependencies automatically.

Animated Field Error

AnimatedFieldError grows open and collapses shut so the form below glides, and cross-fades when the message changes. AnimatedField shakes once whenever its shakeKey changes while invalid — pass your submit counter. Submit the demo empty, then with a non-work email.

We'll send the invite here.

$ npx shadcn@latest add https://duskui.com/r/animated-field-error.json
PropTypeDefaultDescription
AnimatedField invalidbooleanfalseSets data-invalid on the Field.
AnimatedField shakeKeynumber | string—Change it (e.g. a submit count) to shake once while invalid. Never shakes on mount.
AnimatedFieldError idstring—Reference it from the control's aria-describedby.
AnimatedFieldError childrenReactNode—The message. Falsy collapses the error.
AnimatedFieldError classNamestring"-mt-3"Wrapper classes. The negative margin cancels the Field's gap-3 while collapsed.

Sign-up Form

A complete form validated with plain React state: quiet until the first submit, then every invalid field shakes, focus jumps to the first problem and errors re-validate as you type. A successful submit swaps in a confirmation. validateSignup is exported — replace it with Zod or Valibot if you prefer.

At least 8 characters.

$ npx shadcn@latest add https://duskui.com/r/signup-form.json
PropTypeDefaultDescription
onSubmit(values: SignupValues) => void | Promise<void>—Called with valid values. A promise keeps the button loading until it settles; a rejection returns to the form.
submitLabelstring"Create account"Submit button text.

API Reference

Every part accepts the props of the element it renders. Field renders a div role="group"; FieldLabel is the Radix-powered DuskUI Label.

PropTypeDefaultDescription
Field orientation"vertical" | "horizontal" | "responsive""vertical"Stacked, in a row, or a row once the parent FieldGroup is wider than 28rem.
Field data-invalidboolean—Tints the label red. Also set aria-invalid on the control.
Field data-disabledboolean—Dims the label and description.
FieldLegend variant"legend" | "label""legend"Heading or label-sized legend.
FieldError errorsArray<{ message?: string } | undefined>—Errors from a validation library. Deduplicated; several render as a list.
FieldSeparator childrenReactNode—Optional text centered on the line.

Accessibility

  • Link hints and errors to the control with id + aria-describedby, and set aria-invalid on the control itself — the Field only handles the visuals.
  • FieldError and AnimatedFieldError use role="alert", so new messages are announced.
  • FieldSet + FieldLegend render a native fieldset, so screen readers announce the group name before each control.
  • The Sign-up Form moves focus to the first invalid field on submit and keeps the submit button focusable while loading.
  • Shakes and height animations respect prefers-reduced-motion.