Skip to content

Commit

Permalink
Added features for scrollIntoView with options
Browse files Browse the repository at this point in the history
  • Loading branch information
darkfrog26 committed Oct 21, 2019
1 parent ce0e1a2 commit d12b740
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
8 changes: 8 additions & 0 deletions dom/src/main/scala/io/youi/ElementFeatures.scala
@@ -0,0 +1,8 @@
package io.youi

import scala.scalajs.js

@js.native
trait ElementFeatures extends js.Object {
def scrollIntoView(options: ScrollIntoViewOptions): Unit
}
9 changes: 9 additions & 0 deletions dom/src/main/scala/io/youi/ScrollIntoViewOptions.scala
@@ -0,0 +1,9 @@
package io.youi

import scala.scalajs.js

trait ScrollIntoViewOptions extends js.Object {
var behavior: js.UndefOr[String] = js.undefined
var block: js.UndefOr[String] = js.undefined
var inline: js.UndefOr[String] = js.undefined
}
4 changes: 4 additions & 0 deletions dom/src/main/scala/io/youi/dom.scala
Expand Up @@ -9,6 +9,7 @@ import org.scalajs.dom.raw.HTMLElement
import scala.collection.mutable
import scala.concurrent.{Future, Promise}
import scala.language.implicitConversions
import scala.scalajs.js

object dom extends ExtendedElement(None) {
def bySelector[T <: Element](selectors: String, root: Option[Element] = None): Vector[T] = {
Expand Down Expand Up @@ -85,6 +86,9 @@ object dom extends ExtendedElement(None) {
}
}

// Existing HTML features that Scala.js doesn't already provide
implicit def element2Features(element: html.Element): ElementFeatures = element.asInstanceOf[ElementFeatures]

implicit class ElementExtras[E <: Element](e: E) extends ExtendedElement(Some(e)) {
def parentByTag[T <: HTMLElement](tagName: String): Option[T] = findParentRecursive[T](e.asInstanceOf[HTMLElement], (p: HTMLElement) => {
p.tagName == tagName
Expand Down

0 comments on commit d12b740

Please sign in to comment.