From 3ca600eb255258863f1c8c0f2fbfd8a0df0b142a Mon Sep 17 00:00:00 2001 From: David Barri Date: Sat, 16 Jan 2016 11:59:31 +1100 Subject: [PATCH] Allow js.Dictionary as a tag attr value --- .../scalajs/react/vdom/Implicits.scala | 3 ++ doc/changelog/0.10.4.md | 1 + .../japgolly/scalajs/react/CoreTest.scala | 35 ++++++++++--------- .../scalajs/react/PrefixedVdomTest.scala | 35 ++++++++++--------- 4 files changed, 40 insertions(+), 34 deletions(-) diff --git a/core/src/main/scala/japgolly/scalajs/react/vdom/Implicits.scala b/core/src/main/scala/japgolly/scalajs/react/vdom/Implicits.scala index 6d0fceb73..74b97080a 100644 --- a/core/src/main/scala/japgolly/scalajs/react/vdom/Implicits.scala +++ b/core/src/main/scala/japgolly/scalajs/react/vdom/Implicits.scala @@ -29,6 +29,9 @@ abstract class Implicits extends LowPri { implicit final val _react_attrJsFn : AttrValue[js.Function] = GenericAttr[js.Function] implicit final val _react_attrJsObj : AttrValue[js.Object] = GenericAttr[js.Object] + implicit final def _react_attrJsDictionary[A]: AttrValue[js.Dictionary[A]] = + new GenericAttr[js.Dictionary[A]](d => d.asInstanceOf[js.Object]) + @inline implicit final def _react_attrRef[R <: Ref]: AttrValue[R] = new GenericAttr[R](_.name) diff --git a/doc/changelog/0.10.4.md b/doc/changelog/0.10.4.md index 86275780d..592682767 100644 --- a/doc/changelog/0.10.4.md +++ b/doc/changelog/0.10.4.md @@ -4,3 +4,4 @@ * `Callback.future` now re-throws captured exceptions. * Add `RouterCtl.onSet` to perform additional actions when a route is set. +* `js.Dictionary` can be used as a tag attribute value. ([#241](https://github.com/japgolly/scalajs-react/issues/241)) \ No newline at end of file diff --git a/test/src/test/scala/japgolly/scalajs/react/CoreTest.scala b/test/src/test/scala/japgolly/scalajs/react/CoreTest.scala index 5f24c08e7..b7fcb2345 100644 --- a/test/src/test/scala/japgolly/scalajs/react/CoreTest.scala +++ b/test/src/test/scala/japgolly/scalajs/react/CoreTest.scala @@ -43,23 +43,24 @@ object CoreTest extends TestSuite { def reactNode: ReactNode = H1("cool") def checkbox(check: Boolean) = input(`type` := "checkbox", checked := check) - 'short - test(div(45: Short), "
45
") - 'byte - test(div(50: Byte), "
50
") - 'int - test(div(666), "
666
") - 'long - test(div(123L), "
123
") - 'double - test(div(12.3), "
12.3
") - 'string - test(div("yo"), "
yo
") - 'reactNode - test(div(reactNode), "

cool

") - 'comp - test(div(H1("a")), "

a

") - 'seqTag - test(div(Seq (span(1), span(2))), "
12
") - 'listTag - test(div(List(span(1), span(2))), "
12
") - 'listComp - test(div(List(H1("a"), H1("b"))), "

a

b

") - 'list2jAry - test(div(List(H1("a"), H1("b")).toJsArray), "

a

b

") - 'jAryTag - test(div(JArray(span(1), span(2))), "
12
") - 'jAryComp - test(div(JArray(H1("a"), H1("b"))), "

a

b

") - 'checkboxT - test(checkbox(true), """""") // checked="" is new as of React 0.14 but it works - 'checkboxF - test(checkbox(false), """""") - 'aria - test(div(aria.label := "ow", "a"), """
a
""") + 'short - test(div(45: Short), "
45
") + 'byte - test(div(50: Byte), "
50
") + 'int - test(div(666), "
666
") + 'long - test(div(123L), "
123
") + 'double - test(div(12.3), "
12.3
") + 'string - test(div("yo"), "
yo
") + 'reactNode - test(div(reactNode), "

cool

") + 'comp - test(div(H1("a")), "

a

") + 'seqTag - test(div(Seq (span(1), span(2))), "
12
") + 'listTag - test(div(List(span(1), span(2))), "
12
") + 'listComp - test(div(List(H1("a"), H1("b"))), "

a

b

") + 'list2jAry - test(div(List(H1("a"), H1("b")).toJsArray), "

a

b

") + 'jAryTag - test(div(JArray(span(1), span(2))), "
12
") + 'jAryComp - test(div(JArray(H1("a"), H1("b"))), "

a

b

") + 'checkboxT - test(checkbox(true), """""") // checked="" is new as of React 0.14 but it works + 'checkboxF - test(checkbox(false), """""") + 'aria - test(div(aria.label := "ow", "a"), """
a
""") + 'jsDict - test(div(style := js.Dictionary("a" -> "b")), """
""") 'dangerouslySetInnerHtml - test(div(dangerouslySetInnerHtml("")), "
") diff --git a/test/src/test/scala/japgolly/scalajs/react/PrefixedVdomTest.scala b/test/src/test/scala/japgolly/scalajs/react/PrefixedVdomTest.scala index fe04f8a45..4eb193ac5 100644 --- a/test/src/test/scala/japgolly/scalajs/react/PrefixedVdomTest.scala +++ b/test/src/test/scala/japgolly/scalajs/react/PrefixedVdomTest.scala @@ -31,23 +31,24 @@ object PrefixedVdomTest extends TestSuite { def reactNode: ReactNode = H1("cool") def checkbox(check: Boolean) = <.input(^.`type` := "checkbox", ^.checked := check) - 'short - test(<.div(45: Short), "
45
") - 'byte - test(<.div(50: Byte), "
50
") - 'int - test(<.div(666), "
666
") - 'long - test(<.div(123L), "
123
") - 'double - test(<.div(12.3), "
12.3
") - 'string - test(<.div("yo"), "
yo
") - 'reactNode - test(<.div(reactNode), "

cool

") - 'comp - test(<.div(H1("a")), "

a

") - 'seqTag - test(<.div(Seq (<.span(1), <.span(2))), "
12
") - 'listTag - test(<.div(List(<.span(1), <.span(2))), "
12
") - 'listComp - test(<.div(List(H1("a"), H1("b"))), "

a

b

") - 'list2jAry - test(<.div(List(H1("a"), H1("b")).toJsArray), "

a

b

") - 'jAryTag - test(<.div(JArray(<.span(1), <.span(2))), "
12
") - 'jAryComp - test(<.div(JArray(H1("a"), H1("b"))), "

a

b

") - 'checkboxT - test(checkbox(true), """""") // checked="" is new as of React 0.14 but it works - 'checkboxF - test(checkbox(false), """""") - 'aria - test(<.div(^.aria.label := "ow", "a"), """
a
""") + 'short - test(<.div(45: Short), "
45
") + 'byte - test(<.div(50: Byte), "
50
") + 'int - test(<.div(666), "
666
") + 'long - test(<.div(123L), "
123
") + 'double - test(<.div(12.3), "
12.3
") + 'string - test(<.div("yo"), "
yo
") + 'reactNode - test(<.div(reactNode), "

cool

") + 'comp - test(<.div(H1("a")), "

a

") + 'seqTag - test(<.div(Seq (<.span(1), <.span(2))), "
12
") + 'listTag - test(<.div(List(<.span(1), <.span(2))), "
12
") + 'listComp - test(<.div(List(H1("a"), H1("b"))), "

a

b

") + 'list2jAry - test(<.div(List(H1("a"), H1("b")).toJsArray), "

a

b

") + 'jAryTag - test(<.div(JArray(<.span(1), <.span(2))), "
12
") + 'jAryComp - test(<.div(JArray(H1("a"), H1("b"))), "

a

b

") + 'checkboxT - test(checkbox(true), """""") // checked="" is new as of React 0.14 but it works + 'checkboxF - test(checkbox(false), """""") + 'aria - test(<.div(^.aria.label := "ow", "a"), """
a
""") + 'jsDict - test(<.div(^.style := js.Dictionary("a" -> "b")), """
""") 'dangerouslySetInnerHtml - test(<.div(^.dangerouslySetInnerHtml("")), "
")