Skip to content

[cssom] is setting Element.style as a string specified anywhere? ElementCSSInlineStyle only has the getter #5127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pygy opened this issue May 28, 2020 · 3 comments

Comments

@pygy
Copy link

pygy commented May 28, 2020

I'm coming at this from microsoft/TypeScript#13466 which correctly points out that there is no setter for style in the old spec for ElementCSSInlineStyle. TS stops at that, and setting HTMLElement.style is thus a type error (same for SVGElement, both inherit from the mixin).

So I went out fishing for a spec for the setter and came out empty handed. The new CSSWG spec also lacks a setter... Is there such a thing, somewhere?

@Loirooriol
Copy link
Contributor

Loirooriol commented May 28, 2020

Yes, in CSSOM: https://drafts.csswg.org/cssom/#elementcssinlinestyle

interface mixin ElementCSSInlineStyle {
  [SameObject, PutForwards=cssText] readonly attribute CSSStyleDeclaration style;
};

Where PutForwards=cssText means (https://heycam.github.io/webidl/#PutForwards)

If the [PutForwards] extended attribute appears on a read only regular attribute declaration whose type is an interface type, it indicates that assigning to the attribute will have specific behavior. Namely, the assignment is “forwarded” to the attribute (specified by the extended attribute argument) on the object that is currently referenced by the attribute being assigned to.

So basically element.style = string is treated as element.style.cssText = string, and cssText has an explicit setter: https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-csstext

@emilio
Copy link
Collaborator

emilio commented May 29, 2020

Yes, [PutForwards] is what does the magic here.

@emilio emilio closed this as completed May 29, 2020
@pygy
Copy link
Author

pygy commented May 29, 2020

Thanks @Loirooriol @emilio !

The fact that setting null resets the styles is thus a side effect of the fact that "null" is not a valid declaration, correct?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants