Skip to main content

Form

Form state and validation wired to the fields.

In Multi-brand

See it live​

Start Storybook to see it live: npm run storybook

When to use it​

In Multi-brand: Validation shared by every product team.

  • Use it when: Any form that checks answers and shows errors next to the fields.
  • Not when: A single control that saves at once (a switch).

Instead:

  • Field: How one control is laid out.

How Multi-brand uses it​

An error message
Use color.status.danger and a sentence
Not The brand color
Status colors are shared, never branded.
The words of an error
Use Shared across brands: plain and specific
Not Brand tone in errors
Errors read the same in every brand, so support can help anyone. Example: “Your card was declined. Try another card or contact your bank.”

Words​

  • Shared structure: object, state, next step.
  • Brand tone lives in headlines and marketing copy, not in errors.
  • Errors and confirmations read the same in every brand.
  • Use: Get started, Plan, Order. Avoid: Brand-specific words in errors, Jargon.

The labels components use, from the voice tokens:

  • content.action.commit: Save
  • content.action.cancel: Cancel
  • content.action.destroy: Remove
  • content.action.retry: Try again
  • content.action.empty-action: Get started

See Voice and tone for the whole voice.

Accessibility and keyboard​

Test before you ship:

  • Errors are announced, linked to their fields, and the first one gets focus on submit. undefined

Use it in code​

npx open-ds add form

The component reads only component keys and semantic tokens, so it follows the brand and mode on <html>.

Tokens it reads​

Form reads 6 tokens of its own, each an alias of a semantic token. Each row is one part: its own token, the semantic it aliases, and the value it ends at. Change a semantic and every component that reads it follows; override one of Form's tokens to change Form alone.

Changes with theme

Multi-brand decides what changes when you switch theme. Here a switch changes colors, type and shape, so the marked rows differ between its brands and between light and dark; everything else holds steady.

PartIts token and the semantic it aliasesValue
Item
Gapcomponent.form.item.gapspace.gap.defaultvar(--form-item-gap)space.12:0.75rem
Text
Text
Changes with theme
component.form.label.labelcolor.status.dangervar(--form-label-label)Aster Lightred.light.600:#C42B2BAster Darkred.dark.600:#F28B8BBirch Lightred.light.600:#C42B2BBirch Darkred.dark.600:#F28B8BCoral Lightred.light.600:#C42B2BCoral Darkred.dark.600:#F28B8B
Description
Text sizecomponent.form.description.font-sizetype.body.font-sizevar(--form-description-font-size)font.size.16:1rem
Text
Changes with theme
component.form.description.labelcolor.text.mutedvar(--form-description-label)Aster Lightslate-deep.light.600:#4B5A6FAster Darkslate-deep.dark.400:#96A3B5Birch Lightslate-deep.light.600:#4B5A6FBirch Darkslate-deep.dark.400:#96A3B5Coral Lightslate-deep.light.600:#4B5A6FCoral Darkslate-deep.dark.400:#96A3B5
Message
Text sizecomponent.form.message.font-sizetype.body.font-sizevar(--form-message-font-size)font.size.16:1rem
Text
Changes with theme
component.form.message.labelcolor.status.dangervar(--form-message-label)Aster Lightred.light.600:#C42B2BAster Darkred.dark.600:#F28B8BBirch Lightred.light.600:#C42B2BBirch Darkred.dark.600:#F28B8BCoral Lightred.light.600:#C42B2BCoral Darkred.dark.600:#F28B8B