static 的 target 不监控大小变化

This commit is contained in:
2betop 2020-06-11 19:58:02 +08:00
parent 9983812fea
commit 72db95752b
2 changed files with 6 additions and 3 deletions

View File

@ -13,7 +13,7 @@ import {findDOMNode} from 'react-dom';
import React from 'react'; import React from 'react';
import {calculatePosition, getContainer, ownerDocument} from '../utils/dom'; import {calculatePosition, getContainer, ownerDocument} from '../utils/dom';
import {autobind} from '../utils/helper'; import {autobind} from '../utils/helper';
import {resizeSensor} from '../utils/resize-sensor'; import {resizeSensor, getComputedStyle} from '../utils/resize-sensor';
// @ts-ignore // @ts-ignore
BasePosition.propTypes.placement = () => null; BasePosition.propTypes.placement = () => null;
@ -38,7 +38,10 @@ class Position extends BasePosition {
}); });
} }
if (!this.watchedTarget || this.watchedTarget !== target) { if (
(!this.watchedTarget || this.watchedTarget !== target) &&
getComputedStyle(target, 'position') !== 'static'
) {
this.resizeDispose?.(); this.resizeDispose?.();
this.watchedTarget = target; this.watchedTarget = target;
this.resizeDispose = resizeSensor(target, () => this.resizeDispose = resizeSensor(target, () =>

View File

@ -17,7 +17,7 @@ class EventQueue {
} }
} }
function getComputedStyle(element: HTMLElement, prop: string) { export function getComputedStyle(element: HTMLElement, prop: string) {
if ((element as any).currentStyle) { if ((element as any).currentStyle) {
return (element as any).currentStyle[prop]; return (element as any).currentStyle[prop];
} else if (window.getComputedStyle) { } else if (window.getComputedStyle) {