[csswg-drafts] [css-position-3] Revisit the scroll position of sticky-positioned boxes (#7930)

flackr has just created a new issue for https://github.com/w3c/csswg-drafts:

== [css-position-3] Revisit the scroll position of sticky-positioned boxes ==
In #1459 I raised an issue around the behavior of scrolling sticky elements (or descendants) into view. In particular since [scrolling an element into view](https://drafts.csswg.org/cssom-view/#scroll-an-element-into-view) used the sticky element's current bounding border box returned from getBoundingClientRect, this could result in:
* Repeated attempts to scroll the element to the top. E.g. If sticky elements not anchored to `top: 0` are linked to in the anchor or the anchor itself is a part of the sticky element not at the top the anchor will (usually, unless resricted by their containing block) move after you scroll to their previous location.
* Anchor links and scroll into view not making anchor content visible. E.g. if the sticky containing block contains subsequent sticky elements those later elements typically cover up the earlier one. https://jsbin.com/simivof/edit?html,output is an example of this.

As a result, we [updated](https://github.com/w3c/csswg-drafts/commit/5a8ed5b0c57ab1749ff69ab9c9ec4d5595e68950) [the spec](https://drafts.csswg.org/css-position-3/#stickypos-scroll) to use the non-offsetted position for scroll operations.

Since this update, [chromium implements this behavior behind experimental web platform features](https://crbug.com/664246) which fixes this issue as well as issues with input fields combined with scroll-padding (e.g. [bug 1178622](https://crbug.com/1178622)) however the experimental behavior has also raised many bugs about the scrolling being unexpected (e.g. [bug 1334207](https://crbug.com/1334207)). I expect we will see many more bugs filed if we attempt to enable this behavior by default as input fields within sticky headers is a common practice for search fields.

The TLDR, we have two options:
* Scroll to the current position - This is the current behavior in Chrome (without flag), Firefox and Safari.
* Scroll to the non-offsetted position - Implemented in Chrome with experimental web platform features.

I propose that we revert the spec change and go back to the currently shipping behavior for two main reasons:
1. It is the current behavior implemented in all major browsers and `position: sticky` use is rapidly increasing ([at roughly 12.5% of Chrome page loads right now](https://chromestatus.com/metrics/feature/timeline/popularity/3354)). Changing this is likely to break the experience on a lot of those sites.
2. It is very hard for developers to work around issues caused by scrolling to the initial position, however there are (or could be) ways for developers to mitigate the issues with scrolling to the current position. In particular:
   - The anchor scrolling bug fixed by this issue could (at least in the identified use cases) be fixed by the developer changing the anchor to an element outside of the sticky positioned element.
   - The input scroll-padding issue could be fixed by improvements to the css-scroll-snap spec which would allow developers to exclude the sticky positioned element from the scroll-padding. For now, they could work around it by applying a negative `scroll-margin`.

Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/7930 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Thursday, 20 October 2022 19:43:35 UTC