Lightbox keybinds (#928)

* Add mousetrap-pause
* Disable keybinds while lightbox open
This commit is contained in:
WithoutPants
2020-11-08 11:22:38 +11:00
committed by GitHub
parent 94392c7c4d
commit 8097cd39d2
5 changed files with 25 additions and 0 deletions

View File

@@ -53,6 +53,18 @@ const ImageWall: React.FC<IImageWallProps> = ({ images }) => {
// FsLightbox doesn't update unless the key updates
const key = images.map((i) => i.id).join(",");
function onLightboxOpen() {
// disable mousetrap
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(Mousetrap as any).pause();
}
function onLightboxClose() {
// re-enable mousetrap
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(Mousetrap as any).unpause();
}
return (
<div className="gallery">
<div className="flexbin">{thumbs}</div>
@@ -61,6 +73,8 @@ const ImageWall: React.FC<IImageWallProps> = ({ images }) => {
toggler={lightboxToggle}
sources={photos}
key={key}
onOpen={onLightboxOpen}
onClose={onLightboxClose}
/>
</div>
);