@@ -30,22 +30,32 @@ function Pop({
3030 if ( ! popperRef . current || ! containerRef . current || ! target ) return
3131
3232 const targetRect = target . getBoundingClientRect ( )
33+ const containerRect = containerRef . current . getBoundingClientRect ( )
3334 const popperRect = popperRef . current . getBoundingClientRect ( )
3435
35- let topOffset = targetRect . bottom + offset . y
36+ // eslint-disable-next-line
37+ console . log ( 'targetRect' , targetRect )
38+ // eslint-disable-next-line
39+ console . log ( 'containerRect' , containerRect )
40+ // eslint-disable-next-line
41+ console . log ( 'popperRect' , popperRect )
42+ // eslint-disable-next-line
43+ console . log ( 'offset' , offset )
3644
37- if ( topOffset + popperRect . height > window . innerHeight ) {
38- topOffset = targetRect . top - popperRect . height - offset . y
39- }
45+ const topOffset =
46+ targetRect . bottom + offset . y > containerRect . bottom
47+ ? targetRect . top - popperRect . height - offset . y
48+ : targetRect . bottom + offset . y
4049
41- let leftOffset = targetRect . left
42- if ( leftOffset + popperRect . width > window . innerWidth ) {
43- leftOffset = targetRect . right - popperRect . width
44- }
50+ const leftOffset =
51+ targetRect . right + popperRect . width > containerRect . right
52+ ? targetRect . left - popperRect . width + targetRect . width
53+ : targetRect . left
4554
4655 popperRef . current . style . top = `${ topOffset } px`
4756 popperRef . current . style . left = `${ leftOffset } px`
48- } , [ offset , target , containerRef , popperRef ] )
57+ // eslint-disable-next-line react-hooks/exhaustive-deps
58+ } , [ offset . x , offset . y , target , containerRef , popperRef ] )
4959
5060 const { width } = position
5161 const style = {
0 commit comments