Skip to content

Commit 3ca600e

Browse files
committed
Allow js.Dictionary as a tag attr value
1 parent acb4bfb commit 3ca600e

File tree

4 files changed

+40
-34
lines changed

4 files changed

+40
-34
lines changed

core/src/main/scala/japgolly/scalajs/react/vdom/Implicits.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ abstract class Implicits extends LowPri {
2929
implicit final val _react_attrJsFn : AttrValue[js.Function] = GenericAttr[js.Function]
3030
implicit final val _react_attrJsObj : AttrValue[js.Object] = GenericAttr[js.Object]
3131

32+
implicit final def _react_attrJsDictionary[A]: AttrValue[js.Dictionary[A]] =
33+
new GenericAttr[js.Dictionary[A]](d => d.asInstanceOf[js.Object])
34+
3235
@inline implicit final def _react_attrRef[R <: Ref]: AttrValue[R] =
3336
new GenericAttr[R](_.name)
3437

doc/changelog/0.10.4.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44

55
* `Callback.future` now re-throws captured exceptions.
66
* Add `RouterCtl.onSet` to perform additional actions when a route is set.
7+
* `js.Dictionary` can be used as a tag attribute value. ([#241](https://github.com/japgolly/scalajs-react/issues/241))

test/src/test/scala/japgolly/scalajs/react/CoreTest.scala

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,24 @@ object CoreTest extends TestSuite {
4343
def reactNode: ReactNode = H1("cool")
4444
def checkbox(check: Boolean) = input(`type` := "checkbox", checked := check)
4545

46-
'short - test(div(45: Short), "<div>45</div>")
47-
'byte - test(div(50: Byte), "<div>50</div>")
48-
'int - test(div(666), "<div>666</div>")
49-
'long - test(div(123L), "<div>123</div>")
50-
'double - test(div(12.3), "<div>12.3</div>")
51-
'string - test(div("yo"), "<div>yo</div>")
52-
'reactNode - test(div(reactNode), "<div><h1>cool</h1></div>")
53-
'comp - test(div(H1("a")), "<div><h1>a</h1></div>")
54-
'seqTag - test(div(Seq (span(1), span(2))), "<div><span>1</span><span>2</span></div>")
55-
'listTag - test(div(List(span(1), span(2))), "<div><span>1</span><span>2</span></div>")
56-
'listComp - test(div(List(H1("a"), H1("b"))), "<div><h1>a</h1><h1>b</h1></div>")
57-
'list2jAry - test(div(List(H1("a"), H1("b")).toJsArray), "<div><h1>a</h1><h1>b</h1></div>")
58-
'jAryTag - test(div(JArray(span(1), span(2))), "<div><span>1</span><span>2</span></div>")
59-
'jAryComp - test(div(JArray(H1("a"), H1("b"))), "<div><h1>a</h1><h1>b</h1></div>")
60-
'checkboxT - test(checkbox(true), """<input type="checkbox" checked=""/>""") // checked="" is new as of React 0.14 but it works
61-
'checkboxF - test(checkbox(false), """<input type="checkbox"/>""")
62-
'aria - test(div(aria.label := "ow", "a"), """<div aria-label="ow">a</div>""")
46+
'short - test(div(45: Short), "<div>45</div>")
47+
'byte - test(div(50: Byte), "<div>50</div>")
48+
'int - test(div(666), "<div>666</div>")
49+
'long - test(div(123L), "<div>123</div>")
50+
'double - test(div(12.3), "<div>12.3</div>")
51+
'string - test(div("yo"), "<div>yo</div>")
52+
'reactNode - test(div(reactNode), "<div><h1>cool</h1></div>")
53+
'comp - test(div(H1("a")), "<div><h1>a</h1></div>")
54+
'seqTag - test(div(Seq (span(1), span(2))), "<div><span>1</span><span>2</span></div>")
55+
'listTag - test(div(List(span(1), span(2))), "<div><span>1</span><span>2</span></div>")
56+
'listComp - test(div(List(H1("a"), H1("b"))), "<div><h1>a</h1><h1>b</h1></div>")
57+
'list2jAry - test(div(List(H1("a"), H1("b")).toJsArray), "<div><h1>a</h1><h1>b</h1></div>")
58+
'jAryTag - test(div(JArray(span(1), span(2))), "<div><span>1</span><span>2</span></div>")
59+
'jAryComp - test(div(JArray(H1("a"), H1("b"))), "<div><h1>a</h1><h1>b</h1></div>")
60+
'checkboxT - test(checkbox(true), """<input type="checkbox" checked=""/>""") // checked="" is new as of React 0.14 but it works
61+
'checkboxF - test(checkbox(false), """<input type="checkbox"/>""")
62+
'aria - test(div(aria.label := "ow", "a"), """<div aria-label="ow">a</div>""")
63+
'jsDict - test(div(style := js.Dictionary("a" -> "b")), """<div style="a:b;"></div>""")
6364

6465
'dangerouslySetInnerHtml - test(div(dangerouslySetInnerHtml("<span>")), "<div><span></div>")
6566

test/src/test/scala/japgolly/scalajs/react/PrefixedVdomTest.scala

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,24 @@ object PrefixedVdomTest extends TestSuite {
3131
def reactNode: ReactNode = H1("cool")
3232
def checkbox(check: Boolean) = <.input(^.`type` := "checkbox", ^.checked := check)
3333

34-
'short - test(<.div(45: Short), "<div>45</div>")
35-
'byte - test(<.div(50: Byte), "<div>50</div>")
36-
'int - test(<.div(666), "<div>666</div>")
37-
'long - test(<.div(123L), "<div>123</div>")
38-
'double - test(<.div(12.3), "<div>12.3</div>")
39-
'string - test(<.div("yo"), "<div>yo</div>")
40-
'reactNode - test(<.div(reactNode), "<div><h1>cool</h1></div>")
41-
'comp - test(<.div(H1("a")), "<div><h1>a</h1></div>")
42-
'seqTag - test(<.div(Seq (<.span(1), <.span(2))), "<div><span>1</span><span>2</span></div>")
43-
'listTag - test(<.div(List(<.span(1), <.span(2))), "<div><span>1</span><span>2</span></div>")
44-
'listComp - test(<.div(List(H1("a"), H1("b"))), "<div><h1>a</h1><h1>b</h1></div>")
45-
'list2jAry - test(<.div(List(H1("a"), H1("b")).toJsArray), "<div><h1>a</h1><h1>b</h1></div>")
46-
'jAryTag - test(<.div(JArray(<.span(1), <.span(2))), "<div><span>1</span><span>2</span></div>")
47-
'jAryComp - test(<.div(JArray(H1("a"), H1("b"))), "<div><h1>a</h1><h1>b</h1></div>")
48-
'checkboxT - test(checkbox(true), """<input type="checkbox" checked=""/>""") // checked="" is new as of React 0.14 but it works
49-
'checkboxF - test(checkbox(false), """<input type="checkbox"/>""")
50-
'aria - test(<.div(^.aria.label := "ow", "a"), """<div aria-label="ow">a</div>""")
34+
'short - test(<.div(45: Short), "<div>45</div>")
35+
'byte - test(<.div(50: Byte), "<div>50</div>")
36+
'int - test(<.div(666), "<div>666</div>")
37+
'long - test(<.div(123L), "<div>123</div>")
38+
'double - test(<.div(12.3), "<div>12.3</div>")
39+
'string - test(<.div("yo"), "<div>yo</div>")
40+
'reactNode - test(<.div(reactNode), "<div><h1>cool</h1></div>")
41+
'comp - test(<.div(H1("a")), "<div><h1>a</h1></div>")
42+
'seqTag - test(<.div(Seq (<.span(1), <.span(2))), "<div><span>1</span><span>2</span></div>")
43+
'listTag - test(<.div(List(<.span(1), <.span(2))), "<div><span>1</span><span>2</span></div>")
44+
'listComp - test(<.div(List(H1("a"), H1("b"))), "<div><h1>a</h1><h1>b</h1></div>")
45+
'list2jAry - test(<.div(List(H1("a"), H1("b")).toJsArray), "<div><h1>a</h1><h1>b</h1></div>")
46+
'jAryTag - test(<.div(JArray(<.span(1), <.span(2))), "<div><span>1</span><span>2</span></div>")
47+
'jAryComp - test(<.div(JArray(H1("a"), H1("b"))), "<div><h1>a</h1><h1>b</h1></div>")
48+
'checkboxT - test(checkbox(true), """<input type="checkbox" checked=""/>""") // checked="" is new as of React 0.14 but it works
49+
'checkboxF - test(checkbox(false), """<input type="checkbox"/>""")
50+
'aria - test(<.div(^.aria.label := "ow", "a"), """<div aria-label="ow">a</div>""")
51+
'jsDict - test(<.div(^.style := js.Dictionary("a" -> "b")), """<div style="a:b;"></div>""")
5152

5253
'dangerouslySetInnerHtml - test(<.div(^.dangerouslySetInnerHtml("<span>")), "<div><span></div>")
5354

0 commit comments

Comments
 (0)