jsdom / cssstyle

A Node.js implementation of the CSS Object Model CSSStyleDeclaration interface
MIT License
107 stars 70 forks source link

fix: ensure priority is set before calling the onchange callback #152

Open LeahHirst opened 2 years ago

LeahHirst commented 2 years ago

fixes https://github.com/jsdom/jsdom/issues/2649

The onChange callback is called prematurely when invoking setProperty with an important priority. This results in elements wrongly being assigned an inline style attribute value without !important. Setting multiple important properties in jsdom results in the last one assigned missing !important:

const el = document.createElement('div');
el.style.setProperty('opacity', '0', 'important');
el.style.setProperty('width', '0', 'important');
el.getAttribute('style'); // `opacity: 0 !important; width: 0;`