FormControl base component RFC #2870
Replies: 6 comments 2 replies
-
We'd like to close this RFC by July 6. If you want to suggest any changes, make sure to do it until that date. |
Beta Was this translation helpful? Give feedback.
-
True, label is required, but |
Beta Was this translation helpful? Give feedback.
-
I would add a additional sentence here:
|
Beta Was this translation helpful? Give feedback.
-
I agree with response provided by you - we should showcase how to use different components/block components in FormControl examples and reference these examples from other documentation pages |
Beta Was this translation helpful? Give feedback.
-
I think the composable is a must - composable that will allow user to consume (and change) the context values will make it easier to implement custom form field wrappers that use |
Beta Was this translation helpful? Give feedback.
-
This RFC has been approved and we're going to implement the FormControl base component. |
Beta Was this translation helpful? Give feedback.
-
PoC: #2865
Jira: https://vsf.atlassian.net/wiki/spaces/SFUI/pages/177537032/FormControl+component
Background
Building form fields is not trivial. In most cases you'd like to add more than just an input. You need a label, an error message, and sometimes some text describing the field a bit better for a user. We want to introduce a new base component that would help to build this kind of a complex fields in a convenient way, and follow all required a11y rules at the same time.
Proposal
FormControl could be a base component. Because we want to provide high flexibility we could implement it using context API in React and Provide/Inject API in Vue.
<FormControl>
would be only a context provider, so we would have to implement a bunch of related components:id
with a label and visually reflect states likedisabled
.invalid
.aria-describedby
attribute.What should be the context interface?
All of these values user should be able to pass via
<FormControl>
props. However, we should provide default values for all of them. Booleans could befalse
by default, and theid
could be automatically generated. It could be a nice feature when user don't have to bother setting theid
manually.Other consumers
Field components must loosely consume the context values. It means they should work within
<FormControl>
and without it. We could exposeuseFormControl
hook/composable, to easily get the context or inject all the values.Components that should inject form control values (consume the context):
a11y rules we should follow
id
must be passed to the label using HTMLfor
attribute.aria-describedby
attribute on the input. Error message and helper text must generate their own IDs and pass them if displayed.aria-invalid
attribute the the input.Usage example
Vue
React
Open questions
There were some open question before that I want to address now.
Do we want to use this kind of FormControl component within all of our blocks?
It depends. I'd say in some block, yes, but not in each and everyone. Definitely, base components like
<SfInput>
or<Radio>
that are going to consume the context must showcase how they could be combined with the FormControl. However, in blocks like forms we should focus on delivering the actual value, so fulfilling the use case. In my opinion using FormControl may bring unwanted noise in this kind of blocks.What should be the scope of FormControl component? Should we implement subcomponents like Label, ErrorMessage? How should they be styled?
I can see high benefit of having these as base components. I think we should also style them, so they follow SFUI design guidelines. We could also extract hook/composable to consume the context, so the user may build their own label if needed.
What should take priority - props on the input component level or state coming from FormControl component?
I think it's clear that props on the component should take priority over the values coming from the context. FormControl provides high-level context, but if any of the components would have to by any reason override the values, they should take priority.
Should the error state be automatically passed to the input components?
Yes, I think that's one of the biggest benefits – shared state, automatically synced between all subcomponents.
Beta Was this translation helpful? Give feedback.
All reactions