Skip to content
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
5 changes: 4 additions & 1 deletion cjs/interface/css-style-declaration.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ const handler = {
return getKeys(style).length;
if (/^\d+$/.test(name))
return getKeys(style)[name];
return style.get(uhyphen(name));

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather go for:

return style.get(uhyphen(name)) ?? '';

// Per CSSOM, reading a property that is not set returns the empty string,
// not undefined (which also matches getPropertyValue, routed here).
const value = style.get(uhyphen(name));
return value === void 0 ? '' : value;
},

set(style, name, value) {
Expand Down
5 changes: 4 additions & 1 deletion esm/interface/css-style-declaration.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ const handler = {
return getKeys(style).length;
if (/^\d+$/.test(name))
return getKeys(style)[name];
return style.get(uhyphen(name));
// Per CSSOM, reading a property that is not set returns the empty string,
// not undefined (which also matches getPropertyValue, routed here).
const value = style.get(uhyphen(name));
return value === void 0 ? '' : value;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather go for:

return style.get(uhyphen(name)) ?? '';

},

set(style, name, value) {
Expand Down
4 changes: 4 additions & 0 deletions test/interface/css-style-declaration.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ const {document} = parseHTML('');

let node = document.createElement('div');
assert(node.style.cssText, '', 'empty style');
// Per CSSOM, an unset property reads as the empty string, not undefined —
// matching getPropertyValue, which is routed through the same getter.
assert(node.style.color, '', 'unset property getter returns ""');
assert(node.style.getPropertyValue('color'), '', 'unset getPropertyValue returns ""');
node.style.cssText = 'background-color: blue; background-image: url("https://t.co/i.png");';
assert(node.style.backgroundColor, 'blue', 'style getter');
assert(node.style.backgroundImage, 'url("https://t.co/i.png")', 'style value with colon');
Expand Down