Skip to content

scrollIntoView should account for scroll-margin of element #8689

@nwidynski

Description

@nwidynski

Provide a general summary of the issue here

Found while working on the carousel/rotator RFC - Our scrollIntoView shim correctly scrolls the visible layout rect into view, but does not consider scroll margins. This is not in parity with the native behavior of element.scrollIntoView().

🤔 Expected Behavior?

Element should be scrolled to its visible layout rect offset by its scroll margin.

😯 Current Behavior

Element is only visibly scrolled into view, even though scroll margin explicitly marks a wish to scroll to an offset.

💁 Possible Solution

getComputedStyle for the element as well when scrolling in to view. Then offset the rect to account for margin in px.

🔦 Context

No response

🖥️ Steps to Reproduce

  1. Visit the example in https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView
  2. Scroll the "Go to bottom" button (scroll-margin of 60px) out of view
  3. Run this script in the console:
document.getElementById('go-to-bottom').scrollIntoView({block: 'nearest', container: 'nearest'})

Version

latest

What browsers are you seeing the problem on?

Chrome

If other, please specify.

No response

What operating system are you using?

OSX

🧢 Your Company/Team

No response

🕷 Tracking Issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions