Skip to content

Commit 6a2cfcf

Browse files
committed
fix: add blur behavior to popover
1 parent 0f64533 commit 6a2cfcf

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

site/src/components/Popover/Popover.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
cloneElement,
1414
createContext,
1515
useContext,
16+
useEffect,
1617
useId,
1718
useRef,
1819
useState,
@@ -66,6 +67,15 @@ export const Popover: FC<PopoverProps> = (props) => {
6667
const [uncontrolledOpen, setUncontrolledOpen] = useState(false);
6768
const triggerRef: TriggerRef = useRef(null);
6869

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+
6979
const value: PopoverContextValue = {
7080
triggerRef,
7181
id: `${hookId}-popover`,

0 commit comments

Comments
 (0)