From caaee7c2fc537af03f2fc1af66aec61df05fb27e Mon Sep 17 00:00:00 2001 From: Leah Hirst Date: Thu, 25 Aug 2022 14:36:14 +0100 Subject: [PATCH] fix: ensure priority is set before calling the onchange callback --- lib/CSSStyleDeclaration.js | 2 +- lib/CSSStyleDeclaration.test.js | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/CSSStyleDeclaration.js b/lib/CSSStyleDeclaration.js index bded9a44..63799d1c 100644 --- a/lib/CSSStyleDeclaration.js +++ b/lib/CSSStyleDeclaration.js @@ -68,6 +68,7 @@ CSSStyleDeclaration.prototype = { this[lowercaseName] = value; this._importants[lowercaseName] = priority; + this._onChange(this.cssText); }, _setProperty: function(name, value, priority) { if (value === undefined) { @@ -91,7 +92,6 @@ CSSStyleDeclaration.prototype = { } this._values[name] = value; this._importants[name] = priority; - this._onChange(this.cssText); }, /** diff --git a/lib/CSSStyleDeclaration.test.js b/lib/CSSStyleDeclaration.test.js index 9fa8ed3b..db4b310f 100644 --- a/lib/CSSStyleDeclaration.test.js +++ b/lib/CSSStyleDeclaration.test.js @@ -359,6 +359,13 @@ describe('CSSStyleDeclaration', () => { style.setProperty('opacity', 0); }); + test('onchange callback should be called when priority is specified on a setProperty call', () => { + var style = new CSSStyleDeclaration(function(cssText) { + expect(cssText).toEqual('opacity: 0 !important;'); + }); + style.setProperty('opacity', 0, 'important'); + }); + test('setting float should work the same as cssfloat', () => { var style = new CSSStyleDeclaration(); style.float = 'left';