Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dropdown not correctly positioned horizontally when body position is relative #927

Merged
merged 1 commit into from
Jun 18, 2024
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
Loading