diff --git a/cjs/interface/css-style-declaration.js b/cjs/interface/css-style-declaration.js index 726ab98..845be4d 100644 --- a/cjs/interface/css-style-declaration.js +++ b/cjs/interface/css-style-declaration.js @@ -36,7 +36,7 @@ const handler = { return getKeys(style).length; if (/^\d+$/.test(name)) return getKeys(style)[name]; - return style.get(uhyphen(name)); + return style.get(uhyphen(name)) ?? ''; }, set(style, name, value) { diff --git a/esm/interface/css-style-declaration.js b/esm/interface/css-style-declaration.js index 7b8de0a..deb8b59 100644 --- a/esm/interface/css-style-declaration.js +++ b/esm/interface/css-style-declaration.js @@ -35,7 +35,7 @@ const handler = { return getKeys(style).length; if (/^\d+$/.test(name)) return getKeys(style)[name]; - return style.get(uhyphen(name)); + return style.get(uhyphen(name)) ?? ''; }, set(style, name, value) { diff --git a/test/interface/css-style-declaration.js b/test/interface/css-style-declaration.js index 767863f..baa5af2 100644 --- a/test/interface/css-style-declaration.js +++ b/test/interface/css-style-declaration.js @@ -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');