Skip to content

Commit 84d9b7b

Browse files
authored
Merge pull request #1598 from ASU/safari-header-fix
fix(component-header-footer): fix header focus change that broke safari links
2 parents d19e746 + 79fda2b commit 84d9b7b

File tree

1 file changed

+5
-7
lines changed
  • packages/component-header-footer/src/header/components/HeaderMain/NavbarContainer/NavItem

1 file changed

+5
-7
lines changed

packages/component-header-footer/src/header/components/HeaderMain/NavbarContainer/NavItem/index.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,23 +69,21 @@ const NavItem = ({ link, setItemOpened, itemOpened }) => {
6969
}
7070
};
7171

72-
const handleFocusOut = () => {
73-
setTimeout(() => {
72+
const handleFocusChange = () => {
73+
requestAnimationFrame(() => {
7474
const node = clickRef.current;
7575
if (opened && node && !node.contains(document.activeElement)) {
7676
setItemOpened();
7777
}
78-
}, 0);
78+
});
7979
};
8080

81-
const node = clickRef.current;
82-
8381
document.addEventListener("click", handleClickOutside, true);
84-
node?.addEventListener("focusout", handleFocusOut);
82+
document.addEventListener("focusin", handleFocusChange);
8583

8684
return () => {
8785
document.removeEventListener("click", handleClickOutside, true);
88-
node?.removeEventListener("focusout", handleFocusOut);
86+
document.removeEventListener("focusin", handleFocusChange);
8987
};
9088
}, [opened]);
9189

0 commit comments

Comments
 (0)