w3c / csswg-drafts

CSS Working Group Editor Drafts
https://drafts.csswg.org/
Other
4.5k stars 667 forks source link

[cssom-view] extend scrollIntoViewOptions' *ScrollLogicalPosition* with `"farthest"` and `"none"` #8098

Open Schepp opened 1 year ago

Schepp commented 1 year ago

Relevant spec: https://w3c.github.io/csswg-drafts/cssom-view/#enumdef-scrolllogicalposition

While Element.scrollIntoView() got a lot more practical with the current ScrollLogicalPosition block and inline values, there is still some scenarios that would benefit from additional options that are "farthest" and "none".

In both cases, the scenario is that we've created a scroll slider whose items are at such a narrow size, that you would see e.g. three of them at once with the fourth being cut off at the border.

The slider has arrow key support as well as programmatic scroll buttons on both sides. We use IntersectionObserver to keep track of the visibility of each item in the slider, so that we can determine which item to scroll into view when the user strikes an arrow key or clicks one of the two directional scroll buttons:

CodePen example: https://codepen.io/Schepp/pen/KKeyaJx

Now to how "farthest" and "none" ScrollLogicalPosition can help us here:

argyleink commented 1 year ago

farthest is a great term for what i consider "paging" through the items: snap to the next not-in view item which reveals a new page/set of items 👍🏻

not only does the inner part of the slider scroll in the inline direction, the whole slider itself will also scroll into view in block direction, if cut off. This is a bit irritating.

totally agree and I've brought it up internally many times. in this carousel i ended up not using the scroll apis because of this side effect. setting block: none in the options would be great.