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

ScrollBehavior definition is missing 'instant' for window.scrollTo #47441

Closed
RandScullard opened this issue Jan 14, 2022 · 12 comments
Closed

ScrollBehavior definition is missing 'instant' for window.scrollTo #47441

RandScullard opened this issue Jan 14, 2022 · 12 comments
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Help Wanted You can do this
Milestone

Comments

@RandScullard
Copy link

Bug Report

?? Search Terms

instant
ScrollBehavior
window
scrollTo
type definition

?? Version & Regression Information

v4.5.4, but it's also mentioned in #46654 (v4.4.4) and #28755 (v3.2.1)

? Playground Link

Playground link with relevant code

?? Code

window.scrollTo({
  top: 0,
  left: 0,
  behavior: 'instant' // This should be allowed
})

?? Actual behavior

The value of instant cannot be assigned to behavior when using window.scrollTo.

?? Expected behavior

The value of instant is allowed when using window.scrollTo according to https://developer.mozilla.org/en-US/docs/Web/API/Window/scrollTo as well as in real-world testing in major browsers. I just tested window.scrollTo with instant on Chrome, Firefox, and macOS Safari and it does not give the same behavior as auto. In my tests, auto produced smooth scrolling and instant scrolled instantly.

Please note that the MDN documentation specifies different behavior options for element.scrollTo and element.scrollIntoView vs. window.scrollTo. This bug report is specific to window.scrollTo. The existing ScrollBehavior type definition will most likely need to be bifurcated to handle all functions correctly.

Until the type definition is fixed, you can get the instant scrolling behavior by casting as any:

window.scrollTo({ top: 0, left: 0, behavior: 'instant' } as any)
@RandScullard
Copy link
Author

Please note that this issue is very similar to #46654, but that issue was related to element.scrollTo and this issue is related to window.scrollTo. The two functions have different options for ScrollBehavior. (And thanks to @patik - his work on #46654 saved me time in creating this issue!)

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Help Wanted You can do this labels Jan 14, 2022
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Jan 14, 2022
@BayanBennett
Copy link

Note that behavior: "auto" inherits the behavior from the CSS scroll-behavior, which is why having the "instant" value is important

@BayanBennett
Copy link

BayanBennett commented Apr 27, 2022

@BayanBennett
Copy link

BayanBennett commented Apr 27, 2022

More context: It seems like the "instant" value isn't part of the CSSOM spec https://github.com/w3c/csswg-drafts/blob/main/cssom-view-1/Overview.bs#L407

EDIT: instant is back due to w3c/csswg-drafts#8107, thanks to #47441 (comment) for pointing this out.

@zhangenming
Copy link

8b07e5831d8c3695a2fddbac139c908

auto and instant behave differently in my browser

@YahangWu
Copy link

YahangWu commented Mar 29, 2023

This has been restored in cssom w3c/csswg-drafts#8107, please added it back. Thanks :))

@curtisburns
Copy link

Just encountered this issue. Would be great to have this as MDN docs seem to suggest it is an option, and I only get the behaviour I need with instant and not auto which seems to fall back on the CSS style rule if set (I have it set to smooth). Have used 'instant' as ScrollBehavior in the meantime. Cheers.

@Teamop
Copy link

Teamop commented Apr 19, 2023

it's already fixed in #53133 which was just include in v5.1-beta

@cbroomemktw
Copy link

@Teamop thanks! For anyone who can't update while still in beta you can brute force this setting as a workaround:

      const scrollToOptions = { top: 0, left: 0, behavior: 'instant' };
      window.scrollTo(scrollToOptions as unknown as ScrollToOptions);

@DanielRuf
Copy link

Note that behavior: "auto" inherits the behavior from the CSS scroll-behavior, which is why having the "instant" value is important

Exactly.

@jakebailey
Copy link
Member

As noted in #47441 (comment), this is already fixed and now released in TS 5.1.

@helloint
Copy link

As noted in #47441 (comment), this is already fixed and now released in TS 5.1.

Can this small issue being published to latest 4.x? Upgrading to 5.x is a big change to the project and the entire eco

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests