-
Notifications
You must be signed in to change notification settings - Fork 265
Add platform-provided mixins explainer #1208
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
base: main
Are you sure you want to change the base?
Add platform-provided mixins explainer #1208
Conversation
|
|
||
| **Pros:** | ||
| - Familiar JavaScript pattern. | ||
| - Prototype-based composition. |
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 pro to this approach is that it allows for child classes to easily extend from mixins. e.g.
class CustomSubmitButton extends HTMLSubmitButtonMixin(HTMLElement) { ... }
class ExtraCustomSubmitButton extends CustomSubmitButton {...}
Is this possible with the current mixin proposal?
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.
Yes, we talked about in the meeting about child classes inheriting ElementInternals. I tested it and child classes do inherit the instance and can modify it. With the proposed approach we could have:
class ParentElement extends HTMLElement {
#internals;
constructor() {
super();
this.#internals = this.attachInternals();
// ...
this._internals = this.attachInternals({ mixins });
}
_getInternals() {
return this.#internals;
}
}
class ChildElement extends ParentElement {
constructor() {
super();
const internals = this._getInternals();
internals.role = 'checkbox';
const isSubmit = this._internals.mixins.includes(HTMLSubmitButtonMixin);
if (isSubmit) {
// ...
}
}
}| **Cons:** | ||
| - Doesn't currently address form submission behavior. | ||
| - Scoped to specific attributes rather than general behaviors. | ||
|
|
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.
Does it make sense to list "Extend Markup Like Customizable Select"? Or is that too different of a problem? The dealbreaking con with this approach is that it won't work for all types (or any types beyond select?).
https://developer.mozilla.org/en-US/docs/Learn_web_development/Extensions/Forms/Customizable_select
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.
Yes, added it as an alternative. PTAL.
V1 includes:
attachInternals()and avoid dynamic changes at runtime.ElementInternalsto query behaviors.