Form Field
FormField groups a control with its label, helper text, and validation message.
import { FormField } from '@/components/ui/wideset/form-field/FormField';
import { TextInput } from '@/components/ui/wideset/text-input/TextInput';
<FormField
label="Billing email"
htmlFor="billing-email"
helperText="We send receipts here."
>
<TextInput id="billing-email" placeholder="name@company.com" />
</FormField>Installation
pnpm dlx wideset add form-field
Copies the component and any Wideset components it uses into your project.
Examples
Variants
vertical stacks the label over the control and suits most forms, narrow columns and mobile. horizontal puts the label in a column of up to 10rem beside the control, with the helper text under the label; use it for settings pages where labels line up and values are short. Keep one layout per form.
import { FormField } from '@/components/ui/wideset/form-field/FormField';
import { TextInput } from '@/components/ui/wideset/text-input/TextInput';
export default function FormFieldVariants() {
return (
<div className="gap-ws-11 flex w-[28rem] max-w-full flex-col">
<FormField
variant="vertical"
label="Workspace name"
htmlFor="workspace-vertical"
helperText="Shown on invoices and in emails."
>
<TextInput id="workspace-vertical" placeholder="Northwind" />
</FormField>
<FormField
variant="horizontal"
label="Workspace name"
htmlFor="workspace-horizontal"
helperText="Shown on invoices and in emails."
>
<TextInput id="workspace-horizontal" placeholder="Northwind" />
</FormField>
</div>
);
}States
required adds the asterisk to the label only; it does not validate and does not reach the input, so set required or aria-required on the control as well. errorText replaces the helper text while it is set, so the hint comes back once the value is fixed. The field points the control's aria-describedby at the helper or error text and sets aria-invalid while the error shows, but the danger variant is yours to set on the input. Advisory warnings use helper text; FormField has no separate warning state.
import { FormField } from '@/components/ui/wideset/form-field/FormField';
import { TextInput } from '@/components/ui/wideset/text-input/TextInput';
export default function FormFieldStates() {
return (
<div className="gap-ws-11 flex w-[20rem] max-w-full flex-col">
<FormField
label="Billing email"
htmlFor="email-required"
required
helperText="We send receipts here."
>
<TextInput id="email-required" placeholder="name@company.com" required />
</FormField>
<FormField
label="Billing email"
htmlFor="email-error"
required
helperText="We send receipts here."
errorText="Enter an email address like name@company.com."
>
<TextInput id="email-error" placeholder="name@company.com" variant="danger" required />
</FormField>
<FormField
label="Workspace slug"
htmlFor="workspace-warning"
helperText="Warning: changing this slug breaks existing workspace links."
>
<TextInput id="workspace-warning" placeholder="northwind" />
</FormField>
</div>
);
}API reference
| Name | Description | Default |
|---|---|---|
children* | The control. A single element is linked to the helper or error text with `aria-describedby`. ReactNode | — |
label* | Field label content; connect it to the control with matching IDs. ReactNode | — |
aside | Quiet content at the far end of the label row, such as a counter or a link. ReactNode | — |
className | Additional classes added to the root element. string | — |
errorText | Validation message displayed in place of helper text when provided. string | — |
helperText | Supporting text displayed when there is no error message. string | — |
helperTextId | Id of the helper or error text. Generated when omitted. string | — |
required | Shows `FieldLabel.RequiredIndicator`. Set `required` on the control as well. boolean | — |
suffix | Quiet text after the label, such as "(optional)". string | — |
tooltip | Extra explanation behind an info button next to the label. ReactNode | — |
tooltipAriaLabel | Accessible name of the tooltip button. Defaults to `'More information'`. string | — |
variant | 'horizontal''vertical' | 'vertical' |
WrapperComponent | Wrapper element. Use `fieldset` to label a group of related controls. 'div''fieldset' | 'div' |
Accessibility
requiredonly draws the asterisk, and the asterisk isaria-hidden. Setrequired(oraria-required) on the control too.htmlForworks for native controls, TextInput, Textarea, Select and MultiSelect (theiridlands on the input or trigger). It does not reachComboBox: give FormField anid(it lands on the label) and pass it to the ComboBox asaria-labelledby.- With
fieldset, the label is not a<legend>: also name the group (aria-labelonRadioButton.Group). - The
tooltipis a<button>next to the label (not inside it), labelled “More information”; translate withtooltipAriaLabel.suffixis inside the label, so it is part of the control’s accessible name (“Nickname (optional)”).
import { FormField } from '@/components/ui/wideset/form-field/FormField';
import { TextInput } from '@/components/ui/wideset/text-input/TextInput';
<FormField
label="Billing email"
htmlFor="billing-email"
helperText="We send receipts here."
>
<TextInput id="billing-email" placeholder="name@company.com" />
</FormField>