Merged in feat/SW-2800-lightbox-history-state (pull request #2147)
feat(SW-2800): closing image gallery and lightbox on using browser navigation * feat(SW-2800): closing image gallery and lightbox on using browser navigation Approved-by: Linus Flood
This commit is contained in:
committed by
Linus Flood
parent
93a155f1e4
commit
41e09f082a
@@ -46,6 +46,20 @@ export default function Lightbox({
|
||||
)
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
function handlePopState() {
|
||||
handleClose()
|
||||
}
|
||||
|
||||
window.history.pushState(null, "", window.location.href)
|
||||
window.addEventListener("popstate", handlePopState)
|
||||
|
||||
return () => {
|
||||
window.removeEventListener("popstate", handlePopState)
|
||||
}
|
||||
/* eslint-disable-next-line react-hooks/exhaustive-deps */
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<ModalOverlay
|
||||
isOpen={isOpen}
|
||||
@@ -79,7 +93,7 @@ export default function Lightbox({
|
||||
) : (
|
||||
<Gallery
|
||||
images={images}
|
||||
onClose={onClose}
|
||||
onClose={handleClose}
|
||||
onSelectImage={(image) => {
|
||||
setSelectedImageIndex(
|
||||
images.findIndex((img) => img === image)
|
||||
|
||||
Reference in New Issue
Block a user