Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Popper): 修复位置计算逻辑,如 trigger 不可见立即隐藏 Popper #701

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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