-
Notifications
You must be signed in to change notification settings - Fork 1.3k
chore: Revert "Revert "fix: scrollIntoView should respect scroll-margin (#8715)"" #9146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| let {left: newLeft, top: newTop} = targetElement.getBoundingClientRect(); | ||
| // Account for sub pixel differences from rounding | ||
| if ((Math.abs(originalLeft - newLeft) > 1) || (Math.abs(originalTop - newTop) > 1)) { | ||
| scrollParents = containingElement ? getScrollParents(containingElement, true) : []; | ||
| for (let scrollParent of scrollParents) { | ||
| scrollIntoView(scrollParent as HTMLElement, containingElement as HTMLElement, {block: 'center', inline: 'center'}); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we added the bypass for chrome, this now also supports alternative alignments, to center the containingElement. This was missing in the previous PR also 👍
| if (!isScrollPrevented) { | ||
| scrollParents.push(root); | ||
| } | ||
| let scrollParents = getScrollParents(targetElement, true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noting that this does not behave like the native equivalent, since it skips overflow:hidden scroll parents. This potential issue also existed before this PR, so I don't think it's a blocker.
| if (shouldScrollBlock && block === 'start') { | ||
| y += scrollAreaLeft - scrollPortLeft; | ||
| } else if (shouldScrollBlock && block === 'center') { | ||
| y += (scrollAreaTop + scrollAreaBottom) / 2 - (scrollPortTop + scrollPortBottom) / 2; | ||
| } else if (shouldScrollBlock && block === 'end') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Native scrollIntoView only checks for shouldScroll with the nearest alignment option. Should we also do that?
This PR refactors
scrollIntoViewandscrollIntoViewportto supportscrollMargin, while working around the regressions mentioned in #8689 (comment). Additionally, a newinline&blockoption for alignment of a container element has been added.By leveraging bounding rectangles, the internal calculations are now streamlined with
DOMLayoutDelegateand significantly simplified.✅ Pull Request Checklist:
📝 Test Instructions:
🧢 Your Project: