Skip to content

Commit

Permalink
Fix padding appender hook (#66143)
Browse files Browse the repository at this point in the history
* Fix focus inserted default block

* Support clicks below the padding in the iframed editor

Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: kevin940726 <kevin940726@git.wordpress.org>
Co-authored-by: afercia <afercia@git.wordpress.org>
  • Loading branch information
4 people authored and gutenbergplugin committed Oct 16, 2024
1 parent b43d31f commit bbf2aad
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions packages/edit-post/src/components/layout/use-padding-appender.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ export function usePaddingAppender() {
return useRefEffect(
( node ) => {
function onMouseDown( event ) {
if ( event.target !== node ) {
if (
event.target !== node &&
// Tests for the parent element because in the iframed editor if the click is
// below the padding the target will be the parent element (html) and should
// still be treated as intent to append.
event.target !== node.parentElement
) {
return;
}

Expand All @@ -38,7 +44,7 @@ export function usePaddingAppender() {
return;
}

event.stopPropagation();
event.preventDefault();

const blockOrder = registry
.select( blockEditorStore )
Expand All @@ -57,9 +63,12 @@ export function usePaddingAppender() {
insertDefaultBlock();
}
}
node.addEventListener( 'mousedown', onMouseDown );
const { ownerDocument } = node;
// Adds the listener on the document so that in the iframed editor clicks below the
// padding can be handled as they too should be treated as intent to append.
ownerDocument.addEventListener( 'mousedown', onMouseDown );
return () => {
node.removeEventListener( 'mousedown', onMouseDown );
ownerDocument.removeEventListener( 'mousedown', onMouseDown );
};
},
[ registry ]
Expand Down

0 comments on commit bbf2aad

Please sign in to comment.