From acf18463497963310ce42f06769e470df03448f9 Mon Sep 17 00:00:00 2001 From: liaoxuezhi Date: Fri, 16 Jul 2021 10:03:42 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20Overlay=20=E5=BD=93=E7=9B=AE=E6=A0=87?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E6=89=80=E5=9C=A8=E6=BB=9A=E5=8A=A8=E5=AE=B9?= =?UTF-8?q?=E5=99=A8=E5=A4=84=E4=BA=8E=E5=BC=B9=E7=AA=97=E6=89=80=E5=9C=A8?= =?UTF-8?q?=E5=AE=B9=E5=99=A8=E6=97=B6,=20=E6=BB=9A=E5=8A=A8=E5=AE=B9?= =?UTF-8?q?=E5=99=A8=E6=BB=9A=E5=8A=A8=E9=9C=80=E8=A6=81=E9=87=8D=E6=96=B0?= =?UTF-8?q?=E5=AE=9A=E4=BD=8D=20(#2285)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Overlay.tsx | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/components/Overlay.tsx b/src/components/Overlay.tsx index ca53e2b78..f174079d7 100644 --- a/src/components/Overlay.tsx +++ b/src/components/Overlay.tsx @@ -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(