Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/components/Editor/MediaUploader/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,13 @@ const MediaUploader = ({ mediaUploader, onClose, editor, unsplashApiKey }) => {
.run();
};

const handleKeydown = event =>
not(isUploading) && event.key === "Escape" && handleClose();

return (
<Modal
{...{ isOpen }}
className="ne-media-uploader-modal"
closeButton={false}
closeOnOutsideClick={not(isUploading)}
onClose={handleClose}
onKeyDown={handleKeydown}
>
<div className="ne-media-uploader">
{!isNotPresent(tabs) && (
Expand Down
18 changes: 9 additions & 9 deletions src/components/EditorContent/ImagePreview.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,17 @@ const ImagePreview = ({ imagePreviewDetails, setImagePreviewDetails }) => {
});

useEffect(() => {
document.addEventListener(
"keydown",
e => e.key === "Escape" && setImagePreviewDetails(null)
);
if (!imagePreviewRef.current) return;

return () =>
document.removeEventListener(
"keydown",
e => e.key === "Escape" && setImagePreviewDetails(null)
);
imagePreviewRef.current.setAttribute("tabindex", "-1");
imagePreviewRef.current.focus();
}, []);

const handleKeyDown = e => {
e.stopPropagation();
e.key === "Escape" && setImagePreviewDetails(null);
};

return createPortal(
<div className="ne-image-preview-wrapper active">
{isLoading && <Spinner className="ne-image-preview-wrapper__spinner" />}
Expand All @@ -52,6 +51,7 @@ const ImagePreview = ({ imagePreviewDetails, setImagePreviewDetails }) => {
alt={t("neetoEditor.editorContent.imagePreviewAltText")}
ref={imagePreviewRef}
src={imagePreviewDetails.src}
onKeyDown={handleKeyDown}
onLoad={() => setIsLoading(false)}
/>
{imagePreviewDetails && (
Expand Down
Loading