Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to set css class for svg custom elements #919

Closed
danielpieper opened this issue Jan 29, 2024 · 1 comment
Closed

Unable to set css class for svg custom elements #919

danielpieper opened this issue Jan 29, 2024 · 1 comment

Comments

@danielpieper
Copy link

danielpieper commented Jan 29, 2024

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
Copy link
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants