Components

Field

Combine labels, controls, and help text to compose accessible form fields and grouped inputs.

PreviewSource

Choose a unique username for your account.

Must be at least 8 characters long.

Example requirements

Also uses: Input.

Installation

Complete the project setup first. The init command configures TypeScript, Vite, Tailwind CSS v4, and Preact compatibility.

CLI

Run init once using the installation guide, then add this component. The CLI copies the required source files and installs their exact dependencies with Bun.

bunx --bun github:LiasCode/shadcn-preact#main add field input switch

Add --dry-run to review the changes. Existing modified files are protected; use --overwrite only when you want to replace them.

Manual installation / degit (optional)

1. Install dependencies

bun add --exact class-variance-authority@0.7.1 cn@0.4.0 preact@11.0.1 tw-animate-css@1.4.0

The usage example also needs Input, Switch. Follow their installation guides as well.

2. Copy the component with degit

Run this from your project root. It selects field.tsx, its local dependencies, and both licenses directly from the repository, then copies them into src/components/ui.

bunx degit@3.10.0 https://github.com/LiasCode/shadcn-preact#main ./.cache/shadcn-preact/field --files LICENSE.md,registry/ui/field.tsx,registry/ui/label.tsx,registry/ui/lib/utils.ts,registry/ui/primitives/LICENSE,registry/ui/primitives/internals/empty.ts,registry/ui/primitives/internals/getReactElementRef.ts,registry/ui/primitives/internals/getStateAttributesProps.ts,registry/ui/primitives/internals/mergeObjects.ts,registry/ui/primitives/internals/resolveClassName.ts,registry/ui/primitives/internals/resolveStyle.ts,registry/ui/primitives/internals/types.ts,registry/ui/primitives/internals/useMergedRefs.ts,registry/ui/primitives/internals/useRefWithInit.ts,registry/ui/primitives/internals/useRenderElement.ts,registry/ui/primitives/merge-props/index.ts,registry/ui/primitives/separator/Separator.tsx,registry/ui/primitives/separator/index.ts,registry/ui/separator.tsx --force
mkdir -p ./src/components/ui
cp -R ./.cache/shadcn-preact/field/registry/ui/. ./src/components/ui/
cp ./.cache/shadcn-preact/field/LICENSE.md ./src/components/ui/LICENSE.md

The temporary copy lives in .cache/shadcn-preact/field. Existing components stay in place; shared source files are updated from main.

Selected source files (18)

Usage

import { Input } from "./components/ui/input";
import { Switch } from "./components/ui/switch";
import {
  Field,
  FieldContent,
  FieldDescription,
  FieldError,
  FieldGroup,
  FieldLabel,
  FieldLegend,
  FieldSeparator,
  FieldSet,
  FieldTitle,
} from "./components/ui/field"
<FieldSet>
  <FieldLegend>Profile</FieldLegend>
  <FieldDescription>This appears on invoices and emails.</FieldDescription>
  <FieldGroup>
    <Field>
      <FieldLabel htmlFor="name">Full name</FieldLabel>
      <Input id="name" autoComplete="off" placeholder="Evil Rabbit" />
      <FieldDescription>This appears on invoices and emails.</FieldDescription>
    </Field>
    <Field>
      <FieldLabel htmlFor="username">Username</FieldLabel>
      <Input id="username" autoComplete="off" aria-invalid />
      <FieldError>Choose another username.</FieldError>
    </Field>
    <Field orientation="horizontal">
      <Switch id="newsletter" />
      <FieldLabel htmlFor="newsletter">Subscribe to the newsletter</FieldLabel>
    </Field>
  </FieldGroup>
</FieldSet>

Examples

Textarea

TextareaSource

Share your thoughts about our service.

Example requirements

Also uses: Textarea.

Fieldset

FieldsetSource
Address Information

We need your address to deliver your order.

Example requirements

Also uses: Input.

Responsive Layout

- Vertical fields: Default orientation stacks label, control, and helper text—ideal for mobile-first layouts. - Horizontal fields: Set orientation="horizontal" on Field to align the label and control side-by-side. Pair with FieldContent to keep descriptions aligned. - Responsive fields: Set orientation="responsive" for automatic column layouts inside container-aware parents. Apply @container/field-group classes on FieldGroup to switch orientations at specific breakpoints.

Responsive LayoutSource
Profile

Fill in your profile information.

Provide your full name for identification

Example requirements

Also uses: Button, Input.

Blur Validation

Blur ValidationSource

Use at least three lowercase letters. Try admin to see custom validation.

Example requirements

Also uses: Button, Input.

Composite Validation

Composite ValidationSource

Example requirements

Also uses: Button, Combobox, Select, Slider.

Item Scopes

Item ScopesSource
Contact preferences

Receive a message in your inbox.

Request a callback.

Currently unavailable.

Example requirements

Also uses: Button, Radio Group.

Selection Validation

Selection ValidationSource

Example requirements

Validation

ValidationSource

Enter a valid email address to try form validation.

Example requirements

Also uses: Button, Input.

Reference

See the official Field documentation for composition patterns and API details. This page uses the Preact port and examples from the pinned upstream revision.

Component source