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

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/CSSStyleDeclaration.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ CSSStyleDeclaration.prototype = {
var isCustomProperty = name.indexOf('--') === 0;
if (isCustomProperty) {
this._setProperty(name, value, priority);
this._onChange(this.cssText);
return;
}
var lowercaseName = name.toLowerCase();
Expand All @@ -68,6 +69,7 @@ CSSStyleDeclaration.prototype = {

this[lowercaseName] = value;
this._importants[lowercaseName] = priority;
this._onChange(this.cssText);
},
_setProperty: function(name, value, priority) {
if (value === undefined) {
Expand All @@ -91,7 +93,6 @@ CSSStyleDeclaration.prototype = {
}
this._values[name] = value;
this._importants[name] = priority;
this._onChange(this.cssText);
},

/**
Expand Down
14 changes: 14 additions & 0 deletions lib/CSSStyleDeclaration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,20 @@ 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('onchange callback should be called when custom property is set', () => {
var style = new CSSStyleDeclaration(function(cssText) {
expect(cssText).toEqual('--test-prop: 0;');
});
style.setProperty('--test-prop', 0);
});

test('setting float should work the same as cssfloat', () => {
var style = new CSSStyleDeclaration();
style.float = 'left';
Expand Down