Skip to content

Commit

Permalink
Iframe: Bubble events from html element instead of body element to fi…
Browse files Browse the repository at this point in the history
…x drag chip positioning (#56099)
  • Loading branch information
andrewserong authored Nov 14, 2023
1 parent 8850bfb commit db508a2
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/block-editor/src/components/iframe/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,13 @@ function bubbleEvent( event, Constructor, frame ) {
* @param {Document} iframeDocument Document to attach listeners to.
*/
function useBubbleEvents( iframeDocument ) {
return useRefEffect( ( body ) => {
return useRefEffect( () => {
const { defaultView } = iframeDocument;
if ( ! defaultView ) {
return;
}
const { frameElement } = defaultView;
const html = iframeDocument.documentElement;
const eventTypes = [ 'dragover', 'mousemove' ];
const handlers = {};
for ( const name of eventTypes ) {
Expand All @@ -88,12 +89,12 @@ function useBubbleEvents( iframeDocument ) {
const Constructor = window[ constructorName ];
bubbleEvent( event, Constructor, frameElement );
};
body.addEventListener( name, handlers[ name ] );
html.addEventListener( name, handlers[ name ] );
}

return () => {
for ( const name of eventTypes ) {
body.removeEventListener( name, handlers[ name ] );
html.removeEventListener( name, handlers[ name ] );
}
};
} );
Expand Down

0 comments on commit db508a2

Please sign in to comment.