Skip to content

fix: render CSS for component classes in a slice of KV types - #1527

Open
ruziba3vich wants to merge 1 commit into
a-h:mainfrom
ruziba3vich:fix-css-kv-slice-render
Open

ruziba3vich wants to merge 1 commit into
a-h:mainfrom
ruziba3vich:fix-css-kv-slice-render

Conversation

@ruziba3vich

Copy link
Copy Markdown

What

templ.RenderCSSItems writes nothing for component classes passed as a slice of templ.KV values:

templ.RenderCSSItems(ctx, w, []templ.KeyValue[templ.CSSClass, bool]{
	templ.KV(templ.CSSClass(c1), true),
})
// writes nothing

The class attribute gets the class name, because cssProcessor.Add handles []KeyValue[CSSClass, bool], but the <style> element for the class is never written. A single KeyValue[CSSClass, bool] and a map[CSSClass]bool are rendered.

Fix

cssItemsRenderer.Render handles []KeyValue[CSSClass, bool] by rendering each entry with the existing KeyValue[CSSClass, bool] case, so disabled classes are still skipped.

Tests

A new case in TestRenderCSS passes one enabled and one disabled class in a slice and checks the output. It fails on main.

@ruziba3vich
ruziba3vich force-pushed the fix-css-kv-slice-render branch from 7fc6ee3 to 1ad8c83 Compare November 23, 2026 15:38

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

1 participant