pierbezuhoff
10/07/2025, 2:49 AMCanvasBasedWindow to ComposeViewport i found that after pressing Tab the canvas becomes focused and gains a distracting white outline (on chrome). Is there a way to apply CSS to the canvas? It's under shadow-root so normal stylesheets don't affect it.Vidmantas Kerbelis
10/07/2025, 5:54 AMcanvas {
outline: none;
}
From the latest Compose version, the <canvas> is now part of a #shadow-root, and it does not directly get all of the CSS styling, unless I just don't know how to.
I found a workaround for this, which is:
ComposeViewport {
LaunchedEffect(Unit) {
main.shadowRoot?.let { shadowRoot ->
val style = document.createElement("style") as HTMLStyleElement
style.textContent = """
canvas {
outline: none;
}
""".trimIndent()
shadowRoot.appendChild(style)
}
}
}
This appends the canvas style in the shadowRoot once it is created, and removes the focus and the outlineOleksandr Karpovich [JB]
10/07/2025, 2:58 PMRok Oblak
10/08/2025, 6:47 AMOleksandr Karpovich [JB]
10/08/2025, 7:32 AMAlex Styl
10/12/2025, 6:36 AMVidmantas Kerbelis
10/12/2025, 7:53 AMComposeViewport,
val main = document.body!!.getElementsByTagName("main")[0]!!
ComposeViewport(main) { }
Sorry, quickly typed the snippet up, assumed that this part was implicitly evidentAlex Styl
10/12/2025, 8:05 AMval composeTarget = document.getElementById("ComposeTarget") ?: error("No ComposeTarget")
ComposeViewport(composeTarget) {
LaunchedEffect(Unit) {
composeTarget.shadowRoot?.let { shadowRoot ->
val style = document.createElement("style") as HTMLStyleElement
style.textContent = """
canvas {
outline: none;
}
""".trimIndent()
shadowRoot.appendChild(style)
}
}