Installation
$ pnpm dlx shadcn@latest add @synccn/form-fieldFirst time in this project? Connect synccn with one command.
Usage
import { FormField, FieldSet } from "@/components/ui/form-field";<FormField label="Email" error={errors.email}> <Input /></FormField>API reference
Generated from the component's TypeScript types, so it always matches the code.
FormField
Label, control, description and error in one consistent block. The control gets the right id, aria-invalid and aria-describedby for free.
- label
React.ReactNodeField label.
- description
React.ReactNodeHelp text, hidden while there's an error.
- error
React.ReactNodeError message; also marks the control invalid.
- required
booleanAdds an asterisk and aria-required.
- optional
booleanAdds “(optional)” after the label.
- childrenrequired
React.ReactElement<any>The control. It receives id and ARIA attributes.
- className
stringExtra classes for the root element.
FieldSet
Groups related fields under a heading, like a fieldset.
- legend
React.ReactNodeGroup heading.
- description
React.ReactNodeText under the heading.
- children
React.ReactNodeContent to render.
- className
stringExtra classes for the root element.
Dependencies
Read from the component's imports when the site builds. The CLI installs all of these for you.
Helpers
- lib/utilscn (merges class names)
npm packages
- clsx for cn()
- tailwind-merge for cn()
- lucide-react for CircleAlert
Accessibility
From the source
Read from this component's code when the site builds, so it can't drift.
- ARIA roles: alert
- Labels are tied to their controls
- Announces changes to screen readers