rebuild hrm
This commit is contained in:
12
node_modules/@react-aria/utils/src/scrollIntoView.ts
generated
vendored
12
node_modules/@react-aria/utils/src/scrollIntoView.ts
generated
vendored
@@ -11,6 +11,7 @@
|
||||
*/
|
||||
|
||||
import {getScrollParents} from './getScrollParents';
|
||||
import {nodeContains} from './shadowdom/DOMFunctions';
|
||||
|
||||
interface ScrollIntoViewportOpts {
|
||||
/** The optional containing element of the target to be centered in the viewport. */
|
||||
@@ -22,7 +23,7 @@ interface ScrollIntoViewportOpts {
|
||||
* Similar to `element.scrollIntoView({block: 'nearest'})` (not supported in Edge),
|
||||
* but doesn't affect parents above `scrollView`.
|
||||
*/
|
||||
export function scrollIntoView(scrollView: HTMLElement, element: HTMLElement) {
|
||||
export function scrollIntoView(scrollView: HTMLElement, element: HTMLElement): void {
|
||||
let offsetX = relativeOffset(scrollView, element, 'left');
|
||||
let offsetY = relativeOffset(scrollView, element, 'top');
|
||||
let width = element.offsetWidth;
|
||||
@@ -80,7 +81,7 @@ function relativeOffset(ancestor: HTMLElement, child: HTMLElement, axis: 'left'|
|
||||
if (child.offsetParent === ancestor) {
|
||||
// Stop once we have found the ancestor we are interested in.
|
||||
break;
|
||||
} else if (child.offsetParent.contains(ancestor)) {
|
||||
} else if (nodeContains(child.offsetParent, ancestor)) {
|
||||
// If the ancestor is not `position:relative`, then we stop at
|
||||
// _its_ offset parent, and we subtract off _its_ offset, so that
|
||||
// we end up with the proper offset from child to ancestor.
|
||||
@@ -97,8 +98,8 @@ function relativeOffset(ancestor: HTMLElement, child: HTMLElement, axis: 'left'|
|
||||
* that will be centered in the viewport prior to scrolling the targetElement into view. If scrolling is prevented on
|
||||
* the body (e.g. targetElement is in a popover), this will only scroll the scroll parents of the targetElement up to but not including the body itself.
|
||||
*/
|
||||
export function scrollIntoViewport(targetElement: Element | null, opts?: ScrollIntoViewportOpts) {
|
||||
if (targetElement && document.contains(targetElement)) {
|
||||
export function scrollIntoViewport(targetElement: Element | null, opts?: ScrollIntoViewportOpts): void {
|
||||
if (targetElement && nodeContains(document, targetElement)) {
|
||||
let root = document.scrollingElement || document.documentElement;
|
||||
let isScrollPrevented = window.getComputedStyle(root).overflow === 'hidden';
|
||||
// If scrolling is not currently prevented then we aren’t in a overlay nor is a overlay open, just use element.scrollIntoView to bring the element into view
|
||||
@@ -117,6 +118,9 @@ export function scrollIntoViewport(targetElement: Element | null, opts?: ScrollI
|
||||
} else {
|
||||
let scrollParents = getScrollParents(targetElement);
|
||||
// If scrolling is prevented, we don't want to scroll the body since it might move the overlay partially offscreen and the user can't scroll it back into view.
|
||||
if (!isScrollPrevented) {
|
||||
scrollParents.push(root);
|
||||
}
|
||||
for (let scrollParent of scrollParents) {
|
||||
scrollIntoView(scrollParent as HTMLElement, targetElement as HTMLElement);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user