Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix padding appender hook #66143

Merged
merged 2 commits into from
Oct 16, 2024
Merged
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
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 @@ -16,7 +16,13 @@ export function usePaddingAppender( enabled ) {
const effect = 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 @@ -31,7 +37,7 @@ export function usePaddingAppender( enabled ) {
return;
}

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

const blockOrder = registry
.select( blockEditorStore )
Expand All @@ -50,9 +56,12 @@ export function usePaddingAppender( enabled ) {
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
Loading