Brand Guide

Components

Label

Names a form control, and focuses it when pressed.

Default

With a switch

A label beside its control, as in a settings row.

An email when Dex finds a match.

Around a checkbox

A label wrapped round its control needs no htmlFor.

In a field

FieldLabel is the label inside a Field. The field joins it to the control.

Optional

For a group

A group of options takes a FieldLegend in a FieldSet.
How do you want to work?

Disabled

A disabled field dims its label with its control.

Parts of a field

The parts in @dex/shared/components/field that put a label, a control and a message together.
  • Field holds one control with its label and message. It owns the ids that connect them. Pass controlId when the control needs an id you know elsewhere, and invalid or disabled for the whole field.
  • FieldLabel is the label. It points at the field's control without an htmlFor.
  • FieldControl wraps the one control. It passes on the field's id, its error state and the id of the message.
  • FieldMessage takes the helper text as description and the error as error, and shows the error in the helper text's place while there is one.
  • FieldSet and FieldLegend do the same for a group of options, such as chips, radios or choice cards. invalid on the FieldSet turns every option's border red.

Best practices

  • Every control has a label. In a form, that is a FieldLabel in a Field. Use Label on its own for a control outside a field, such as a switch in a settings row.
  • Join a Label to its control with htmlFor, or wrap the control in it. With htmlFor, the cursor becomes a pointer over the label.
  • A label names one control. For one question with several options, use a FieldLegend in a FieldSet.
  • Mark a field that can be left empty with optional.
  • The label keeps its colour when the field has an error. Only the control's border and the message turn red.