Skip to content

Instantly share code, notes, and snippets.

Created June 15, 2016 09:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/1f412b2c851e90836f81d292a416dc78 to your computer and use it in GitHub Desktop.
Save anonymous/1f412b2c851e90836f81d292a416dc78 to your computer and use it in GitHub Desktop.
Scala.jsFiddle gist
import org.scalajs.dom
import dom.html
import scalajs.js.annotation.JSExport
object ScalaJSExample extends js.JSApp{
val listings = Seq(
"Apple", "Apricot", "Banana", "Cherry",
"Mango", "Mangosteen", "Mandarin",
"Grape", "Grapefruit", "Guava"
)
val box = input(
`type`:="text",
placeholder:="Type here!"
).render
val output = div(renderListings).render
box.onkeyup = (e: dom.Event) => {
output.innerHTML = ""
output.appendChild(renderListings)
}
def renderListings = ul(
for {
fruit <- listings
if fruit.toLowerCase.startsWith(
box.value.toLowerCase
)
} yield {
val (first, last) = fruit.splitAt(
box.value.length
)
li(
span(
backgroundColor:="yellow",
first
),
last
)
}
).render
def main() = {
val document = js.Dynamic.global.document
val d= div(
h1("Search Box!"),
p(
"Type here to filter " +
"the list of things below!"
),
div(box),
output
).render
println(d)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment