Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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