Skip to content

Commit

Permalink
Add a fix to the calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
pksjce committed Nov 14, 2023
1 parent c18ae86 commit ecb0717
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/__tests__/anchored-position.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ describe('getAnchoredPosition', () => {
// Not really sure what to expect here.
expect(anchorSide).toEqual('outside-right')
expect(anchorAlign).toEqual('start')
expect(top).toEqual(-28) // should be 16 which is the top start of the anchor element. Negative value is wrong.
expect(top).toEqual(0)
expect(left).toEqual(52)
})
})
3 changes: 2 additions & 1 deletion src/anchored-position.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,8 @@ function pureCalculateAnchoredPosition(
// likely to be able to scroll.
if (alternateOrder && positionAttempt < alternateOrder.length) {
if (pos.top + floatingRect.height > viewportRect.height + relativeViewportRect.top) {
pos.top = viewportRect.height + relativeViewportRect.top - floatingRect.height
// This prevents top from being a negative value
pos.top = Math.max(viewportRect.height + relativeViewportRect.top - floatingRect.height, 0)
}
}
}
Expand Down

0 comments on commit ecb0717

Please sign in to comment.