A partial archive of discourse.wicg.io as of Saturday February 24, 2024.

Exposing and preserving unrecognized properties on element inline-styles

stuartpb
2015-07-31

Right now, when a user sets the style on an element via element.style.someProperty = 'some-value', the browser rewrites that element’s style attribute by a method that only serializes out the properties that the browser recognizes. (I think I might have discovered this in another thread on here, but I can’t remember where.)

In the absence of a more robust CSS access model in the DOM (which still looks to be a far ways off, even with the Houdini WG working on it), having a place to store experimental CSS properties to be used by an element is very useful, eg. the way the Pointer Events Polyfill is currently considering polyfilling the behavior of the touch-action property.

I propose specifying a new model of the style attribute (or its prototype / interface, especially if it would raise the bar for the return value of getComputedStyle), making it effectively work like the dataset property when it comes to portions that are syntactically valid but specify unrecognized property names or values (accepting any string and returning any unrecognized values as the unrecognized string, making them available as camel-cased properties on style, then re-serializing them out when setting the string value of the attribute).

I’m aware there might be some limitations to how extensible this property may be (ie. it’s not possible to let element.style.border = 'wing-a-ding cheese whiz' change the type of element.style.border from 'object' to 'string'), but I think, for the sake of polyfillability, it’s worth specifying around those limitations, rather than just throwing up our hands and keeping it un-extensible.

stuartpb
2015-07-31

That thread I posted had a comment that notes it’s possible to work around the disappearance of properties by attaching a mutation listener, so that may be useful to create a polyfill for this kind of inline-style preservation (having it as a standard / globally-polyfilled behavior would make it so every other polyfill wouldn’t need to attach its own mutation observer).