Overlay 定位, 需要同时监控目标组件很本身的大小变化

This commit is contained in:
2betop 2020-08-13 17:28:36 +08:00
parent c8ab0553eb
commit 2836b90758

View File

@ -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());
}
}