Forms
FormField
Wires a label, description and error to any control — native selects, date pickers, editors from other libraries — plus Fieldset for groups.
import { FormField, Fieldset, FormLabel, FormDescription, FormError } from '@reactloom/ui';Examples
Cloned child
The child receives id, aria-describedby, aria-invalid, required and disabled.
Used for tax calculation.
import { FormField } from '@reactloom/ui';
export default function Example() {
return (
<div style={{ width: '100%', maxWidth: 360 }}>
{/* Any control: native select, a date picker, a rich editor… */}
<FormField label="Country" description="Used for tax calculation." required>
<select
defaultValue=""
style={{
appearance: 'none',
width: '100%',
height: 36,
borderRadius: 'var(--pl-radius-md)',
border: '1px solid var(--pl-color-border-input)',
backgroundColor: 'var(--pl-color-bg-surface)',
color: 'var(--pl-color-fg-default)',
padding: '0 2.25rem 0 0.75rem',
font: 'inherit',
backgroundImage:
'url("data:image/svg+xml,%3Csvg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%270 0 24 24%27 fill=%27none%27 stroke=%27%2371717a%27 stroke-width=%272%27 stroke-linecap=%27round%27 stroke-linejoin=%27round%27%3E%3Cpath d=%27m6 9 6 6 6-6%27/%3E%3C/svg%3E")',
backgroundRepeat: 'no-repeat',
backgroundPosition: 'right 0.625rem center',
backgroundSize: '1rem 1rem',
cursor: 'pointer',
}}
>
<option value="" disabled>Select a country</option>
<option>Germany</option>
<option>India</option>
<option>United States</option>
</select>
</FormField>
</div>
);
}Render function
For components that need explicit wiring.
Choose a date in the future.
import { FormField } from '@reactloom/ui';
export default function Example() {
return (
<div style={{ width: '100%', maxWidth: 360 }}>
<FormField label="Due date" error="Choose a date in the future.">
{(field) => (
// `field` holds id, aria-describedby, aria-invalid, required, disabled
<input type="date" {...field} style={{ width: '100%', height: 32, padding: '0 8px' }} />
)}
</FormField>
</div>
);
}Fieldset
Group related fields under a legend.
import { Fieldset, Grid, GridItem, Input } from '@reactloom/ui';
export default function Example() {
return (
<Fieldset legend="Billing address" description="As it appears on your invoices." style={{ width: '100%', maxWidth: 480 }}>
<Grid columns={{ base: 1, sm: 2 }} gap="3">
<GridItem colSpan="full">
<Input label="Street" autoComplete="street-address" />
</GridItem>
<Input label="City" autoComplete="address-level2" />
<Input label="Postal code" autoComplete="postal-code" />
</Grid>
</Fieldset>
);
}API reference
FormField props
| Prop | Type | Default |
|---|---|---|
labelVisible label, associated with the control. | ReactNode | — |
descriptionHelp text linked with aria-describedby. | ReactNode | — |
errorError message; marks the control invalid and is described. | ReactNode | — |
invalidInvalid without a message. | boolean | false |
hideLabelKeep the label for screen readers, hide it visually. | boolean | false |
showOptionalAppend “(optional)” to labels of non-required fields. | boolean | false |
required · disabledPassed to the control. | boolean | false |
controlIdId for the control; generated when omitted. | string | — |
childrenrequired | ReactElement | (props) => ReactNode | — |
Fieldset props
| Prop | Type | Default |
|---|---|---|
legend | ReactNode | — |
description · errorLinked to the group. | ReactNode | — |
orientation | 'vertical' | 'horizontal' | 'vertical' |
disabledDisables every control inside natively. | boolean | false |
Accessibility
- Use FormField for third-party controls so they get the same wiring as ReactLoom’s own.
Usage guidelines
Do
- Use Fieldset for addresses, date parts, related toggles.
Don’t
- Don’t nest a ReactLoom Input inside FormField — it already has a label.