Components
Form
Native form wrapper built on Base UI Form with integrated client and server-side error mapping to Field controls.
"use client";
import { Button } from "@/components/ui/button";
import {
Field,
FieldDescription,
FieldError,
FieldLabel,
} from "@/components/ui/field";
import { Form } from "@/components/ui/form";
import { Input } from "@/components/ui/input";
import { Textarea } from "@/components/ui/textarea";
import { toastManager } from "@/components/ui/toast";
export default function Particle() {
return (
<Form
onSubmit={(event) => {
event.preventDefault();
const data = new FormData(event.currentTarget);
const name = String(data.get("name") ?? "");
toastManager.add({
description: `Project "${name}" has been created.`,
title: "Project created",
type: "success",
});
}}
>
<Field name="name">
<FieldLabel>Project name</FieldLabel>
<Input placeholder="taut-ui" required />
<FieldError match="valueMissing">Project name is required.</FieldError>
</Field>
<Field name="notes">
<FieldLabel>Description</FieldLabel>
<Textarea placeholder="Short summary of the project..." size="sm" />
<FieldDescription>
Optional internal notes for your team.
</FieldDescription>
</Field>
<Button className="self-end" type="submit">
Create project
</Button>
</Form>
);
}
Installation
pnpm dlx shadcn@latest add @taut-ui/form
Usage
import { Button } from "@/components/ui/button"
import { Field, FieldError, FieldLabel } from "@/components/ui/field"
import { Form } from "@/components/ui/form"
import { Input } from "@/components/ui/input"<Form onSubmit={(e) => e.preventDefault()}>
<Field name="email">
<FieldLabel>Email</FieldLabel>
<Input required type="email" />
<FieldError />
</Field>
<Button type="submit">Submit</Button>
</Form>Examples
Controlled Errors
"use client";
import { useState } from "react";
import { Button } from "@/components/ui/button";
import { Field, FieldError, FieldLabel } from "@/components/ui/field";
import { Form } from "@/components/ui/form";
import { Input } from "@/components/ui/input";
export default function Particle() {
const [errors, setErrors] = useState<Record<string, string>>({
domain: "This custom domain is already linked to another project.",
});
return (
<Form
errors={errors}
onFormSubmit={(formValues) => {
const domain = String(formValues.domain ?? "").trim();
if (!domain.includes(".")) {
setErrors({
domain: "Enter a valid hostname (e.g. docs.taut.app).",
});
return;
}
setErrors({});
}}
>
<Field name="domain">
<FieldLabel>Custom domain</FieldLabel>
<Input defaultValue="app.taut.dev" placeholder="docs.taut.app" />
<FieldError />
</Field>
<Button className="w-full" type="submit">
Verify domain
</Button>
</Form>
);
}
API Reference
Form
Wraps Base UI Form (<form>).
| Prop | Type | Default | Description |
|---|---|---|---|
errors | Record<string, string | string[]> | - | External/server validation errors keyed by name |
validationMode | "onSubmit" | "onBlur" | "onChange" | "onSubmit" | Controls when field validation triggers |
onFormSubmit | (formValues: Record<string, unknown>, details) => void | - | Called on valid submission (preventDefault built-in) |
actionsRef | React.RefObject<Form.Actions | null> | - | Imperative handle exposing validate(fieldName?) |
className | string | - | Additional CSS classes |