Skip to content

Commit

Permalink
Merge pull request #295 from ghiscoding/bugfix/position-outside-viewport
Browse files Browse the repository at this point in the history
fix: make sure picker position is never outside body viewport
  • Loading branch information
uvarov-frontend authored Aug 18, 2024
2 parents 5ba6b06 + 9e6767f commit 6f2f53d
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion package/src/scripts/helpers/position.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,17 @@ export const setPositionCalendar = (input: HTMLInputElement | undefined, calenda

const { top: offsetTop, left: offsetLeft } = getOffset(input);
const top = offsetTop + getPosition[YPosition];
const left = offsetLeft + getPosition[XPosition];
let left = offsetLeft + getPosition[XPosition];

// make sure the new position is not outside the viewport,
// if so then change position to have enough space to show full picker
const { vw } = getViewportDimensions();
if (left + calendar.clientWidth > vw) {
const scrollbarWidth = (window.innerWidth - document.body.clientWidth);
left = vw - calendar.clientWidth - scrollbarWidth;
} else if (left < 0) {
left = 0;
}

Object.assign(calendar.style, { left: `${left}px`, top: `${top}px` });
}
Expand Down

0 comments on commit 6f2f53d

Please sign in to comment.