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