diff --git a/web/core/src/jsMain/kotlin/org/jetbrains/compose/web/elements/Elements.kt b/web/core/src/jsMain/kotlin/org/jetbrains/compose/web/elements/Elements.kt index afab3a5d8c..66c3049e08 100644 --- a/web/core/src/jsMain/kotlin/org/jetbrains/compose/web/elements/Elements.kt +++ b/web/core/src/jsMain/kotlin/org/jetbrains/compose/web/elements/Elements.kt @@ -943,8 +943,8 @@ fun Style( * @param rulesBuild allows to define the style rules using [StyleSheetBuilder] */ @Composable -fun Style( - applyAttrs: (AttrsBuilder.() -> Unit)? = null, +inline fun Style( + noinline applyAttrs: (AttrsBuilder.() -> Unit)? = null, rulesBuild: StyleSheetBuilder.() -> Unit ) { val builder = StyleSheetBuilderImpl() diff --git a/web/core/src/jsTest/kotlin/elements/StyleTest.kt b/web/core/src/jsTest/kotlin/elements/StyleTest.kt new file mode 100644 index 0000000000..ad6c499588 --- /dev/null +++ b/web/core/src/jsTest/kotlin/elements/StyleTest.kt @@ -0,0 +1,38 @@ +/* + * Copyright 2020-2021 JetBrains s.r.o. and respective authors and developers. + * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file. + */ + +package org.jetbrains.compose.web.core.tests.elements + +import androidx.compose.runtime.* +import org.jetbrains.compose.web.css.* +import org.jetbrains.compose.web.dom.* +import org.jetbrains.compose.web.testutils.* +import org.w3c.dom.* +import org.w3c.dom.css.* +import kotlin.test.* + +class StyleTest { + @Test + fun testingComposableStyle() = runTest { + var color by mutableStateOf(Color.green) + composition { + Style { + val element = remember { "body" } + element { + backgroundColor(color) + } + } + } + val element = root.firstChild + assertTrue(element is HTMLStyleElement) + val sheet = element.sheet + assertTrue(sheet is CSSStyleSheet) + assertEquals("""body { background-color: green; }""", sheet.cssRules.asList().single().cssText) + + color = Color.red + waitForRecompositionComplete() + assertEquals("""body { background-color: red; }""", sheet.cssRules.asList().single().cssText) + } +}