Browse Source

[web] Don't leave emtpy style attribute if nothing as applied

pull/702/head
Shagen Ogandzhanian 4 years ago
parent
commit
8118bb7cbe
  1. 3
      web/core/src/jsMain/kotlin/androidx/compose/web/DomApplier.kt
  2. 8
      web/core/src/jsTest/kotlin/DomSideEffectTests.kt
  3. 6
      web/core/src/jsTest/kotlin/InlineStyleTests.kt
  4. 6
      web/core/src/jsTest/kotlin/elements/AttributesTests.kt
  5. 64
      web/core/src/jsTest/kotlin/elements/TableTests.kt

3
web/core/src/jsMain/kotlin/androidx/compose/web/DomApplier.kt

@ -80,8 +80,7 @@ class DomNodeWrapper(val node: Node) {
fun updateStyleDeclarations(style: StyleHolder?) { fun updateStyleDeclarations(style: StyleHolder?) {
val htmlElement = node as? HTMLElement ?: return val htmlElement = node as? HTMLElement ?: return
// TODO: typed-om-polyfill hasn't StylePropertyMap::clear() htmlElement.removeAttribute("style")
htmlElement.style.cssText = ""
style?.properties?.forEach { (name, value) -> style?.properties?.forEach { (name, value) ->
setProperty(htmlElement.attributeStyleMap, name, value) setProperty(htmlElement.attributeStyleMap, name, value)

8
web/core/src/jsTest/kotlin/DomSideEffectTests.kt

@ -29,7 +29,7 @@ class DomSideEffectTests {
} }
} }
assertEquals( assertEquals(
expected = "<div><div style=\"\"><p>Hello World!</p></div></div>", expected = "<div><div><p>Hello World!</p></div></div>",
actual = root.outerHTML actual = root.outerHTML
) )
} }
@ -57,7 +57,7 @@ class DomSideEffectTests {
composition { CustomDiv(i) } composition { CustomDiv(i) }
assertEquals( assertEquals(
expected = "<div><div style=\"\">Value = 0</div></div>", expected = "<div><div>Value = 0</div></div>",
actual = root.outerHTML actual = root.outerHTML
) )
@ -75,7 +75,7 @@ class DomSideEffectTests {
message = "onDispose should be called with a previous value" message = "onDispose should be called with a previous value"
) )
assertEquals( assertEquals(
expected = "<div><div style=\"\">Value = 1</div></div>", expected = "<div><div>Value = 1</div></div>",
actual = root.outerHTML actual = root.outerHTML
) )
} }
@ -97,7 +97,7 @@ class DomSideEffectTests {
} }
assertEquals( assertEquals(
expected = "<div><div style=\"\">Goedemorgen!</div></div>", expected = "<div><div>Goedemorgen!</div></div>",
actual = root.outerHTML actual = root.outerHTML
) )

6
web/core/src/jsTest/kotlin/InlineStyleTests.kt

@ -67,7 +67,7 @@ class InlineStyleTests {
} }
assertEquals( assertEquals(
expected = "<span style=\"\">text</span>", expected = "<span>text</span>",
actual = root.innerHTML actual = root.innerHTML
) )
@ -106,7 +106,7 @@ class InlineStyleTests {
waitChanges() waitChanges()
assertEquals( assertEquals(
expected = "<span style=\"\">text</span>", expected = "<span>text</span>",
actual = root.innerHTML actual = root.innerHTML
) )
} }
@ -140,7 +140,7 @@ class InlineStyleTests {
val expected = if (isRed) { val expected = if (isRed) {
"<span style=\"color: red;\">text</span>" "<span style=\"color: red;\">text</span>"
} else { } else {
"<span style=\"\">text</span>" "<span>text</span>"
} }
assertEquals( assertEquals(
expected = expected, expected = expected,

6
web/core/src/jsTest/kotlin/elements/AttributesTests.kt

@ -25,7 +25,7 @@ class AttributesTests {
} }
assertEquals( assertEquals(
expected = "<label for=\"l1\" style=\"\">label</label>", expected = "<label for=\"l1\">label</label>",
actual = root.innerHTML actual = root.innerHTML
) )
} }
@ -38,7 +38,7 @@ class AttributesTests {
} }
assertEquals( assertEquals(
expected = "<label style=\"\">label</label>", expected = "<label>label</label>",
actual = root.innerHTML actual = root.innerHTML
) )
} }
@ -57,7 +57,7 @@ class AttributesTests {
} }
assertEquals( assertEquals(
expected = "<label for=\"lb1\" style=\"\">label</label>", expected = "<label for=\"lb1\">label</label>",
actual = root.innerHTML actual = root.innerHTML
) )
} }

64
web/core/src/jsTest/kotlin/elements/TableTests.kt

@ -137,45 +137,45 @@ class TableTests {
assertEquals( assertEquals(
expected = """ expected = """
<table style=""> <table>
<caption style="">CaptionText</caption> <caption>CaptionText</caption>
<colgroup style=""> <colgroup>
<col style=""> <col>
<col style=""> <col>
<col style=""> <col>
</colgroup> </colgroup>
<thead style=""> <thead>
<tr style=""> <tr>
<th style=""></th> <th></th>
<th style=""></th> <th></th>
<th colspan="2" style="">First</th> <th colspan="2">First</th>
</tr> </tr>
<tr style=""> <tr>
<th style=""></th> <th></th>
<th style=""></th> <th></th>
<th scope="col" style="">A</th> <th scope="col">A</th>
<th scope="col" style="">B</th> <th scope="col">B</th>
</tr> </tr>
</thead> </thead>
<tbody style=""> <tbody>
<tr style=""> <tr>
<th scope="row" rowspan="2" style="">Rows</th> <th scope="row" rowspan="2">Rows</th>
<th scope="row" style="">1</th> <th scope="row">1</th>
<td style="">30</td> <td>30</td>
<td style="">40</td> <td>40</td>
</tr> </tr>
<tr style=""> <tr>
<th scope="row" style="">2</th> <th scope="row">2</th>
<td style="">10</td> <td>10</td>
<td style="">20</td> <td>20</td>
</tr> </tr>
</tbody> </tbody>
<tfoot style=""> <tfoot>
<tr style=""> <tr>
<th scope="row" style="">Totals</th> <th scope="row">Totals</th>
<th style=""></th> <th></th>
<td style="">40</td> <td>40</td>
<td style="">60</td> <td>60</td>
</tr> </tr>
</tfoot> </tfoot>
</table> </table>

Loading…
Cancel
Save