Close navigation if the user tabs out of navigation links

This commit is contained in:
Helen Chong 2024-06-08 00:45:21 +08:00
parent a7c2bf8f29
commit 85ef8b87b3
1 changed files with 9 additions and 0 deletions

View File

@ -118,4 +118,13 @@
closeNavigation(); closeNavigation();
} }
}); });
const handleBlur = () => {
const navList = event.currentTarget.closest(".navbar__links");
if (!event.relatedTarget || !navList.contains(event.relatedTarget)) {
closeNavigation();
}
}
navbarLinkItems[navbarLinkItems.length - 1].addEventListener("blur", handleBlur);
</script> </script>