Skip to content

Commit

Permalink
Allow js.Dictionary as a tag attr value
Browse files Browse the repository at this point in the history
  • Loading branch information
japgolly committed Jan 16, 2016
1 parent acb4bfb commit 3ca600e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions doc/changelog/0.10.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
35 changes: 18 additions & 17 deletions test/src/test/scala/japgolly/scalajs/react/CoreTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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), "<div>45</div>")
'byte - test(div(50: Byte), "<div>50</div>")
'int - test(div(666), "<div>666</div>")
'long - test(div(123L), "<div>123</div>")
'double - test(div(12.3), "<div>12.3</div>")
'string - test(div("yo"), "<div>yo</div>")
'reactNode - test(div(reactNode), "<div><h1>cool</h1></div>")
'comp - test(div(H1("a")), "<div><h1>a</h1></div>")
'seqTag - test(div(Seq (span(1), span(2))), "<div><span>1</span><span>2</span></div>")
'listTag - test(div(List(span(1), span(2))), "<div><span>1</span><span>2</span></div>")
'listComp - test(div(List(H1("a"), H1("b"))), "<div><h1>a</h1><h1>b</h1></div>")
'list2jAry - test(div(List(H1("a"), H1("b")).toJsArray), "<div><h1>a</h1><h1>b</h1></div>")
'jAryTag - test(div(JArray(span(1), span(2))), "<div><span>1</span><span>2</span></div>")
'jAryComp - test(div(JArray(H1("a"), H1("b"))), "<div><h1>a</h1><h1>b</h1></div>")
'checkboxT - test(checkbox(true), """<input type="checkbox" checked=""/>""") // checked="" is new as of React 0.14 but it works
'checkboxF - test(checkbox(false), """<input type="checkbox"/>""")
'aria - test(div(aria.label := "ow", "a"), """<div aria-label="ow">a</div>""")
'short - test(div(45: Short), "<div>45</div>")
'byte - test(div(50: Byte), "<div>50</div>")
'int - test(div(666), "<div>666</div>")
'long - test(div(123L), "<div>123</div>")
'double - test(div(12.3), "<div>12.3</div>")
'string - test(div("yo"), "<div>yo</div>")
'reactNode - test(div(reactNode), "<div><h1>cool</h1></div>")
'comp - test(div(H1("a")), "<div><h1>a</h1></div>")
'seqTag - test(div(Seq (span(1), span(2))), "<div><span>1</span><span>2</span></div>")
'listTag - test(div(List(span(1), span(2))), "<div><span>1</span><span>2</span></div>")
'listComp - test(div(List(H1("a"), H1("b"))), "<div><h1>a</h1><h1>b</h1></div>")
'list2jAry - test(div(List(H1("a"), H1("b")).toJsArray), "<div><h1>a</h1><h1>b</h1></div>")
'jAryTag - test(div(JArray(span(1), span(2))), "<div><span>1</span><span>2</span></div>")
'jAryComp - test(div(JArray(H1("a"), H1("b"))), "<div><h1>a</h1><h1>b</h1></div>")
'checkboxT - test(checkbox(true), """<input type="checkbox" checked=""/>""") // checked="" is new as of React 0.14 but it works
'checkboxF - test(checkbox(false), """<input type="checkbox"/>""")
'aria - test(div(aria.label := "ow", "a"), """<div aria-label="ow">a</div>""")
'jsDict - test(div(style := js.Dictionary("a" -> "b")), """<div style="a:b;"></div>""")

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

Expand Down
35 changes: 18 additions & 17 deletions test/src/test/scala/japgolly/scalajs/react/PrefixedVdomTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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), "<div>45</div>")
'byte - test(<.div(50: Byte), "<div>50</div>")
'int - test(<.div(666), "<div>666</div>")
'long - test(<.div(123L), "<div>123</div>")
'double - test(<.div(12.3), "<div>12.3</div>")
'string - test(<.div("yo"), "<div>yo</div>")
'reactNode - test(<.div(reactNode), "<div><h1>cool</h1></div>")
'comp - test(<.div(H1("a")), "<div><h1>a</h1></div>")
'seqTag - test(<.div(Seq (<.span(1), <.span(2))), "<div><span>1</span><span>2</span></div>")
'listTag - test(<.div(List(<.span(1), <.span(2))), "<div><span>1</span><span>2</span></div>")
'listComp - test(<.div(List(H1("a"), H1("b"))), "<div><h1>a</h1><h1>b</h1></div>")
'list2jAry - test(<.div(List(H1("a"), H1("b")).toJsArray), "<div><h1>a</h1><h1>b</h1></div>")
'jAryTag - test(<.div(JArray(<.span(1), <.span(2))), "<div><span>1</span><span>2</span></div>")
'jAryComp - test(<.div(JArray(H1("a"), H1("b"))), "<div><h1>a</h1><h1>b</h1></div>")
'checkboxT - test(checkbox(true), """<input type="checkbox" checked=""/>""") // checked="" is new as of React 0.14 but it works
'checkboxF - test(checkbox(false), """<input type="checkbox"/>""")
'aria - test(<.div(^.aria.label := "ow", "a"), """<div aria-label="ow">a</div>""")
'short - test(<.div(45: Short), "<div>45</div>")
'byte - test(<.div(50: Byte), "<div>50</div>")
'int - test(<.div(666), "<div>666</div>")
'long - test(<.div(123L), "<div>123</div>")
'double - test(<.div(12.3), "<div>12.3</div>")
'string - test(<.div("yo"), "<div>yo</div>")
'reactNode - test(<.div(reactNode), "<div><h1>cool</h1></div>")
'comp - test(<.div(H1("a")), "<div><h1>a</h1></div>")
'seqTag - test(<.div(Seq (<.span(1), <.span(2))), "<div><span>1</span><span>2</span></div>")
'listTag - test(<.div(List(<.span(1), <.span(2))), "<div><span>1</span><span>2</span></div>")
'listComp - test(<.div(List(H1("a"), H1("b"))), "<div><h1>a</h1><h1>b</h1></div>")
'list2jAry - test(<.div(List(H1("a"), H1("b")).toJsArray), "<div><h1>a</h1><h1>b</h1></div>")
'jAryTag - test(<.div(JArray(<.span(1), <.span(2))), "<div><span>1</span><span>2</span></div>")
'jAryComp - test(<.div(JArray(H1("a"), H1("b"))), "<div><h1>a</h1><h1>b</h1></div>")
'checkboxT - test(checkbox(true), """<input type="checkbox" checked=""/>""") // checked="" is new as of React 0.14 but it works
'checkboxF - test(checkbox(false), """<input type="checkbox"/>""")
'aria - test(<.div(^.aria.label := "ow", "a"), """<div aria-label="ow">a</div>""")
'jsDict - test(<.div(^.style := js.Dictionary("a" -> "b")), """<div style="a:b;"></div>""")

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

Expand Down

0 comments on commit 3ca600e

Please sign in to comment.