Composer: Fix arrow keys reset forwarding

This commit is contained in:
Alexander Zinchuk 2021-12-25 12:41:10 +01:00
parent 2dc6f738b6
commit 0d48faba2f

View File

@ -394,7 +394,11 @@ const MediaViewer: FC<StateProps & DispatchProps> = ({
}); });
useEffect(() => { useEffect(() => {
const handleKeyDown = (e: KeyboardEvent) => { if (!isOpen) {
return undefined;
}
function handleKeyDown(e: KeyboardEvent) {
switch (e.key) { switch (e.key) {
case 'Left': // IE/Edge specific value case 'Left': // IE/Edge specific value
case 'ArrowLeft': case 'ArrowLeft':
@ -406,14 +410,14 @@ const MediaViewer: FC<StateProps & DispatchProps> = ({
selectMessage(nextMessageId); selectMessage(nextMessageId);
break; break;
} }
}; }
document.addEventListener('keydown', handleKeyDown, false); document.addEventListener('keydown', handleKeyDown, false);
return () => { return () => {
document.removeEventListener('keydown', handleKeyDown, false); document.removeEventListener('keydown', handleKeyDown, false);
}; };
}, [nextMessageId, previousMessageId, selectMessage]); }, [isOpen, nextMessageId, previousMessageId, selectMessage]);
useEffect(() => { useEffect(() => {
if (isZoomed || IS_TOUCH_ENV) return undefined; if (isZoomed || IS_TOUCH_ENV) return undefined;