Skip to content

Commit 73561a3

Browse files
committed
Added Sel.findFirstIn
1 parent bd02333 commit 73561a3

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

HISTORY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Changed overloaded `classSet` methods into `classSet{,1}{,M}`.
55
* Added `simulateKeyDownUp` and `simulateKeyDownPressUp` to `KeyboardEventData` in the test module.
66
* In rare circumstances, `Simulation.run` targets can go out of date. Targets are now stored by-name.
7+
* Added `Sel.findFirstIn`.
78

89
# 0.6.0 ([commit log](https://github.com/japgolly/scalajs-react/compare/v0.5.4...v0.6.0))
910

test/src/main/scala/japgolly/scalajs/react/test/Sel.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ sealed abstract class Sel {
3232
case => Array()
3333
}
3434

35+
final def findFirstIn(i: ComponentM): ComponentM = {
36+
val a = findAllIn(i)
37+
if (a.isEmpty)
38+
sys.error(s"DOM not found for [$this]")
39+
else
40+
a.head
41+
}
42+
3543
final def findInE(i: ComponentM): Either[String, ComponentM] = {
3644
val a = findAllIn(i)
3745
a.length match {
@@ -78,7 +86,6 @@ object Sel {
7886
def apply(css: String): Sel = {
7987
def lvl(s: String): Sel =
8088
(id /: s.split("(?=\\.)").filter(_.nonEmpty))((q,a) => q & elem(a))
81-
// .filter here ↗ due to https://github.com/scala-js/scala-js/issues/1171
8289
def elem(s: String): Sel =
8390
if (s.isEmpty)
8491
else if (s == "*") id

0 commit comments

Comments
 (0)