Skip to content

Commit

Permalink
fix(Popover): fix popover position for window browser (#1712)
Browse files Browse the repository at this point in the history
This reverts commit b2425f6.

Co-authored-by: Zhang Rui <zhangrui@growingio.com>
  • Loading branch information
Ryan Zhang and Zhang Rui committed Dec 21, 2021
1 parent 41fa074 commit d20aa1d
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/popover/usePop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,16 @@ const clear3D = (transform: string): string | number[] => {
if (!transform) {
return transform;
}
if (transform.indexOf('translate3d') === -1) {
return transform;

if (transform.indexOf('translate3d') !== -1) {
const text = clear(transform)(['translate3d(', 'px', ')']);
return text.split(',').map((value) => Number(value));
}
if (transform.indexOf('translate') !== -1) {
const text = clear(transform)(['translate(', 'px', ')']);
return text.split(',').map((value) => Number(value));
}
const text = clear(transform)(['translate3d(', 'px', ')']);
return text.split(',').map((value) => Number(value));
return transform;
};

const usePop = ({ referenceElement, popperElement, placement, modifiers, strategy }: UsePopProps) => {
Expand All @@ -46,10 +51,10 @@ const usePop = ({ referenceElement, popperElement, placement, modifiers, strateg
if (styles?.popper?.bottom === 'auto') {
let yField = y < 0 ? 0 : y;
yField = yField + divHeight > winHeight ? winHeight - divHeight : yField;
styles.popper.transform = `translate3d(${x}px, ${yField}px, ${z}px)`;
styles.popper.transform = `translate3d(${x}px, ${yField}px, ${z || 0}px)`;
} else if (styles?.popper?.bottom === '0') {
const yField = y + divHeight > 0 ? 0 : y;
styles.popper.transform = `translate3d(${x}px, ${yField}px, ${z}px)`;
styles.popper.transform = `translate3d(${x}px, ${yField}px, ${z || 0}px)`;
}
}
}
Expand Down

1 comment on commit d20aa1d

@vercel
Copy link

@vercel vercel bot commented on d20aa1d Dec 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.