Skip to content

[cssom-view-1] Option for scrollIntoView that doesn't propagate to ancestors #9452

Closed
@flackr

Description

@flackr

The scrollIntoView API invokes the behavior to scroll an element into view which:

means to run these steps for each ancestor element or viewport that establishes a scrolling box scrolling box, in order of innermost to outermost scrolling box

However, in many circumstances it can be counter-intuitive that a scroll into view call scrolls ancestor scrollers. E.g. If a slideshow or carousel uses a scrolling box for slides and uses scrollIntoView to advance to the next slide, this will also force the top level scroller to scroll the slideshow into view. This is often surprising, especially when scrollIntoView is used as a convenience to automatically calculate the scroll position rather than using scrollTo on the scroller. @argyleink has examples where this has been problematic.

As such, I propose we add the ability to scroll an element into view that only scrolls the nearest scrolling box. There are two ways to do this:

  1. Add an option to ScrollIntoViewOptions, e.g. scroll = "nearest" | "ancestors" with a default of ancestors or specify a boundary scroller (happy to bikeshed names), or
  2. Add the necessary options to ScrollToOptions to scroll a particular element into view. E.g. we could provide a target and alignment options (similar to ScrollIntoViewOptions). It would be hard to define reasonable interactions when for example a target is specified and a left value is specified. Further, it would be odd when there is an intermediate scroller that does not have the element visible, do we scroll to where the element is outside of the intermediate scroller's scrollport or do we scroll to the intermediate scroller?

I think option 1 is simpler and a reasonable api.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions