Skip to content

Commit 839e365

Browse files
committed
Possible fix
1 parent 2e9dcf8 commit 839e365

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/__tests__/anchored-position.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,9 +400,9 @@ describe('getAnchoredPosition', () => {
400400
const settings: Partial<PositionSettings> = {side: 'outside-bottom', align: 'start'}
401401
const {top, left, anchorSide} = getAnchoredPosition(float, anchor, settings)
402402

403-
// Should keep the requested bottom side, allowing the overlay to extend below viewport
403+
// Should flip to top side to avoid rendering below viewport, even with scrollable space
404404
expect(anchorSide).toEqual('outside-top')
405-
expect(top).toEqual(796) // anchorRect.top + anchorRect.height + anchorOffset (4)
405+
expect(top).toEqual(796) // anchorRect.top - floatingRect.height - anchorOffset (4) = 950 - 150 - 4
406406
expect(left).toEqual(100) // anchorRect.left
407407
})
408408
})

src/anchored-position.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,11 @@ function getClippingRect(element: Element): BoxPosition {
233233
left: elemRect.left + borderLeft,
234234
width: elemRect.width - borderRight - borderLeft,
235235

236-
// If the clipping node is document.body, it can expand to the full height of the window
237-
height: Math.max(
238-
elemRect.height - borderTop - borderBottom,
239-
clippingNode === document.body ? window.innerHeight : -Infinity,
240-
),
236+
// If the clipping node is document.body, use the viewport height instead of body height
237+
height:
238+
clippingNode === document.body
239+
? window.innerHeight
240+
: Math.max(elemRect.height - borderTop - borderBottom, -Infinity),
241241
}
242242
}
243243

0 commit comments

Comments
 (0)