Skip to content

Commit

Permalink
Allow for multiple iframed editors on a page
Browse files Browse the repository at this point in the history
  • Loading branch information
jeryj authored and scruffian committed Jun 19, 2024
1 parent 831c206 commit cf6cea5
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions packages/block-editor/src/components/block-tools/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,23 @@ export default function BlockTools( {
) {
event.preventDefault();
clearSelectedBlock();

// If we're iframed, we need to use the iframe instead of the contentRef
// If there are multiple editors, we need to find the iframe that contains our contentRef to make sure
// we're focusing the region that contains this editor.
const editorCanvas =
__unstableContentRef.current.ownerDocument !== document
? document.querySelector(
'iframe[name="editor-canvas"]'
)
: __unstableContentRef.current;
document
.querySelectorAll( 'iframe[name="editor-canvas"]' )
.values()
.find( ( iframe ) => {
// Find the iframe that contains our contentRef
const iframeDocument =
iframe.contentDocument ||
iframe.contentWindow.document;

return (
iframeDocument ===
__unstableContentRef.current.ownerDocument
);
} ) ?? __unstableContentRef.current;

// The region is provivided by the editor, not the block-editor.
// We should send focus to the region if one is available to reuse the
Expand Down

0 comments on commit cf6cea5

Please sign in to comment.