Skip to the content

Field

Field wraps one control with a label, an optional note and a hint line. You pass the control as component; Field injects value, onChange, variant, readOnly and reset into it. Every key of a Form renders as a Field.
Forms

When to use

Use when
  • A control needs a label, a hint or a validation message in the design-system layout.
  • You build a form without Form but want the same field anatomy.
Avoid when
  • Inside a Form — declare the field in fields instead of rendering Field yourself.
  • Label and control need a custom arrangement (side by side, a complex grid) — compose the parts directly.

Usage

What should we call you?
Optional
We will use it to send you updates.
Password must be at least 8 characters long.
Passwords match.
<Field component={Input} name="name" label="Name" hintText="What should we call you?" />
<Field component={Input} name="email" label="Email" optionalText="Optional" />
<Field component={Input} name="password" label="Password" error hintErrorText="At least 8 characters." />
<Field component={Input} name="confirm" label="Confirmation" success hintSuccessText="Passwords match." />

error and success paint the label, the hint and the control; variant sets the state directly and wins over both. The hint line always reserves one line, so switching to an error does not shift the content below. readOnly prints readOnlyText (default apenas leitura) in the note slot.

Rich hints

hintText, hintErrorText and hintSuccessText accept a ReactNode, so a hint can carry an inline action:

<Field
  component={Input}
  name="amount"
  label="Amount"
  hintText={
    <Flex flexDirection="row" justifyContent="between" width="100%">
      <Text text="Daily limit: 5,000" />
      <Button variant="linked" size="extraSmall" text="Use all" onClick={fillMax} />
    </Flex>
  }
/>

Fill

With a TextArea, inputProps={{ fill: true }} makes the whole field grow into the leftover space of its flex parent; the label and hint keep their height and only the control grows.

<Flex height="100dvh">
  <Field component={TextArea} name="content" label="Content" inputProps={{ fill: true, rows: 4 }} />
</Flex>

Accessibility

  • The label is a native <label for={name}> and the control receives id={name}: always pass name.
  • hideLabel keeps the label as the control's name but takes it out of the layout, so the control lines up with a bare control under a shared heading.
  • Controls a <label> cannot name (marked ariaLabelledByField, such as InputRange) get aria-labelledby pointing at the label. An aria-label or aria-labelledby in inputProps wins.
  • While the field has an error (errors or error), the control gets aria-invalid; a visual-only variant="error" does not set it. aria-describedby points at the visible hint.

Properties

Placement props (area, alignSelf, justifySelf) apply to the field; fieldProps reaches its inner Flex.

See also