Skip to content

docs(ds-global-form): error-state stories for every input and field#709

Open
advl wants to merge 2 commits into
mainfrom
feat/form-error-stories
Open

docs(ds-global-form): error-state stories for every input and field#709
advl wants to merge 2 commits into
mainfrom
feat/form-error-stories

Conversation

@advl

@advl advl commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Done

Add an error-state story to every input and field, because each one presents errors differently — a single pattern-level error demo doesn't represent them.

Two helpers in src/storybook/:

  • errorStory() — builds the RHF-driven WithError story for a *Field: the field is registered, marked touched, and given a failing validation rule for its empty value, so react-hook-form reports an error → the Wrapper adds .danger to .ds.field and renders <FieldError>. This shows each field's real error presentation (red chrome + message), distinct per component.
  • danger() decorator — wraps a bare presentational subcomponent in the field .danger > .payload context (+ a FieldError message), so the error-chrome selector matches. Subcomponents have no Wrapper/RHF of their own, so this shows the visual error layer the subcomponent owns, honestly, without faking form state.

Coverage:

  • WithError on all 15 remaining *Field stories (DateField already had one).
  • ErrorState on all 15 UI subcomponent stories (HiddenInput/HiddenField excluded — no UI).
  • Covers the bespoke error styling too (ColorInput .color-trigger, FileUploadInput .drop-zone), which key off the same .danger > .payload ancestor.

QA

  • Storybook: every components/*Field has a WithError showing the red chrome + error message; every subcomponents/*Input has an ErrorState showing the error visual.
  • Verified: bun run check gate passes, full suite 236 tests pass, build:storybook succeeds.

PR readiness check

  • Label: Documentation 📝
  • PR title follows Conventional Commits.
  • Code follows the code standards.
  • Package defines check, check:fix, test, build, build:all.
  • New package: n/a.
  • Requires visual testing (Chromatic) — adds visible error-state snapshots.

Screenshots

Error states are best reviewed via Chromatic / the built Storybook (jsdom can't render the .danger chrome visuals).

Each input/field presents errors differently, so show the error state per
component rather than once at the pattern level.

Two helpers in storybook/:
- errorStory(): builds the RHF-driven WithError story for a *Field — the field
  is registered, marked touched, and given a failing validation rule, so the
  Wrapper adds .danger and renders FieldError (the field's real error state).
- danger(): a decorator that wraps a bare presentational subcomponent in the
  field .danger > .payload context so the error chrome selector matches, plus a
  FieldError message — showing the visual error layer the subcomponent owns
  (subcomponents have no Wrapper/RHF of their own).

Adds WithError to all 15 remaining *Field stories (DateField already had one)
and ErrorState to all 15 UI subcomponents (Hidden* excluded — no UI).

Package check gate passes; 236 tests pass; storybook builds.
@advl advl added the Documentation 📝 Improvements or additions to documentation label Jun 30, 2026
- ColorField WithError was a no-op: ColorField binds a non-empty default
  (#000000), so a plain required rule can never fail. Use a validate rule so
  the error actually surfaces.
- Fold DateField's hand-rolled WithError into the errorStory() helper for
  consistency with every other field.
- Fix RadioInput ErrorState TSDoc: pointed at a non-existent RadioField — now
  references ChoicesField/SimpleChoicesField, and clarifies a single radio has
  no control-level error border (error shown via the message).
- Soften Checkbox/Range ErrorState TSDoc: these controls have no error border
  of their own (Range's field-tier error chrome lands on the number input);
  the error is conveyed by the FieldError message.

From the #709 review swarm. check gate passes; storybook builds.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Documentation 📝 Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant