@@ -30,23 +30,22 @@ function Pop({
3030 if ( ! popperRef . current || ! containerRef . current || ! target ) return
3131
3232 const targetRect = target . getBoundingClientRect ( )
33- const containerRect = containerRef . current . getBoundingClientRect ( )
3433 const popperRect = popperRef . current . getBoundingClientRect ( )
3534
36- const topOffset =
37- targetRect . bottom + offset . y > containerRect . bottom
38- ? targetRect . top - popperRect . height - offset . y
39- : targetRect . bottom + offset . y
35+ let topOffset = targetRect . bottom + offset . y
4036
41- const leftOffset =
42- targetRect . right + popperRect . width > containerRect . right
43- ? targetRect . left - popperRect . width + targetRect . width
44- : targetRect . left
37+ if ( topOffset + popperRect . height > window . innerHeight ) {
38+ topOffset = targetRect . top - popperRect . height - offset . y
39+ }
40+
41+ let leftOffset = targetRect . left
42+ if ( leftOffset + popperRect . width > window . innerWidth ) {
43+ leftOffset = targetRect . right - popperRect . width
44+ }
4545
4646 popperRef . current . style . top = `${ topOffset } px`
4747 popperRef . current . style . left = `${ leftOffset } px`
48- // eslint-disable-next-line react-hooks/exhaustive-deps
49- } , [ offset . x , offset . y , target , containerRef , popperRef ] )
48+ } , [ offset , target , containerRef , popperRef ] )
5049
5150 const { width } = position
5251 const style = {
0 commit comments