Skip to content
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

HTMLElement.style cannot be set directly #628

Closed
jledentu opened this issue Oct 19, 2022 · 1 comment · Fixed by #629
Closed

HTMLElement.style cannot be set directly #628

jledentu opened this issue Oct 19, 2022 · 1 comment · Fixed by #629
Labels
bug Something isn't working

Comments

@jledentu
Copy link
Contributor

Describe the bug

HTMLElement.style cannot be set, i.e element.style = 'display: none' doesn't work in happy-dom though it works in browsers (even if the style property is readonly according to the spec).

https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style#setting_styles

While this property is considered read-only, it is possible to set an inline style by assigning a string directly to the style property. In this case the string is forwarded to CSSStyleDeclaration.cssText. Using style in this manner will completely overwrite all inline styles on the element.

To Reproduce

const { Window } = require('happy-dom');

const window = new Window();
const document = window.document;
const button = document.createElement('button');
button.style = 'display: none';

console.log(button.outerHTML); // "<button></button>"

Expected behavior

const button = document.createElement('button');
button.style = 'display: none';
console.log(button.outerHTML); // should display "<button style="display: none"></button>"

Device:

  • Version 7.6.0
  • Node 16.17.1
@jledentu jledentu added the bug Something isn't working label Oct 19, 2022
@jledentu jledentu changed the title HTMLElement.style cannot be set HTMLElement.style cannot be set directly Oct 19, 2022
jledentu added a commit to jledentu/happy-dom that referenced this issue Oct 20, 2022
jledentu added a commit to jledentu/happy-dom that referenced this issue Oct 25, 2022
jledentu added a commit to jledentu/happy-dom that referenced this issue Oct 25, 2022
capricorn86 added a commit that referenced this issue Oct 25, 2022
#628@patch: Handle style setter in HTMLElement.
@capricorn86
Copy link
Owner

Thank you @jledentu for your contribution! 🙂

The fix has been released.

You can read more about the release here:
https://github.com/capricorn86/happy-dom/releases/tag/v7.6.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants