Very experimental handle "back" to close media modal

Don't try this at home, kids
This commit is contained in:
Lim Chee Aun 2023-03-23 15:54:17 +08:00
parent 9822583048
commit 0f1b08b3ea

View file

@ -22,6 +22,17 @@ function MediaModal({
const carouselFocusItem = useRef(null);
useLayoutEffect(() => {
carouselFocusItem.current?.scrollIntoView();
history.pushState({ mediaModal: true }, '');
const handlePopState = (e) => {
if (e.state?.mediaModal) {
onClose();
}
};
window.addEventListener('popstate', handlePopState);
return () => {
window.removeEventListener('popstate', handlePopState);
};
}, []);
const prevStatusID = useRef(statusID);
useEffect(() => {