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
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/media-editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"@wordpress/i18n": "file:../i18n",
"@wordpress/icons": "file:../icons",
"@wordpress/interface": "file:../interface",
"@wordpress/keyboard-shortcuts": "file:../keyboard-shortcuts",
"@wordpress/keycodes": "file:../keycodes",
"@wordpress/notices": "file:../notices",
"@wordpress/private-apis": "file:../private-apis",
Expand Down
39 changes: 28 additions & 11 deletions packages/media-editor/src/components/media-editor-modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import { Modal } from '@wordpress/components';
import { useDispatch, useSelect } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { ShortcutProvider } from '@wordpress/keyboard-shortcuts';
import type { Field } from '@wordpress/dataviews';
import type { KeyboardEvent as ReactKeyboardEvent } from 'react';

/**
* Internal dependencies
Expand Down Expand Up @@ -52,6 +54,16 @@ export function MediaEditorModal( {
const portalElement =
typeof document === 'undefined' ? null : document.body;

// React synthetic events bubble through the React tree, not the DOM tree,
// so a host `ShortcutProvider` higher up still receives keydown events
// from inside this portaled modal. Stop propagation at the modal boundary
// so host shortcuts (undo/redo, save, etc.) don't fire from within.
const stopKeyDownPropagation = (
event: ReactKeyboardEvent< HTMLDivElement >
) => {
event.stopPropagation();
};

return (
<MediaEditor
id={ id }
Expand Down Expand Up @@ -79,18 +91,23 @@ export function MediaEditorModal( {
onKeyDown,
shouldCloseOnClickOutside,
} ) => (
<Modal
className="media-editor-modal"
title={ __( 'Edit media' ) }
size="fill"
isDismissible={ false }
shouldCloseOnClickOutside={ shouldCloseOnClickOutside }
onKeyDown={ onKeyDown }
onRequestClose={ onRequestClose }
headerActions={ headerActions }
<ShortcutProvider
className="media-editor-modal__shortcut-scope"
onKeyDown={ stopKeyDownPropagation }
>
{ children }
</Modal>
<Modal
className="media-editor-modal"
title={ __( 'Edit media' ) }
size="fill"
isDismissible={ false }
shouldCloseOnClickOutside={ shouldCloseOnClickOutside }
onKeyDown={ onKeyDown }
onRequestClose={ onRequestClose }
headerActions={ headerActions }
>
{ children }
</Modal>
</ShortcutProvider>
) }
/>
);
Expand Down
1 change: 1 addition & 0 deletions packages/media-editor/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
{ "path": "../element" },
{ "path": "../i18n" },
{ "path": "../icons" },
{ "path": "../keyboard-shortcuts" },
{ "path": "../keycodes" },
{ "path": "../notices" },
{ "path": "../private-apis" },
Expand Down
Loading