File tree Expand file tree Collapse file tree 1 file changed +10
-0
lines changed
site/src/components/Popover Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import {
13
13
cloneElement ,
14
14
createContext ,
15
15
useContext ,
16
+ useEffect ,
16
17
useId ,
17
18
useRef ,
18
19
useState ,
@@ -66,6 +67,15 @@ export const Popover: FC<PopoverProps> = (props) => {
66
67
const [ uncontrolledOpen , setUncontrolledOpen ] = useState ( false ) ;
67
68
const triggerRef : TriggerRef = useRef ( null ) ;
68
69
70
+ // This doesn't guarantee that we'll always close any popovers when the
71
+ // user switches tabs when the component is being controlled, but this is
72
+ // basically the most we can do from this component
73
+ useEffect ( ( ) => {
74
+ const closeOnTabSwitch = ( ) => setUncontrolledOpen ( false ) ;
75
+ window . addEventListener ( "blur" , closeOnTabSwitch ) ;
76
+ return ( ) => window . addEventListener ( "blur" , closeOnTabSwitch ) ;
77
+ } , [ ] ) ;
78
+
69
79
const value : PopoverContextValue = {
70
80
triggerRef,
71
81
id : `${ hookId } -popover` ,
You can’t perform that action at this time.
0 commit comments