@@ -10,6 +10,7 @@ import {
1010 Margin ,
1111 DEFAULT_MARGIN ,
1212 PaddingWrapper ,
13+ OUTSIDE_VIEWPORT_STYLE ,
1314} from "../../utils/position" ;
1415import { throttle } from "../../utils/throttle" ;
1516import { Button } from "../button" ;
@@ -55,6 +56,12 @@ export function ExtendedPopover({
5556 adjustPositionToViewportSize
5657 ) ;
5758
59+ function closePopover ( ) {
60+ close ( ) ;
61+ setTriggerDimensions ( null ) ;
62+ setContentDimensions ( null ) ;
63+ }
64+
5865 React . useEffect ( ( ) => {
5966 if (
6067 isOpen &&
@@ -75,7 +82,7 @@ export function ExtendedPopover({
7582 ! contentRef . current . contains ( event . target as Node ) &&
7683 ! triggerRef . current . contains ( event . target as Node )
7784 ) {
78- close ( ) ;
85+ closePopover ( ) ;
7986 }
8087 } ,
8188 [ contentRef , triggerRef , clickOutsideToClose ]
@@ -85,7 +92,7 @@ export function ExtendedPopover({
8592
8693 const handleScroll = throttle (
8794 React . useCallback ( ( ) => {
88- close ( ) ;
95+ closePopover ( ) ;
8996 } , [ ] )
9097 ) ;
9198
@@ -104,7 +111,7 @@ export function ExtendedPopover({
104111 onMouseEnter : ( ) => open ( ) ,
105112 onMouseLeave : ( ) => {
106113 if ( closeOn === "hover" ) {
107- close ( ) ;
114+ closePopover ( ) ;
108115 }
109116 } ,
110117 } ) ,
@@ -151,9 +158,13 @@ function Popover({
151158 content,
152159 placement,
153160} : PopoverProps ) {
161+ // on empty style render popover outside viewport to prevent blinking effect
154162 return visible
155163 ? ReactDOM . createPortal (
156- < ContentWrapper ref = { contentRef } style = { style } >
164+ < ContentWrapper
165+ ref = { contentRef }
166+ style = { style . top && style . left ? style : OUTSIDE_VIEWPORT_STYLE }
167+ >
157168 < PaddingWrapper { ...margin } placement = { placement } >
158169 { content }
159170 </ PaddingWrapper >
0 commit comments