Form field

Wraps a control with its label, helper text and error, so every field reads the same.

Refined portVue source: WildFormField.vueStorybook story: Forms/FormFieldReact component: WFormRow

Try it

Turn each piece on and off, and swap the control underneath.

Threshold
42
Alerts fire when a reading crosses this.
Control
Required
Hint
Help
Error
<WildFormField
  label="Threshold"
  help="Alerts fire when a reading crosses this."
>
  <WildTextInput v-model="threshold" />
</WildFormField>

When to use

  • Use a form field around every input, select and toggle in a form, so each one gets a label and room for help and an error.
  • Use hint for a word or two on the label row, such as Optional.
Don’t use it
  • For a single checkbox. Use the Checkbox’s own label.

Anatomy

A label and optional hint, the control, then help text or an error.

Site name*
Bore 12 — north paddock
ThresholdOptional
42
Alerts fire when a reading crosses this.
<WildFormField label="Threshold" hint="Optional"
  help="Alerts fire when a reading crosses this.">
  <WildTextInput v-model="threshold" />
</WildFormField>
The label is 12px and the help 11px, both smaller than the 14px value, so the data outranks its scaffolding.

States

The error takes the help text’s place, so a field with help keeps its height when validation fires.

Threshold
42
Alerts fire when a reading crosses this.
Threshold
420
Must be between 0 and 100.
A field with no help text grows by one line when an error appears.

Controls

Site name
Bore 12
Region
North paddock
SMS alertsImmediate
Input, select and toggle take the same label, hint, help and error, so a settings column that mixes all three reads as one.

Content

  • Name the setting in the label, as a noun: Threshold, Region, SMS alerts.
  • Say what the setting does in the help: “Alerts fire when a reading crosses this.”
  • Say how to fix it in the error: “Must be between 0 and 100.”

Props

PropTypeDefaultDescription
labelstring—The field’s name. A placeholder isn’t a label.
hintstring—A short note right of the label.
helpstring—Guidance under the control.
errorstring—Replaces the help while it’s set.
requiredbooleanfalseA red asterisk after the label.

Tokens

TokenValueWhere it lands
--font-size-sm12pxLabel.
--font-size-xs11pxHint, help and error.
--font-weight-medium475Label.
--color-grey-900#4F4D55Label, hint and help ink.
--color-error#E12121Required asterisk and error text.
(no token)4pxGap between label, control and message.