Browse Source

Introduce minimal backgroundAttachment to the CSS API

pull/857/head
Shagen Ogandzhanian 3 years ago
parent
commit
585da89c8c
  1. 5
      web/core/src/jsMain/kotlin/androidx/compose/web/css/properties/background.kt
  2. 21
      web/core/src/jsTest/kotlin/css/CSSBackgroundTests.kt

5
web/core/src/jsMain/kotlin/androidx/compose/web/css/properties/background.kt

@ -11,4 +11,9 @@ fun StyleBuilder.backgroundColor(value: String) {
fun StyleBuilder.backgroundColor(value: CSSColorValue) { fun StyleBuilder.backgroundColor(value: CSSColorValue) {
property("background-color", value) property("background-color", value)
}
// https://developer.mozilla.org/en-US/docs/Web/CSS/background-attachment
fun StyleBuilder.backgroundAttachment(value: String) {
property("background-attachment", value)
} }

21
web/core/src/jsTest/kotlin/css/CSSBackgroundTests.kt

@ -7,6 +7,7 @@ package org.jetbrains.compose.web.core.tests.css
import kotlinx.browser.window import kotlinx.browser.window
import org.jetbrains.compose.web.core.tests.runTest import org.jetbrains.compose.web.core.tests.runTest
import org.jetbrains.compose.web.css.backgroundAttachment
import org.jetbrains.compose.web.css.backgroundColor import org.jetbrains.compose.web.css.backgroundColor
import org.jetbrains.compose.web.dom.Div import org.jetbrains.compose.web.dom.Div
import org.w3c.dom.HTMLElement import org.w3c.dom.HTMLElement
@ -29,4 +30,24 @@ class CSSBackgroundTests {
assertEquals("rgb(0, 128, 0)", window.getComputedStyle(root.children[0] as HTMLElement).backgroundColor) assertEquals("rgb(0, 128, 0)", window.getComputedStyle(root.children[0] as HTMLElement).backgroundColor)
assertEquals("rgba(0, 129, 0, 0.2)", window.getComputedStyle(root.children[1] as HTMLElement).backgroundColor) assertEquals("rgba(0, 129, 0, 0.2)", window.getComputedStyle(root.children[1] as HTMLElement).backgroundColor)
} }
@Test
fun backgroundAttachment() = runTest {
composition {
Div({style {
backgroundAttachment("scroll")
}})
Div({style {
backgroundAttachment("fixed")
}})
Div({style {
backgroundAttachment("local")
}})
}
assertEquals("scroll", window.getComputedStyle(root.children[0] as HTMLElement).backgroundAttachment)
assertEquals("fixed", window.getComputedStyle(root.children[1] as HTMLElement).backgroundAttachment)
assertEquals("local", window.getComputedStyle(root.children[2] as HTMLElement).backgroundAttachment)
}
} }
Loading…
Cancel
Save