Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scrollIntoView missing newer options #414

Open
nafg opened this issue Jun 19, 2020 · 5 comments
Open

scrollIntoView missing newer options #414

nafg opened this issue Jun 19, 2020 · 5 comments

Comments

@nafg
Copy link
Contributor

nafg commented Jun 19, 2020

def scrollIntoView(top: Boolean = js.native): Unit = js.native

From lib.dom.d.ts:

scrollIntoView(arg?: boolean | ScrollIntoViewOptions): void;
interface ScrollIntoViewOptions extends ScrollOptions {
    block?: ScrollLogicalPosition;
    inline?: ScrollLogicalPosition;
}
interface ScrollOptions {
    behavior?: ScrollBehavior;
}
type ScrollBehavior = "auto" | "smooth";
type ScrollLogicalPosition = "center" | "end" | "nearest" | "start";

In particular, it would be great not to have to write

div.asInstanceOf[js.Dynamic].scrollIntoView(js.Dynamic.literal(block = "nearest")).asInstanceOf[Unit]

More broadly how is this repo kept in sync with browser APIs? Can ScalablyTyped help somehow?

@sjrd
Copy link
Member

sjrd commented Jun 19, 2020

More broadly how is this repo kept in sync with browser APIs?

By PRs from users who notice that something's not up to date.

ScalablyTyped focuses on applications by design. It's not designed for libraries that everyone depends on, such as the DOM.

@oyvindberg
Copy link

I'll just mention in passing that the Typescript DOM definitions are 1) up to date for every TS release, 2) very detailed, 3) tagged by which standard (es5, esnext, etc) things were defined in. ST takes all this and massages it into Scala.js through a series of rewrites. If there is interest nothing in theory stops us from writing a custom conversion script which would "sync" all/some of it here.

In the mean time it's easy to copy/paste and adapt code as necessary @nafg :)

@armanbilge
Copy link
Member

@nafg would you mind making a PR? would be much appreciated!! :)

@armanbilge
Copy link
Member

  1. up to date for every TS release, 2) very detailed, 3) tagged by which standard (es5, esnext, etc) things were defined in

Sounds very appealing ... maybe one day :)

@armanbilge armanbilge added the good first issue We'd love a PR! label Oct 10, 2021
@nafg
Copy link
Contributor Author

nafg commented Jun 13, 2023

Sorry I never made a PR. For now here is the code I use in my project. Maybe it will be easy for a maintainer to adapt it into the codebase. Otherwise maybe I can do it in the next few days (but I may need a reminder).

object scrollIntoView {
  trait Options extends js.Object {
    val block   : js.UndefOr[String] = js.undefined
    val inline  : js.UndefOr[String] = js.undefined
    val behavior: js.UndefOr[String] = js.undefined
  }

  def blockNearest = new Options {
    override val block = "nearest"
  }

  def apply(elem: dom.Element)(options: Options): Unit =
    elem.asInstanceOf[js.Dynamic].scrollIntoView(options).asInstanceOf[Unit]
}

The obvious change that needs to be made is replacing the object apply method and its implementation with changing the signature of the existing method. I guess blockNearest is an arbitrary convenience object for my own use so it should be discarded. That leaves the Options trait.

I'm just going through utility code in my application codebase. I haven't looked up the DOM docs so it might be missing other things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants