From 9bc7533010662732d671fd1a93e2fb498e9d14dc Mon Sep 17 00:00:00 2001 From: Aman Harwara Date: Tue, 26 Jul 2022 15:54:15 +0530 Subject: [PATCH] fix: preview modal keyboard handling (#1345) --- .../FilePreview/FilePreviewModal.tsx | 61 ++++++++++--------- 1 file changed, 33 insertions(+), 28 deletions(-) diff --git a/packages/web/src/javascripts/Components/FilePreview/FilePreviewModal.tsx b/packages/web/src/javascripts/Components/FilePreview/FilePreviewModal.tsx index 9101b3ea2..093e09237 100644 --- a/packages/web/src/javascripts/Components/FilePreview/FilePreviewModal.tsx +++ b/packages/web/src/javascripts/Components/FilePreview/FilePreviewModal.tsx @@ -27,9 +27,9 @@ const FilePreviewModal: FunctionComponent = observer(({ application, view const keyDownHandler: KeyboardEventHandler = useCallback( (event) => { - const hasNotPressedLeftOrRightKeys = event.key !== KeyboardKey.Left && event.key !== KeyboardKey.Right + const KeysToHandle: string[] = [KeyboardKey.Left, KeyboardKey.Right, KeyboardKey.Escape] - if (hasNotPressedLeftOrRightKeys) { + if (!KeysToHandle.includes(event.key)) { return } @@ -54,9 +54,12 @@ const FilePreviewModal: FunctionComponent = observer(({ application, view } break } + case KeyboardKey.Escape: + dismiss() + break } }, - [currentFile.uuid, otherFiles, setCurrentFile], + [currentFile.uuid, dismiss, otherFiles, setCurrentFile], ) const IconComponent = useMemo( @@ -81,37 +84,39 @@ const FilePreviewModal: FunctionComponent = observer(({ application, view className="flex min-h-[90%] min-w-[90%] flex-col rounded bg-[color:var(--modal-background-color)] p-0 shadow-main " >
-
-
{IconComponent}
- {currentFile.name} +
+
+
{IconComponent}
+ {currentFile.name} +
+
+ + +
-
- - +
+
+ +
+ {showFileInfoPanel && }
-
-
- -
- {showFileInfoPanel && } -
)