Skip to content

Commit ee44674

Browse files
committed
fix: use DOM attribute as-is if it exists
Might fix #641
1 parent 234c197 commit ee44674

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

src/targets/web/globals.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,14 @@ Globals.assign({
8787
}
8888

8989
const { style, children, scrollTop, scrollLeft, ...attributes } = props!
90-
const filter =
91-
instance.nodeName === 'filter' ||
92-
(instance.parentNode && instance.parentNode.nodeName === 'filter')
9390

9491
if (scrollTop !== void 0) instance.scrollTop = scrollTop
9592
if (scrollLeft !== void 0) instance.scrollLeft = scrollLeft
9693

9794
// Set textContent, if children is an animatable value
9895
if (children !== void 0) instance.textContent = children
9996

100-
// Set styles ...
97+
// Apply CSS styles
10198
for (let styleName in style) {
10299
if (!style.hasOwnProperty(styleName)) continue
103100
var isCustomProperty = styleName.indexOf('--') === 0
@@ -111,18 +108,23 @@ Globals.assign({
111108
else instance.style[styleName] = styleValue
112109
}
113110

114-
// Set attributes ...
111+
const isFilterElement =
112+
instance.nodeName === 'filter' ||
113+
(instance.parentNode && instance.parentNode.nodeName === 'filter')
114+
115+
// Apply DOM attributes
115116
for (let name in attributes) {
116117
// Attributes are written in dash case
117-
const dashCase = filter
118-
? name
119-
: attributeCache[name] ||
120-
(attributeCache[name] = name.replace(
121-
/([A-Z])/g,
122-
n => '-' + n.toLowerCase()
123-
))
124-
if (typeof instance.getAttribute(dashCase) !== 'undefined')
125-
instance.setAttribute(dashCase, attributes[name])
118+
const attributeName =
119+
isFilterElement || instance.hasAttribute(name)
120+
? name
121+
: attributeCache[name] ||
122+
(attributeCache[name] = name.replace(
123+
/([A-Z])/g,
124+
n => '-' + n.toLowerCase()
125+
))
126+
127+
instance.setAttribute(attributeName, attributes[name])
126128
}
127129
},
128130
})

0 commit comments

Comments
 (0)