FormSection
A container to group related fields with a title and description.
Use sections to split complex forms into meaningful parts.
Preview
"use client";
import { zodResolver } from "@hookform/resolvers/zod";
import { useForm, FormProvider } from "react-hook-form";
import { z } from "zod";
import InputField from "@/components/ui/InputField";
import FormSection from "@/components/ui/FormSection";
import FormGrid from "@/components/ui/FormGrid";
import { schema } from "./form-section-schema";
export function FormSectionBasicExample() {
const methods = useForm<z.infer<typeof schema>>({
resolver: zodResolver(schema),
defaultValues: {
firstName: "",
lastName: "",
},
});
const onSubmit = (data: z.infer<typeof schema>) => {
console.log("Form data:", data);
alert("Check the console for the form data!");
};
return (
<FormProvider {...methods}>
<form onSubmit={methods.handleSubmit(onSubmit)} className="space-y-4 w-96">
<FormSection title="Personal Information" description="Provide your basic details.">
<FormGrid>
<InputField name="firstName" label="First name" />
<InputField name="lastName" label="Last name" />
</FormGrid>
</FormSection>
<button
type="submit"
className="form-button form-button-primary w-full"
>
Submit
</button>
</form>
</FormProvider>
);
}
Props
| Name | Type | Default | Description |
|---|---|---|---|
| title | string | - | Section title displayed at the top. |
| description | string | - | Section helper text. |