Skip to content

Commit b9fa89c

Browse files
committed
Fix VDOM attributes not accepting all numeric types
1 parent 00c167a commit b9fa89c

File tree

4 files changed

+47
-13
lines changed

4 files changed

+47
-13
lines changed

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@ trait ImplicitsForVdomAttr extends ImplicitsForVdomAttr1 {
2828
import Attr.ValueType
2929
import ValueType._
3030

31-
implicit val vdomAttrVtBoolean: Simple[Boolean] = byImplicit
32-
33-
implicit val vdomAttrVtString: Simple[String] = string
34-
35-
implicit val vdomAttrVtInt: Simple[Int] = byImplicit
36-
37-
implicit val vdomAttrVtJsObject: Simple[js.Object] = direct
31+
implicit val vdomAttrVtBoolean : Simple[Boolean ] = byImplicit
32+
implicit val vdomAttrVtString : Simple[String ] = string
33+
implicit val vdomAttrVtInt : Simple[Int ] = byImplicit
34+
implicit lazy val vdomAttrVtLong : Simple[Long ] = byImplicit
35+
implicit lazy val vdomAttrVtFloat : Simple[Float ] = byImplicit
36+
implicit lazy val vdomAttrVtDouble : Simple[Double ] = byImplicit
37+
implicit lazy val vdomAttrVtShort : Simple[Short ] = byImplicit
38+
implicit lazy val vdomAttrVtByte : Simple[Byte ] = byImplicit
39+
implicit val vdomAttrVtJsObject: Simple[js.Object] = direct
3840

3941
@inline implicit def vdomAttrVtJsDictionary[A]: ValueType[js.Dictionary[A], js.Object] = byImplicit
4042

doc/changelog/1.1.0.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
* Fix React warnings with SVG VDOM.
77

8+
* Fix VDOM attributes not accepting types: `Byte`, `Short`, `Float`, `Double`, `Long`
9+
810
* Refactored `vdom.Builder` which is an internal mechanism for efficiently composing VDOM.
911
There is now:
1012
* An interface - advanced users can create their own if they like

test/src/test/scala/japgolly/scalajs/react/core/vdom/PrefixedTest.scala

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,24 @@ object PrefixedTest extends TestSuite {
5353
'styleDict - test(<.div(^.style := js.Dictionary("x" -> "y")), """<div style="x:y;"></div>""")
5454
'styleAttrs - test(<.div(^.color := "red", ^.cursor.auto), """<div style="color:red;cursor:auto;"></div>""")
5555

56-
'boolean {
57-
't - test(<.div(^.disabled := true), """<div disabled=""></div>""")
58-
'f - test(<.div(^.disabled := false), """<div></div>""")
56+
'attr {
57+
'any {
58+
def aa: VdomAttr[Any] = ^.profile
59+
def as = "profile"
60+
'short - test(<.div(aa := (45: Short)), s"""<div $as="45"></div>""")
61+
'byte - test(<.div(aa := (50: Byte)), s"""<div $as="50"></div>""")
62+
'int - test(<.div(aa := 666), s"""<div $as="666"></div>""")
63+
'long - test(<.div(aa := 123L), s"""<div $as="123"></div>""")
64+
'float - test(<.div(aa := 321f), s"""<div $as="321"></div>""")
65+
'double - test(<.div(aa := 12.3), s"""<div $as="12.3"></div>""")
66+
'string - test(<.div(aa := "yo"), s"""<div $as="yo"></div>""")
67+
'booleanT - test(<.div(aa := true), s"""<div $as="true"></div>""")
68+
'booleanF - test(<.div(aa := false), s"""<div $as="false"></div>""")
69+
}
70+
'boolean {
71+
't - test(<.div(^.disabled := true), """<div disabled=""></div>""")
72+
'f - test(<.div(^.disabled := false), """<div></div>""")
73+
}
5974
}
6075

6176
'VdomArray {

test/src/test/scala/japgolly/scalajs/react/core/vdom/UnprefixedTest.scala

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,24 @@ object UnprefixedTest extends TestSuite {
5555
'styleDict - test(div(style := js.Dictionary("x" -> "y")), """<div style="x:y;"></div>""")
5656
'styleAttrs - test(div(color := "red", cursor.auto), """<div style="color:red;cursor:auto;"></div>""")
5757

58-
'boolean {
59-
't - test(div(disabled := true), """<div disabled=""></div>""")
60-
'f - test(div(disabled := false), """<div></div>""")
58+
'attr {
59+
'any {
60+
def aa: VdomAttr[Any] = profile
61+
def as = "profile"
62+
'short - test(div(aa := (45: Short)), s"""<div $as="45"></div>""")
63+
'byte - test(div(aa := (50: Byte)), s"""<div $as="50"></div>""")
64+
'int - test(div(aa := 666), s"""<div $as="666"></div>""")
65+
'long - test(div(aa := 123L), s"""<div $as="123"></div>""")
66+
'float - test(div(aa := 321f), s"""<div $as="321"></div>""")
67+
'double - test(div(aa := 12.3), s"""<div $as="12.3"></div>""")
68+
'string - test(div(aa := "yo"), s"""<div $as="yo"></div>""")
69+
'booleanT - test(div(aa := true), s"""<div $as="true"></div>""")
70+
'booleanF - test(div(aa := false), s"""<div $as="false"></div>""")
71+
}
72+
'boolean {
73+
't - test(div(disabled := true), """<div disabled=""></div>""")
74+
'f - test(div(disabled := false), """<div></div>""")
75+
}
6176
}
6277

6378
'VdomArray {

0 commit comments

Comments
 (0)