Merge static and dynamic styles (#3950)
* Merge static and dynamic styles --------- Co-authored-by: Jonathan Kelley <jkelleyrtp@gmail.com>
This commit is contained in:
1 parent
68c7b903d5
commit
ad63d529fd
6 files changed
+47
-3
No files matched your search
@@ -58,6 +58,25 @@ export function setAttributeInner(
|
||||
node.innerHTML = value;
|
||||
break;
|
||||
|
||||
case "style":
|
||||
// Save the existing styles
|
||||
const existingStyles: Record<string, string> = {};
|
||||
|
||||
for (let i = 0; i < node.style.length; i++) {
|
||||
const prop = node.style[i];
|
||||
existingStyles[prop] = node.style.getPropertyValue(prop);
|
||||
}
|
||||
// Override all styles
|
||||
node.setAttribute(field, value);
|
||||
// Restore the old styles
|
||||
for (const prop in existingStyles) {
|
||||
// If it wasn't overridden, restore it
|
||||
if (!node.style.getPropertyValue(prop)) {
|
||||
node.style.setProperty(prop, existingStyles[prop]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case "multiple":
|
||||
setAttributeDefault(node, field, value);
|
||||
// reset the selected value whenever multiple changes
|
||||
|
||||
Reference in new issue
Block a user