TypeScript-DOM-lib-generator icon indicating copy to clipboard operation
TypeScript-DOM-lib-generator copied to clipboard

window.scrollTo behavior option missing "instant" string literal union

Open aquaductape opened this issue 3 years ago • 8 comments

Bug Report

window.scrollTo behavior option has three types: "smooth", "instant" and "auto", but typescript doesn't have "instant" value.

🕗 Version

v4.4.4

⏯ Playground Link

https://www.typescriptlang.org/play?#code/O4SwdgJg9sB0DOBjATlANmgKlAFAbwCMBTACwEMA3EKZALgAIByceAFzLFcYF8BKIA

💻 Code

window.scrollTo({behavior: 'instant'})

aquaductape avatar Oct 27 '21 04:10 aquaductape

Hey, I just ran into this issue as well. It looks like according to the CSSOM spec there is no 'instant' setting for option.

You can see in the CSS Overflow Module Level 3 that scroll-behavior only accepts the vales 'auto' | 'instant'. Furthermore, the CSSOM specifies that if behavior is auto and the element in question being scrolled to has the smooth computed for it (i.e. the scroll-behavior property of the element is set to 'smooth') that smooth scrolling will be used. The only case where instant scrolling should be used (per the spec) is if the element doesn't have scroll-behavior set to smooth and auto is the behavior for scrollTo. In other words, instant scrolling behavior cannot be forced by the scrollTo method per the spec.

However, I've checked and both Firefox and Chrome deviate from the spec and allow the use of 'instant' for scrollTo. I'm not sure what should be done here from TypeScript's perspective as the reality of the web and the letter of its law differ. Ideally, the spec would be revised to allow for explicitly instant scrolling

nickgirardo avatar Nov 23 '21 21:11 nickgirardo

It seems this is intended. The instant has been renamed into auto. So you need to change instant into auto. Ref: https://github.com/microsoft/TypeScript-DOM-lib-generator/commit/fe01c9a6d6afde86bd15f2588dc9360416a2beb4#r31507840

y-yagi avatar Dec 12 '21 05:12 y-yagi

For my case I have to use instant option not auto because the <html> tag is set to smooth scroll, by using inline style

aquaductape avatar Dec 12 '21 05:12 aquaductape

I'm running into basically the same issue as @aquaductape: behavior: 'auto' respects the element's CSS scroll-behavior: smooth declaration.

What works (in browsers) is behavior: 'instant', prefixed with a // @ts-expect-error [mildly irritated message] 😉

maranomynet avatar Aug 16 '22 09:08 maranomynet

~~according to https://drafts.csswg.org/cssom-view/#extensions-to-the-window-interface,~~ ~~'instant' has been removed, browser should not support this feature.~~

~~i opened an issue: https://bugs.chromium.org/p/chromium/issues/detail?id=1358809~~

wyattzheng avatar Sep 01 '22 07:09 wyattzheng

The proposed merging of "instant" with "auto" along with the described resolution algoritm of the "auto" behavior value, remove a perfectly valid use case/feature, without as much as a hint of justification or even mentioning it.

After the change window.scrollTo (and related methods) can only affect scroll behavior in the direction of making it smoother, but not make it more instant. Something that was previously possible, and intentionally done (as demonstrated by this issue, and other similar examples available with quick Googling).

This spec change looks like a mistake, IMO — a resonable hypothesis as the linked document is in an "editor's draft" state:

An editor's draft is a document allowing the Group to iterate internally on its content for consideration. Editor's Drafts are works in progress inside a W3C Group and are not required to have the consensus of the Group participants. These drafts have not received formal review and are not endorsed W3C.

These drafts MUST NOT be cited as W3C standards and may or may not become W3C standards.

https://www.w3.org/standards/types#ED (Emphasis mine)

Thus, I argue that this change in TypeScript's lib is premature, and someone should raise an issue with W3C's CSSWG regarding this, instead of pressuring browser makers to act on it in haste.

maranomynet avatar Sep 01 '22 09:09 maranomynet

@maranomynet yes, that makes sense!

wyattzheng avatar Sep 01 '22 09:09 wyattzheng

Thanks people! Filed https://github.com/w3c/csswg-drafts/issues/7773.

saschanaz avatar Sep 22 '22 01:09 saschanaz

should closed by https://github.com/microsoft/TypeScript-DOM-lib-generator/pull/1481

Teamop avatar Apr 19 '23 10:04 Teamop

Right, thanks.

@github-actions close

saschanaz avatar Apr 19 '23 11:04 saschanaz

Closing because @saschanaz is one of the code-owners of this repository.

github-actions[bot] avatar Apr 19 '23 11:04 github-actions[bot]

When I run npm run build, it says that "instant" isn't a valid value for type ScrollBehavior.

My code is

document.documentElement.scrollTo({ top: 0, left: 0, scroll-behavior: 'instant' })

and

window.scrollTo({ top: ref.offsetTop, left: 0, scroll-behavior: 'instant' })

pranav2844 avatar Jul 14 '23 02:07 pranav2844