Last active
February 27, 2022 05:44
-
-
Save tadeaspetak/c54534a7eacdcc95d2761be13df54441 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// resolve focus on opening and closing | |
useEffect(() => { | |
if (open) { | |
previousFocus.current = (document.activeElement as HTMLElement) ?? null; | |
nextFocus(getFocusableElements(container.current)); | |
} else { | |
previousFocus.current?.focus?.(); | |
previousFocus.current = null; | |
} | |
}, [open, portal]); | |
// ... in our key listener, manage `tab` presses | |
switch (e.key) { | |
case "Tab": { | |
e.preventDefault(); | |
nextFocus(getFocusableElements(container.current), !e.shiftKey); | |
break; | |
} | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment