Replies: 4 comments
-
|
Great discussion @pomfrida 🔥 I would focus on creating pure form components without state or context. Make it as simple and close to native form elements as possible with the necessary elements to achieve the style we want. I would also recommend having a look at other headless design system libraries like Base UI and Radix UI: Less is more ✨ We could create stories where we use libraries like react-hook-form for state as proof of concept https://react-hook-form.com/. |
Beta Was this translation helpful? Give feedback.
-
|
Very nice presentation of the different approaches, and I agree that its smart to have a solution on this from the beginning to avoid going back and fix new components. I like the simpler approach, especially using semantic html and vanilla css, i think it will be easier to maintain and work on! Also considering what Victor mentioned in one of our meetings regarding that the newer form elements will be easier to style as native form controls using modern css, so lets keep it close to native where we can, so yay to fieldset and legend 👍 |
Beta Was this translation helpful? Give feedback.
-
|
Thanks both, this is super helpful 🙌 Based on this, I'll start planning work on: I can start drafting the initial API and component structure so we can review it together before integrating it into Checkbox #4208 and Input #4219 that we already started working on. I don't think it would cause any merge conflicts having these PRs open for a little longer while building this foundation as these are all new files. If anyone sees any blockers or has thoughts before I start, feel free to jump in 🙏 |
Beta Was this translation helpful? Give feedback.
-
Component OverviewField: Vertical Layout - Label Above Input:
Field: Inline Layout - Label Beside Input:
ValidationMessage:
Hooks:
Fieldset:
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Background
As part of our v2 component migration to vanilla CSS and custom CSS variables, I've been working on Checkbox 2.0 and noticed we have inconsistent error handling patterns across our form components:
variant="error"+helperTextviaInputWrapperSince we're building
.newcomponents that live alongside v1 with deprecation warnings, we have the opportunity to design a consistent form pattern from the start without breaking changes.Why Not Just Use InputWrapper?
We already have
InputWrapperthat handles labels, helper text, and errors for TextField/Textarea. Why not reuse it?InputWrapper places labels above the input (vertical layout), but Checkbox/Radio/Switch need labels beside the input (inline layout).
Could we make InputWrapper.new flexible enough?
Yes, we could! We could add layout props like
direction="vertical" | "inline"and make it work for both patterns.But consider:
In summary: InputWrapper.new could work, but building focused components gives us a cleaner architecture with less complexity.
What About Duplicating the Current Pattern?
Another option: Keep the current pattern from TextField/Textarea - each component handles its own label, helper text, and error state internally.
Example:
Why this isn't ideal:
The Question
Should we build form wrapper components for our v2 component suite to provide consistent error handling, validation, and accessibility across all form inputs?
Research: Two Main Approaches
I've researched how other major design systems handle this:
Approach 1: FormControl Pattern
Used by: Material UI, Chakra UI, Ant Design
Uses a wrapper component with Context API to distribute state (
error,disabled,required) to all children.Example:
Pros:
Cons:
Approach 2: Hook-based Pattern
Used by: designsystemet.no
Uses simple Field wrapper + hooks for group management. Native
<fieldset>for semantics.Example:
Pros:
<fieldset>,<legend>)Cons:
My Recommendation
Approach 2 (designsystemet.no style) for these reasons:
<fieldset>which is correct for form groupingComponents Needed
For Approach 2, we'd need:
Field- Simple wrapper for individual inputsFieldset+Fieldset.Legend+Fieldset.Description- Grouping componentsValidationMessage- Shared error/helper text componentuseCheckboxGroup- Hook for managing checkbox groupsuseRadioGroup- Hook for managing radio groups (future)Benefits
Proposed Plan
If we agree on this approach:
This way we deliver a consistent form system from day one of v2, rather than retrofitting later.
Questions for Discussion
Looking forward to hearing your thoughts! 💭
Beta Was this translation helpful? Give feedback.
All reactions