Value defaults not committed to DOM
See original GitHub issueWould it make sense to always write value defaults to their respective DOM attributes when the controller loads, as is done on write to a value property? I currently have to remember to explicitly write them in connect
with this.someValue = this.constructor.values.some.default
for every such value to achieve this behavior.
If this feature is desired I’d be happy to implement it. Thanks!
Issue Analytics
- State:
- Created a year ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Default value of state is not updated between renders
The default value is intentionally only used when the component mounts. That's what's meant by "default". After that, the only way to change ......
Read more >Default properties values are not working · Issue #114 - GitHub
Description Default values are not being applied when a property has one specified and its corresponding attribute is not defined.
Read more >Using CSS custom properties (variables) - MDN Web Docs
Custom property fallback values ... Using the var() function, you can define multiple fallback values when the given variable is not yet defined; ......
Read more >Refs and the DOM - React
Refs provide a way to access DOM nodes or React elements created in the render ... By default, you may not use the...
Read more >Lifecycle - Lit.dev
Use the element constructor for initializing LitElement properties with default values. (Attribute values from the DOM are not available when the ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Even if you do set the value in JS on load - this approach could cause a flash of the unstyled (no data attribute) content.
Hence you would be best to add the default styles case in your css (e.g. element
:not([data-my-foo-value])
).Once you have default styles for when the value is not set - you don’t need to worry about default attribute setting.
@lb- That’s a good approach I hadn’t considered and should, in principle, suit my needs. Thank you!