-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RRFC] FormAssociated mixins #43
Comments
There are a lot of possible variations on what a mixin might provide, especially in terms of the public API it creates on the element. I think the the minimal end of the spectrum, like the sketch above, a mixin might add no new public API. It just helps the element author coordinate the form value, form associated callbacks, and form methods on ElementInternals. Another point on the spectrum is to emulate many of the the methods of HTMLInputElement, like So we may want to start with a minimal-API-adding mixin, then layer a richer API mixin on top of that. The minimal-API mixin can optionally have support for pluggable constraints. |
If that is the case, could FormAssociated be developed as a controller instead? |
No, because it needs to override the form associated instance methods like |
I love this. One thing though that should be considered & documented carefully is how to make such a custom form control accessible. I'm not sure browsers are fully there yet for formAssociated controls. |
Supportive of this. Working with forms is fairly confusing, so utilities like this are really helpful. |
Motivation
Building a form associated custom element requires a lot of common boilerplate:
static formAssociated = true
internals.setFormValue()
when neededformDisabledCallback()
formResetCallback()
andformStateRestoreCallback()
Example
A simple-ish
FormAssociated()
element, with validation, might just forward an input's value to the element's value:In this case the
FormAssociated
mixin would:static formAssociated = true
internals.role
setFormValue()
whenvalue
changesformStateRestoreCallback()
to reset the value.How
A
FormAssociated()
mixin, paired with@internals
,@formValue
and@formState
decorators.Current Behavior
Desired Behavior
References
The text was updated successfully, but these errors were encountered: