Skip to content

Commit

Permalink
fix(popover): update popover position when bottom is 0 (#1796)
Browse files Browse the repository at this point in the history
* fix(popover): update popover position when bottom is 0

* fix(code): eslint

Co-authored-by: Zhang Rui <zhangrui@growingio.com>
  • Loading branch information
Ryan Zhang and Zhang Rui committed Jan 13, 2022
1 parent 2da742b commit 006451c
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/popover/usePop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ const clear3D = (transform: string): string | number[] => {
return transform;
};

const getMaxHeight = (element: HTMLElement, maxHeight = 0): number => {
if (!element) {
return maxHeight;
}
const elHeight = element.offsetHeight;
const newMax = elHeight > maxHeight ? elHeight : maxHeight;
if (element.parentElement) {
return getMaxHeight(element.parentElement, newMax);
}
return window.innerHeight > maxHeight ? window.innerHeight : maxHeight;
};
// const getMaxHeight = (element: HTMLElement, maxHeight = 0): number => {
// if (!element) {
// return maxHeight;
// }
// const elHeight = element.offsetHeight;
// const newMax = elHeight > maxHeight ? elHeight : maxHeight;
// if (element.parentElement) {
// return getMaxHeight(element.parentElement, newMax);
// }
// return window.innerHeight > maxHeight ? window.innerHeight : maxHeight;
// };

const getBottomOfElement = (element: HTMLElement) => element?.getBoundingClientRect()?.bottom;
// const getElementHeight = (element: HTMLElement) => element.offsetHeight;
Expand All @@ -62,7 +62,7 @@ const usePop = ({ referenceElement, popperElement, placement, modifiers, strateg
if (Array.isArray(three)) {
const [x, y, z] = three;
const divHeight = popperElement.offsetHeight;
const pageHeight = getMaxHeight(referenceElement);
// const pageHeight = getMaxHeight(referenceElement);
const winHeight = window.innerHeight;

if (styles?.popper?.bottom === 'auto') {
Expand All @@ -79,9 +79,9 @@ const usePop = ({ referenceElement, popperElement, placement, modifiers, strateg
}
styles.popper.transform = `translate3d(${x}px, ${yField}px, ${z || 0}px)`;
} else if (styles?.popper?.bottom === '0') {
const maxYField = pageHeight - (window.pageYOffset + window.innerHeight);
const yField = y + divHeight > maxYField ? maxYField : y;
styles.popper.transform = `translate3d(${x}px, ${yField}px, ${z || 0}px)`;
// const maxYField = pageHeight - (window.pageYOffset + window.innerHeight);
// const yField = y + divHeight > maxYField ? maxYField : y;
styles.popper.transform = `translate3d(${x}px, ${y}px, ${z || 0}px)`;
}
}
}
Expand Down

1 comment on commit 006451c

@vercel
Copy link

@vercel vercel bot commented on 006451c Jan 13, 2022

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.