Style attribute isn’t set in DOM
See original GitHub issueHi! Thank you for the lib!
Ran into an issue with a missing style
tag:
const { h } = require('picodom')
const hyperx = require('hyperx')
const html = hyperx(h, {attrToProp: false})
const a = html`<div style="height: 100%; background-color: red;">123</div>`
console.log(a)
console:
DOM:
<div>123</div>
Tried in the example pen (thought maybe hyperx is to blame), same thing:
Issue Analytics
- State:
- Created 6 years ago
- Comments:19 (11 by maintainers)
Top Results From Across the Web
JS can't set style property - Stack Overflow
Yeah I need all styles from older td to be copied to new td. Entire object. As Sebastian mentioned, style is read-only property....
Read more >Working with Attributes on DOM Elements - CSS-Tricks
Some HTML elements accept width and height as attributes. Some do not. Those attributes are sometimes referred to as presentational attributes.
Read more >Set style attributes directly instead of using cssText for inline ...
I am working on an app where there is a lot of motion and positions that are updated dynamically based on the state....
Read more >HTML attribute: disabled - HTML: HyperText Markup Language
The Boolean disabled attribute, when present, makes the element not ... If this attribute isn't set, the button can still be disabled from ......
Read more >Searching: getElement*, querySelector*
DOM navigation properties are great when elements are close to each other. ... inlined into HTML, but generally isn't a good thing.
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 Free
Top 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
Having thought more about this, I’ve changed my mind.
One reason not to support strings, is it makes it impossible to incrementally patch CSS properties, since you can’t directly diff between a string and an object - or, at least not without rolling out a CSS parser for the string first, which is likely out of the question. So, if we support strings, we’ll invite weird edge-cases where the style-property changes to/from a string/object.
Another argument is why use strings in the first place? Is there ever a good reason to do that?
The use of
style
in the first place, is likely mostly interesting for things like toggling state (collapse/expand, etc.) and hopefully never as a means of actually styling UI elements - for that, a CSS-in-JS framework, or just a good’ol CSS file and theclass
attribute, are likely much preferable. It’s likely not worth sweating over?this is more “surprise, a flat tire!” than “surprise, a trip to italy!”. to be fair, i do prefer all my network switches to randomly drop packets; i haven’t bought a boring, predictable switch in years. 😆