maxence-charriere / go-app

A package to build progressive web apps with Go programming language and WebAssembly.
https://go-app.dev
MIT License
7.75k stars 354 forks source link

Unable to set css class for svg custom elements #919

Closed danielpieper closed 3 weeks ago

danielpieper commented 4 months ago

I have used app.Raw() for svg in the past and now i'm trying out rendering them as custom elements. It occurred to me that the css class is not applied. This is the render function i was using:

func (c *DownloadIcon) Render() app.UI {
    return app.Elem("svg").
        XMLNS("http://www.w3.org/2000/svg").
        Aria("hidden", "true").
        Class(c.cClass...).
        Attr("viewBox", "0 0 24 24").
        Attr("fill", "currentColor").
        Body(
            app.ElemSelfClosing("path").
                Attr("d", "M13 11.1V4a1 1 0 1 0-2 0v7.1L8.8 8.4a1 1 0 1 0-1.6 1.2l4 5a1 1 0 0 0 1.6 0l4-5a1 1 0 1 0-1.6-1.2L13 11Z").
                Attr("fill-rule", "evenodd").
                Attr("clip-rule", "evenodd").
                XMLNS("http://www.w3.org/2000/svg"),
            app.ElemSelfClosing("path").
                Attr("d", "M9.7 15.9 7.4 13H5a2 2 0 0 0-2 2v4c0 1.1.9 2 2 2h14a2 2 0 0 0 2-2v-4a2 2 0 0 0-2-2h-2.4l-2.3 2.9a3 3 0 0 1-4.6 0Zm7.3.1a1 1 0 1 0 0 2 1 1 0 1 0 0-2Z").
                Attr("fill-rule", "evenodd").
                Attr("clip-rule", "evenodd").
                XMLNS("http://www.w3.org/2000/svg"),
        )
}

It seems that there is an issue with how the property is set, see https://stackoverflow.com/questions/37943006/unable-to-change-class-name-of-svg-element and here: https://github.com/maxence-charriere/go-app/blob/master/pkg/app/attribute.go#L105

Any way we could use setAttribute as done in the default case? https://github.com/maxence-charriere/go-app/blob/master/pkg/app/attribute.go#L134 I've just tested out setAttribute instead of the className property and it works (on my machine)

maxence-charriere commented 3 weeks ago

Fixed in https://github.com/maxence-charriere/go-app/releases/tag/v10.0.4