[Platform-provided behaviors for CE] HTMLButtonBehavior with type attribute alternative - #1356
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
0d905bc to
92bcb54
Compare
dandclark
left a comment
There was a problem hiding this comment.
At a first pass through, I like this. Just left some general early thoughts on the design.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
gregwhitworth
left a comment
There was a problem hiding this comment.
Some general questions and primarily "nits". Thank you so much for your great work on this.
|
|
||
| ### Behavior categories and composition | ||
|
|
||
| Behaviors are organized into a set of categories. Categories are conceptual groupings the platform uses to decide which behaviors can coexist on one element. They are not classes exposed to authors; authors only ever reference the concrete behaviors (the leaves below). |
There was a problem hiding this comment.
@slightlyoff raised at one point in this conversation why we're having abstractions. I think it's worth outlining why we're doing this bucketing rather than giving them more granular access. I personally like this design as I think 99% of authors are going to just want all of the goodness out of the box and also not have to keep adding capabilities as we introduce them into the platform (this is coming from years of having to support something similar) but it's worth noting (maybe in appendix or similar) why we're not currently exploring this path. I'm interested in @dandclark and your thoughts as this may also open a can of worms.
There was a problem hiding this comment.
Agreed this deserves to be written down. The granular / à-la-carte path (expose focusability, activation, form participation, etc. as independent primitives) is the low-level-primitives direction in Alternative 7 of the main explainer. When I move this alternative into the main explainer, I will leave the comments pointing to the granular approach.
|
|
||
| Mapping a few native patterns onto categories helps validate the model: | ||
|
|
||
| | Native pattern | Behavior | Category | Notes | |
There was a problem hiding this comment.
I really think this table is a great example of the power this provides
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
anaskim
left a comment
There was a problem hiding this comment.
Thanks for the thorough feedback!
|
|
||
| ### Behavior categories and composition | ||
|
|
||
| Behaviors are organized into a set of categories. Categories are conceptual groupings the platform uses to decide which behaviors can coexist on one element. They are not classes exposed to authors; authors only ever reference the concrete behaviors (the leaves below). |
There was a problem hiding this comment.
Agreed this deserves to be written down. The granular / à-la-carte path (expose focusability, activation, form participation, etc. as independent primitives) is the low-level-primitives direction in Alternative 7 of the main explainer. When I move this alternative into the main explainer, I will leave the comments pointing to the granular approach.
gregwhitworth
left a comment
There was a problem hiding this comment.
Thanks for the edits, I'm a go :)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
The premise of platform-provided behaviors is that authors delete JS and the platform runs the equivalent logic natively. If property and event surface still has to be forwarded in JS, that premise only half-holds, the code moves rather than disappears. If the platform reflected a behavior's properties and events onto the host, bundle size/construction cost/access cost go to zero. No bytes shipped, no per-instance setup, native property access. That's the difference between "custom elements can approximate built-ins" and "custom elements can match built-ins." I'd rather write something like this: class MoSwitch extends HTMLElement {
static formAssociated = true;
static behaviors = [HTMLCheckboxBehavior];
}And have e |
@mohamedmansour This is fair. I think Adobe also asked about this. I'd say if we can't offer this by default, there should be a way of opting-in and letting the browser do the reflection. Thanks for the comment, I'll take a look and discuss more. |
|
Thanks @anaskim, an opt-in would work for me. Two things that might help the discussion: My preference is reflection on by default, because "behaves like a checkbox" is what an author asks for, and having to say so twice is a redundant. But an opt-in that's a single declaration is fine, the thing I want to avoid is per-property forwarding. Something like: static behaviors = [HTMLCheckboxBehavior];
static reflectBehaviors = true; // or per-behavior: [{ behavior: HTMLCheckboxBehavior, reflect: true }]The reason to keep it opt-in is presumably name collisions, an author who already defines Same question applies to events, I'd want |
Not for merging, just getting comments/feedback in-line.