Skip to content

Commit

Permalink
fix: svg class name not working. used setAttribute instead
Browse files Browse the repository at this point in the history
For other DOM element className is a string, but for SVG it's an SVGAnimatedString object.
  • Loading branch information
jorenrui committed Feb 12, 2024
1 parent 6495dda commit cdefac6
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions lib/entity/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class Attributes {
this.base = base
this.dynamicAttributes = []
this.childClone = null
this.initialState = { className: this.base.element.className }
this.initialState = { classList: this.base.element.classList }

this._getDynamicAttributes()
}
Expand All @@ -35,10 +35,6 @@ export class Attributes {
}
}

get baseClasses() {
return this.initialState.className.split(' ')
}

async evaluate() {
await this.evaluateClass()
await this.evaluateText()
Expand Down Expand Up @@ -69,10 +65,12 @@ export class Attributes {
const expr = this.base.element.getAttribute(':class')
if (!expr) return

this.base.element.className = await this.base._interpret(expr, {
base: this.baseClasses,
const updatedClassNames = await this.base._interpret(expr, {
base: this.initialState.classList,
isClass: true,
})

this.base.element.setAttribute('class', updatedClassNames)
}

async evaluateText() {
Expand Down

0 comments on commit cdefac6

Please sign in to comment.