Skip to content

Commit

Permalink
fix: use DOM attribute as-is if it exists
Browse files Browse the repository at this point in the history
Might fix #641
  • Loading branch information
aleclarson committed Jun 1, 2019
1 parent 267c9a8 commit 9bacb1c
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/targets/web/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,14 @@ Globals.assign({
}

const { style, children, scrollTop, scrollLeft, ...attributes } = props!
const filter =
instance.nodeName === 'filter' ||
(instance.parentNode && instance.parentNode.nodeName === 'filter')

if (scrollTop !== void 0) instance.scrollTop = scrollTop
if (scrollLeft !== void 0) instance.scrollLeft = scrollLeft

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

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

// Set attributes ...
const isFilterElement =
instance.nodeName === 'filter' ||
(instance.parentNode && instance.parentNode.nodeName === 'filter')

// Apply DOM attributes
for (let name in attributes) {
// Attributes are written in dash case
const dashCase = filter
? name
: attributeCache[name] ||
(attributeCache[name] = name.replace(
/([A-Z])/g,
n => '-' + n.toLowerCase()
))
if (typeof instance.getAttribute(dashCase) !== 'undefined')
instance.setAttribute(dashCase, attributes[name])
const attributeName =
isFilterElement || instance.hasAttribute(name)
? name
: attributeCache[name] ||
(attributeCache[name] = name.replace(
/([A-Z])/g,
n => '-' + n.toLowerCase()
))

instance.setAttribute(attributeName, attributes[name])
}
},
})

0 comments on commit 9bacb1c

Please sign in to comment.