Skip to content

Commit

Permalink
fix(components/popover): 修复原位置和反面位置都不行时会发生位置抖动的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
mengxinssfd committed Aug 2, 2023
1 parent e6f9cf1 commit 3b899a7
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions packages/components/src/popover/popover.utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { getElRealSize } from '@pkg/shared';
import type { Placement, Placement_12 } from './popover.types';
import { calcDistanceWithParent } from '@tool-pack/dom';

Expand Down Expand Up @@ -62,8 +61,18 @@ export function calcPlacement(
};

const split = placement.split('-') as [Placement, string];
const p: Placement = map[split[0]]();
if (p !== split[0]) split[0] = p;
let p = map[split[0]]();
if (p !== split[0]) {
// 如果原位置不行,那就反向再算一遍;这样反面也不行的话,就会回到原位置,而如果反面行那就是反面
p = map[p]();

// // 返回原位置则代表两面都不满足条件
// if (p === split[0]) {
// // todo: 如果两面都不行,选择较宽的那面
// }

split[0] = p;
}

return split.join('-') as Placement_12;
}
Expand All @@ -73,8 +82,7 @@ interface Size {
height: number;
}
function getSize(el: HTMLElement): Size {
const style = getElRealSize(el);
return { width: style[0], height: style[1] };
return { width: el.offsetWidth, height: el.offsetHeight };
}

export function calcPosition(
Expand Down

0 comments on commit 3b899a7

Please sign in to comment.