mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 04:46:40 +07:00
closing modal on back button
This commit is contained in:
parent
5a6e34d769
commit
49efc452d3
1 changed files with 14 additions and 0 deletions
|
@ -67,6 +67,20 @@ const PhotoSwipeUnconnected: FC<Props> = ({ photoswipe, modalSetShown }) => {
|
|||
});
|
||||
}, [photoswipe.images, photoswipe.index]);
|
||||
|
||||
const closeOnHashChange = useCallback(() => {
|
||||
if (window.location.hash !== '#preview') return closeModal();
|
||||
}, [closeModal]);
|
||||
|
||||
useEffect(() => {
|
||||
window.addEventListener('hashchange', closeOnHashChange);
|
||||
return () => window.removeEventListener('hashchange', closeOnHashChange);
|
||||
}, [closeOnHashChange]);
|
||||
|
||||
useEffect(() => {
|
||||
window.location.hash = 'preview';
|
||||
return () => (window.location.hash = '');
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="pswp" tabIndex={-1} role="dialog" aria-hidden="true" ref={ref}>
|
||||
<div className={classNames('pswp__bg', styles.bg)} />
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue