A label, a hint and an error around a form control, with the ids and aria attributes wired up.
$ pnpm dlx shadcn@latest add https://dashral.com/r/field.jsonInstallation
$ pnpm dlx shadcn@latest add https://dashral.com/r/field.jsonAdds the component, the components it builds on, its npm packages and the theme tokens it uses. Using Dashral often? Add the registry to components.json once:
{
"registries": {
"@dashral": "https://dashral.com/r/{name}.json"
}
}Then add components by name:
$ pnpm dlx shadcn@latest add @dashral/fieldUsage
import { Input } from "@/components/dashral/input"
import { Field } from "@/components/dashral/field"
<Field label="Team URL" description="Letters, numbers and dashes." error={taken && "This URL is taken."}>
<Input prefix="acme.com/" name="slug" />
</Field>Examples
API reference
Field
Also takes every prop of <div>(opens in a new tab).
| Prop | Type | Default |
|---|---|---|
label | ReactNodeShown above, linked to the control. | — |
description | ReactNodeA hint under the control. | — |
error | boolean | ReactNodetrue shows the error style; a message also shows under the control. | — |
labelAction | ReactNodeAt the end of the label's row, e.g. a “Forgot password?” link or the current value. | — |
withAsterisk | booleanMarks the label with an asterisk, e.g. alongside required. | false |
id | stringThe control's id. Generated when left out. | — |
required / disabled | booleanPassed on to the control. | false |
classNames | { label, description, error }Classes for each part. | — |
className | stringExtra classes, merged with cn() so yours win. | — |
FieldLabel
The label every field uses, for a control of your own. It dims with a disabled field.
Also takes every prop of Radix Label(opens in a new tab).
Accessibility
- The control inside gets its id, aria-describedby (hint and error) and aria-invalid from the Field.
- The error message fades in; with reduced motion it doesn't move.