Skip to content

scrollIntoView missing newer options #414

@nafg

Description

@nafg
Contributor

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?

Activity

sjrd

sjrd commented on Jun 19, 2020

@sjrd
Member

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

oyvindberg commented on Jun 19, 2020

@oyvindberg

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

armanbilge commented on Aug 11, 2021

@armanbilge
Member

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

armanbilge

armanbilge commented on Aug 11, 2021

@armanbilge
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 :)

nafg

nafg commented on Jun 13, 2023

@nafg
ContributorAuthor

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @nafg@oyvindberg@sjrd@armanbilge

        Issue actions

          scrollIntoView missing newer options · Issue #414 · scala-js/scala-js-dom