Fix invalid named color detection

If the named color is invalid, the value is not stored into the property.
This commit is contained in:
Frederic Junod
2018-01-12 13:34:03 +01:00
parent dc5b2a4ea0
commit bb0904f20d

View File

@@ -45,10 +45,14 @@ export function asString(color) {
function fromNamed(color) {
const el = document.createElement('div');
el.style.color = color;
document.body.appendChild(el);
const rgb = getComputedStyle(el).color;
document.body.removeChild(el);
return rgb;
if (el.style.color !== '') {
document.body.appendChild(el);
const rgb = getComputedStyle(el).color;
document.body.removeChild(el);
return rgb;
} else {
return '';
}
}