When using the classMap directive in an SVG template, I get the following error:
Unhandled promise rejection TypeError: "setting getter-only property "className""
The error comes from this line in class-map.ts.
According to the SVG specification, className is a readonly property. This differs from className on Element, which can be set.
import {svg, render} from 'lit-html';
import {classMap} from 'lit-html/directives/class-map';
render(svg`<circle class=${classMap({active: true})} cx="23.401" cy="29.716" r="4.301"/>`, document.body);
https://stackblitz.com/edit/lit-html-svg-classname-bug-repro
The class active should have been applied to <circle>.
The following error is thrown:
Unhandled promise rejection TypeError: "setting getter-only property "className""
Should affect all browsers, but I only tested the ones checked below.
Would you like to fix this? Should be as simple as changing that to a el.setAttribute('class', value)
I would be glad to. I will have a pull request up later today or early tomorrow.
@jridgewell Fixed in #932.
Reopening because we had to revert #932
Any prospect of other approaches to get this to work?
For those like me who came here because classMap doesn't work on SVGs, my workaround is to have a function that concatenates a class string without using the classMap directive and assign direct to the class attribute.
const pointClass = d => `point${d.selected ? " selected" : ""}`
<g class=${pointClass(d)} >
Not sure if this works across browsers, I don't have IE / Edge installed at the moment, will try it there once pushed to test server.
Most helpful comment
Reopening because we had to revert #932