Skip to content

Commit

Permalink
fix(Popper): 触发位置计算时,如 trigger 不可见立即隐藏 Popper
Browse files Browse the repository at this point in the history
  • Loading branch information
1zumii committed Mar 26, 2024
1 parent d9bac79 commit 8f00246
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions components/popper/usePopper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
} from 'vue';
import { computePosition, offset, shift, flip, arrow } from '@floating-ui/dom';
import { isBoolean, isFunction } from 'lodash-es';
import { useIntersectionObserver } from '@vueuse/core';
import { useNormalModel } from '../_util/use/useModel';
import popupManager from '../_util/popupManager';
import getElementFromVueInstance from '../_util/getElementFromVueInstance';
Expand Down Expand Up @@ -43,13 +42,6 @@ export default (props: PopperProps, emit: any) => {
}`;
});

// 若触发元素已经被移除或隐藏,则关闭提示信息,否则会导致动画执行异常
useIntersectionObserver(triggerRef, ([{ isIntersecting }]) => {
if (!isIntersecting) {
updateVisible(false);
}
});

const computePopper = () => {
if (isBoolean(props.disabled) && props.disabled) return;
if (isFunction(props.disabled) && props.disabled()) return;
Expand All @@ -73,6 +65,14 @@ export default (props: PopperProps, emit: any) => {
),
}
: getElementFromVueInstance(triggerRef.value);

const triggerRect = triggerEl.getBoundingClientRect();
// trigger 不可见的时候立即隐藏,允许误差
if (triggerRect.width <= 1 && triggerRect.height <= 1) {
updateVisible(false);
return;
}

const popperEl = popperRef.value;
computePosition(triggerEl, popperEl, {
placement: props.placement,
Expand Down

0 comments on commit 8f00246

Please sign in to comment.