Examples

Cloned child

The child receives id, aria-describedby, aria-invalid, required and disabled.

Preview

Used for tax calculation.

Example.tsx
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.

Preview

Choose a date in the future.

Example.tsx
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.

Preview
Billing address

As it appears on your invoices.

Example.tsx
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

FormField props
PropTypeDefault
label
Visible label, associated with the control.
ReactNode—
description
Help text linked with aria-describedby.
ReactNode—
error
Error message; marks the control invalid and is described.
ReactNode—
invalid
Invalid without a message.
booleanfalse
hideLabel
Keep the label for screen readers, hide it visually.
booleanfalse
showOptional
Append “(optional)” to labels of non-required fields.
booleanfalse
required · disabled
Passed to the control.
booleanfalse
controlId
Id for the control; generated when omitted.
string—
childrenrequired
ReactElement | (props) => ReactNode—

Fieldset props

Fieldset props
PropTypeDefault
legend
ReactNode—
description · error
Linked to the group.
ReactNode—
orientation
'vertical' | 'horizontal''vertical'
disabled
Disables every control inside natively.
booleanfalse

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.