Content vs IDL attributes and "browser quality" elements #2256
Replies: 2 comments 6 replies
-
Would it make sense to have a decorator that did this for us? Could a decorator do this? |
Beta Was this translation helpful? Give feedback.
-
Interesting topic.
I'd probably ask if there are good reasons to emulate it. There are some nice things about making sure properties are valid, but setting a property and reading it back immediately with a different value breaks expectations around how JS objects and properties behave. My general rule of thumb for accessors is that they should try to work like plain properties as much as possible. So the question because do you want to behave like HTML elements or JS object? And what do you get out of acting like built-in elements, more than a purity aspect?
I was thinking an attribute converter could help here, but it seems like that would only help for values set as attributes. Converters don't really have the shape to validate and transform property sets (though you could maybe force it into toAttribute). I think we would consider a feature request for this, because the type of solution you showed actually creates another property for internal storage and another set of accessors, and the usage of |
Beta Was this translation helpful? Give feedback.
-
Browser elements like
<input>
separate content attributes from IDL attributes - especially for enums - in a way that isn't common in Lit elements:A visual example may be helpful:
The HTML spec goes into more detail on how browsers reflect enumerated attributes:
While developing a textual input component in Lit that aspires to be "native browser quality," I've reproduced the behavior of
<input>
by separating content attributes (DOM) from IDL attributes (state):In Lit, this pattern is more verbose than the typical
reflect: true
and it took me a few tries to land on this solution while referencing the docs. Which begs the questions:Beta Was this translation helpful? Give feedback.
All reactions