Make ESC key dismiss MediaEditor and TextStoryCreator modals

This commit is contained in:
Alvaro 2022-08-15 13:35:30 -06:00 committed by GitHub
parent 385eb63fd5
commit 95be24e8f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 61 additions and 9 deletions

View file

@ -214,9 +214,19 @@ export const TextStoryCreator = ({
};
const handleEscape = (event: KeyboardEvent) => {
if (event.key === 'Escape') {
setIsColorPickerShowing(false);
event.preventDefault();
event.stopPropagation();
if (
isColorPickerShowing ||
isEditingText ||
isLinkPreviewInputShowing
) {
setIsColorPickerShowing(false);
setIsEditingText(false);
setIsLinkPreviewInputShowing(false);
event.preventDefault();
event.stopPropagation();
} else {
onClose();
}
}
};
@ -227,7 +237,13 @@ export const TextStoryCreator = ({
document.removeEventListener('click', handleOutsideClick);
document.removeEventListener('keydown', handleEscape);
};
}, [isColorPickerShowing, colorPickerPopperButtonRef]);
}, [
isColorPickerShowing,
isEditingText,
isLinkPreviewInputShowing,
colorPickerPopperButtonRef,
onClose,
]);
const sliderColorNumber = getRGBANumber(sliderValue);