feat: Overlay 当目标组件所在滚动容器处于弹窗所在容器时, 滚动容器滚动需要重新定位 (#2285)

This commit is contained in:
liaoxuezhi 2021-07-16 10:03:42 +08:00 committed by GitHub
parent 1a8061aa0c
commit acf1846349
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,12 +12,22 @@ import {
import {findDOMNode} from 'react-dom';
import React from 'react';
import {calculatePosition, getContainer, ownerDocument} from '../utils/dom';
import {autobind, noop} from '../utils/helper';
import {autobind, getScrollParent, noop} from '../utils/helper';
import {resizeSensor, getComputedStyle} from '../utils/resize-sensor';
// @ts-ignore
BasePosition.propTypes.placement = () => null;
function onScroll(elem: HTMLElement, callback: () => void) {
const handler = () => {
requestAnimationFrame(callback);
};
elem.addEventListener('scroll', handler);
return function () {
elem.removeEventListener('scroll', handler);
};
}
// @ts-ignore
class Position extends BasePosition {
props: any;
@ -57,6 +67,15 @@ class Position extends BasePosition {
: noop,
resizeSensor(overlay, () => this.updatePosition(target))
];
const scrollParent = getScrollParent(target);
if (scrollParent && container.contains(scrollParent)) {
this.resizeDispose.push(
onScroll(scrollParent, () => {
this.updatePosition(target);
})
);
}
}
this.setState(