-
Notifications
You must be signed in to change notification settings - Fork 926
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
[labs/forms] WIP: Initial implementation #4773
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: b2b88a5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 0 packagesWhen changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
📊 Tachometer Benchmark ResultsSummarynop-update
render
update
update-reflect
Resultsthis-change
render
update
update-reflect
this-change, tip-of-tree, previous-release
render
update
nop-update
this-change, tip-of-tree, previous-release
render
update
this-change, tip-of-tree, previous-release
render
update
update-reflect
|
The size of lit-html.js and lit-core.min.js are as expected. |
target.set.call(this, value); | ||
getInternals(this)!.setFormValue(value); | ||
}, | ||
init(value: V) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this requires using standard decorators. Think that's ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just sketching things out for now and making sure they compile. I think we'll need to support experimental decorators though, and figure out how to handle the default value. Maybe we try out the pattern we're discussion for @property()
here first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we need user-configurable default values, then we'll have to have a separate decorator for defaults and won't need to rely on the initializer anymore.
|
||
To enable this two decorators are provided to read and write form state: | ||
`@formStateGetter()` and `@formStateSetter()`. They are applied to a getter and | ||
setter to mark them as beind use to readn adn write state. When present, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setter to mark them as beind use to readn adn write state. When present, | |
setter to mark them as being used to read and write state. When present, |
I'm guessing this is what was meant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work! I generally like this approach. 👍
internals. `getInternals()` requires the element class as a parameter and is | ||
guarded against multiple calls similar to `attachInternals()`. | ||
|
||
- `isDisabled()`: An element can be disabled because ti's fieldset is disabled, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- `isDisabled()`: An element can be disabled because ti's fieldset is disabled, | |
- `isDisabled()`: An element can be disabled because its fieldset is disabled, |
/** | ||
* Implement this method to validate the element. Return a `ValidityResult`. | ||
*/ | ||
_getValidity?(): ValidityResult; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code style question; Has this pattern (public properties/methods starting with underscore) been used previously? If not, would protected
with a declared class be an option?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another option is using symbols, which has a few benefits in terms of "hiding" the method from outsiders and making it explicit for implementers:
export const getValidity = Symbol("getValidity");
export interface FormAssociated extends ReactiveElement {
[getValidity]?(): ValidityResult;
}
* Returns true if the element is disabled. | ||
*/ | ||
export const isDisabled = (element: FormAssociated) => | ||
element.matches(':disabled'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would probably break in SSR. I assume that is acceptable?
interface ValidityResult { | ||
flags: Partial<Omit<ValidityState, 'valid'>>; | ||
message?: string; | ||
anchor?: HTMLElement; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this breaks in webkit, if anchor is omitted (or is the element itself, from what I remember).
whatwg/html#10155
https://bugs.webkit.org/show_bug.cgi?id=269832
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is apparently only a problem, if setValidity
is called during constructor phase.
- `validationMessage`: a readonly property that returns the error message that | ||
would be shown to the user if the element was to be checked for validity. | ||
- `willValidate`: a readonly property that returns true if internals's target | ||
element will be validated when the form is submitted. For example, disbabled |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
element will be validated when the form is submitted. For example, disbabled | |
element will be validated when the form is submitted. For example, disabled |
See RRFC: lit/rfcs#43
This a rough sketch of a no-public-API FormAssociated mixin.