diff --git a/packages/block-editor/src/components/block-list/insertion-point.js b/packages/block-editor/src/components/block-list/insertion-point.js index c7eb0e8d6ee80a..8055dff0e37e43 100644 --- a/packages/block-editor/src/components/block-list/insertion-point.js +++ b/packages/block-editor/src/components/block-list/insertion-point.js @@ -51,9 +51,10 @@ function InsertionPointInserter( { return; } + const { ownerDocument } = ref.current; const targetRect = target.getBoundingClientRect(); const isReverse = clientY < targetRect.top + targetRect.height / 2; - const blockNode = getBlockDOMNode( clientId ); + const blockNode = getBlockDOMNode( clientId, ownerDocument ); const container = isReverse ? containerRef.current : blockNode; const closest = getClosestTabbable( blockNode, true, container ) || blockNode; @@ -100,7 +101,8 @@ function InsertionPointPopover( { containerRef, showInsertionPoint, } ) { - const element = getBlockDOMNode( clientId ); + const { ownerDocument } = containerRef.current; + const element = getBlockDOMNode( clientId, ownerDocument ); return ( ) } diff --git a/packages/format-library/src/link/inline.js b/packages/format-library/src/link/inline.js index 9d190ac201c775..9107bfa6bd916a 100644 --- a/packages/format-library/src/link/inline.js +++ b/packages/format-library/src/link/inline.js @@ -26,6 +26,7 @@ function InlineLinkUI( { onChange, speak, stopAddingLink, + forwardedRef, } ) { /** * A unique key is generated when switching between editing and not editing @@ -54,7 +55,9 @@ function InlineLinkUI( { const [ nextLinkValue, setNextLinkValue ] = useState(); const anchorRef = useMemo( () => { - const selection = window.getSelection(); + const { ownerDocument } = forwardedRef.current; + const { defaultView } = ownerDocument; + const selection = defaultView.getSelection(); if ( ! selection.rangeCount ) { return; diff --git a/packages/rich-text/src/component/format-edit.js b/packages/rich-text/src/component/format-edit.js index 753e6a02739b57..2f320d68dee4d8 100644 --- a/packages/rich-text/src/component/format-edit.js +++ b/packages/rich-text/src/component/format-edit.js @@ -30,6 +30,7 @@ export default function FormatEdit( { value, allowedFormats, withoutInteractiveFormatting, + forwardedRef, } ) { return formatTypes.map( ( { name, edit: Edit, tagName } ) => { if ( ! Edit ) { @@ -67,6 +68,7 @@ export default function FormatEdit( { value={ value } onChange={ onChange } onFocus={ onFocus } + forwardedRef={ forwardedRef } /> ); } ); diff --git a/packages/rich-text/src/component/index.js b/packages/rich-text/src/component/index.js index 04fcb77f92b606..7827dfd2b49e3f 100644 --- a/packages/rich-text/src/component/index.js +++ b/packages/rich-text/src/component/index.js @@ -1138,6 +1138,7 @@ function RichText( onChange={ handleChange } onFocus={ focus } formatTypes={ formatTypes } + forwardedRef={ ref } /> ) } { children &&