Replies: 2 comments 5 replies
-
|
Beta Was this translation helpful? Give feedback.
-
Just as an update @sorvell, we are looking into this (for Web Awesome), and I think there is a lot of value to it. Besides helping debugging by not cluttering devtools with extra attributes, it would also simplify some upcoming improvements, and would allow certain traits (e.g. variant) to be inheritable. That said, it is technically challenging to implement, so I’m not sure when (or even definitively if) we'll be able to ship this. Hope this helps! |
Beta Was this translation helpful? Give feedback.
-
Given HTML:
The resulting DOM looks like:
This is not how other platform elements like input work, causes a series of problems, and requires non-trivial code to accommodate.
It also leads to confusing and unexpected behavior:
Unfortunately, this is how Lit's built-in attribute reflection works (reflect: true). Shoelace augments this behavior to make attribute removal reset the default value.
I believe the main reason for this is (1) ensure there's a valid property value if the attribute is removed, (2) provide styling via the attribute.
Case 1 should be handled via a property setter that coerces an invalid value to a correct one (e.g. null would become the default value).
Case 2 should be handled via css custom :state(). This is now widely supported (last 2 major browser versions). While it's true that there's no declarative version of state, the attribute can be used as a fallback if this is important:
While this is admittedly a bit cumbersome, the need is rare.
Here is a proof of concept that these changes should be feasible.
Beta Was this translation helpful? Give feedback.
All reactions