Skip to content

Commit f2477f2

Browse files
committed
Add Reusable[TagMod] to TriStateCheckbox Props
1 parent cd3ecae commit f2477f2

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

coreGeneric/src/main/scala/japgolly/scalajs/react/Reusable.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package japgolly.scalajs.react
33
import japgolly.scalajs.react.internal.CoreGeneral._
44
import japgolly.scalajs.react.util.Effect.Sync
55
import japgolly.scalajs.react.util.{DefaultEffects => D}
6+
import japgolly.scalajs.react.vdom.TagMod
67
import scala.reflect.ClassTag
78

89
/**
@@ -150,6 +151,9 @@ object Reusable {
150151
def reusabilityInstance[A](r: Reusability[A]): Reusable[Reusability[A]] =
151152
byRef(r.test).map(new Reusability(_))
152153

154+
lazy val emptyVdom: Reusable[TagMod] =
155+
Reusable.byRef(TagMod.empty)
156+
153157
// ===================================================================================================================
154158

155159
/** Convenience methods that help you create `I => Reusable[O]` functions.

doc/changelog/2.0.0.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ Contents:
7878
* New extension method `showDom(): String` available on mounted components given
7979
`import japgolly.scalajs.react.test._` and/or `import japgolly.scalajs.react.test.ReactTestUtil._`
8080

81+
* Add `Reusable.emptyVdom` which has the type `Reusable[TagMod]`
82+
8183

8284
# Removals
8385

@@ -333,6 +335,7 @@ You can run the script in the Migration section at the bottom of the page to aut
333335
* `ModStateWithPropsFn`
334336
* `TimerSupport.install` had an infinite loop
335337
* `TriStateCheckbox`'s `onKeyDown` handler was calling `event.preventDefault()` on unhandled keys
338+
* `TriStateCheckbox` now accepts an optional `Reusable[TagMod]` in its `Props` that will be applied to the `<input>`
336339
337340
* Upgrade deps
338341
* Cats-effect to 3.2.1

extra/src/main/scala/japgolly/scalajs/react/extra/internal/TriStateCheckboxF.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,17 @@ class TriStateCheckboxF[F[_]](implicit F: Sync[F]) {
5656

5757
case class Props(state : State,
5858
setNextState: F[Unit],
59-
disabled : Boolean = false) {
59+
disabled : Boolean = false,
60+
tagMod : Reusable[TagMod] = Reusable.emptyVdom,
61+
) {
6062
@inline def render: VdomElement = Component(this)
6163
}
6264

6365
private def render($: ScalaComponent.MountedPure[Props, Unit, Unit], p: Props) = {
6466
val props = F.transSync($.props)(DefaultEffects.Sync)
6567
val setNext = F.flatMap(props)(p => if (p.disabled) F.empty else p.setNextState) // Only access .setNextState inside Sync for Reusability
6668
<.input.checkbox(
69+
p.tagMod,
6770
^.disabled := p.disabled,
6871
TagMod.unless(p.disabled)(eventHandlers(setNext)))
6972
}

tests/src/test/scala/japgolly/scalajs/react/extra/TriStateCheckboxTest.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ package japgolly.scalajs.react.extra
22

33
import japgolly.scalajs.react._
44
import japgolly.scalajs.react.extra.components.TriStateCheckbox
5-
import japgolly.scalajs.react.vdom.html_<^._
6-
import japgolly.scalajs.react.test.TestUtil._
75
import japgolly.scalajs.react.test.ReactTestUtils._
8-
import utest._
6+
import japgolly.scalajs.react.test.TestUtil._
97
import japgolly.scalajs.react.test._
8+
import japgolly.scalajs.react.vdom.html_<^._
9+
import utest._
1010

1111
object TriStateCheckboxTest extends TestSuite {
1212

0 commit comments

Comments
 (0)