From 2836b90758beed1c49697b73558c2bea452e1f80 Mon Sep 17 00:00:00 2001 From: 2betop <2betop.cn@gmail.com> Date: Thu, 13 Aug 2020 17:28:36 +0800 Subject: [PATCH] =?UTF-8?q?Overlay=20=E5=AE=9A=E4=BD=8D,=20=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E5=90=8C=E6=97=B6=E7=9B=91=E6=8E=A7=E7=9B=AE=E6=A0=87?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E5=BE=88=E6=9C=AC=E8=BA=AB=E7=9A=84=E5=A4=A7?= =?UTF-8?q?=E5=B0=8F=E5=8F=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Overlay.tsx | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/components/Overlay.tsx b/src/components/Overlay.tsx index 940a68401..381753a37 100644 --- a/src/components/Overlay.tsx +++ b/src/components/Overlay.tsx @@ -22,7 +22,7 @@ BasePosition.propTypes.placement = () => null; class Position extends BasePosition { props: any; _lastTarget: any; - resizeDispose: () => void; + resizeDispose: Array<() => void>; watchedTarget: any; setState: (state: any) => void; @@ -38,23 +38,24 @@ class Position extends BasePosition { }); } - if ( - (!this.watchedTarget || this.watchedTarget !== target) && - getComputedStyle(target, 'position') !== 'static' - ) { - this.resizeDispose?.(); - this.watchedTarget = target; - this.resizeDispose = resizeSensor(target, () => - this.updatePosition(target) - ); - } - - const overlay = findDOMNode(this as any); + const overlay = findDOMNode(this as any) as HTMLElement; const container = getContainer( this.props.container, ownerDocument(this).body ); + if ( + (!this.watchedTarget || this.watchedTarget !== target) && + getComputedStyle(target, 'position') !== 'static' + ) { + this.resizeDispose?.forEach(fn => fn()); + this.watchedTarget = target; + this.resizeDispose = [ + resizeSensor(target, () => this.updatePosition(target)), + resizeSensor(overlay, () => this.updatePosition(target)) + ]; + } + this.setState( calculatePosition( this.props.placement, @@ -67,7 +68,7 @@ class Position extends BasePosition { } componentWillUnmount() { - this.resizeDispose?.(); + this.resizeDispose?.forEach(fn => fn()); } }