Skip to content

Commit

Permalink
fix: dropdown not correctly positioned horizontally when body positio…
Browse files Browse the repository at this point in the history
…n is relative (#927)
  • Loading branch information
ArnaudWeyts authored Jun 18, 2024
1 parent ff8216b commit d1b2320
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions ember-basic-dropdown/src/utils/calculate-position.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,21 @@ export const calculateWormholedPosition: CalculatePosition = (
style.width = dropdownWidth;
}

/**
* Fixes bug where the dropdown always stays on the same position on the screen when
* the <body> is relatively positioned
*/
const isBodyPositionRelative =
window.getComputedStyle(document.body).getPropertyValue('position') ===
'relative';

// Calculate horizontal position
const triggerLeftWithScroll = triggerLeft + scroll.left;
let triggerLeftWithScroll = triggerLeft;

if (!isBodyPositionRelative) {
triggerLeftWithScroll += scroll.left;
}

if (horizontalPosition === 'auto' || horizontalPosition === 'auto-left') {
// Calculate the number of visible horizontal pixels if we were to place the
// dropdown on the left and right
Expand Down Expand Up @@ -151,13 +164,6 @@ export const calculateWormholedPosition: CalculatePosition = (
// Calculate vertical position
let triggerTopWithScroll = triggerTop;

/**
* Fixes bug where the dropdown always stays on the same position on the screen when
* the <body> is relatively positioned
*/
const isBodyPositionRelative =
window.getComputedStyle(document.body).getPropertyValue('position') ===
'relative';
if (!isBodyPositionRelative) {
triggerTopWithScroll += scroll.top;
}
Expand Down

0 comments on commit d1b2320

Please sign in to comment.