diff --git a/packages/block-editor/src/components/block-selection-clearer/index.js b/packages/block-editor/src/components/block-selection-clearer/index.js index 8501d3179eacd..3806dae48d29d 100644 --- a/packages/block-editor/src/components/block-selection-clearer/index.js +++ b/packages/block-editor/src/components/block-selection-clearer/index.js @@ -19,14 +19,19 @@ export function useBlockSelectionClearer( ref ) { return; } - function onFocus() { + function onMouseDown( event ) { + // Only handle clicks on the canvas, not the content. + if ( event.target.closest( '.wp-block' ) ) { + return; + } + clearSelectedBlock(); } - ref.current.addEventListener( 'focus', onFocus ); + ref.current.addEventListener( 'mousedown', onMouseDown ); return () => { - ref.current.removeEventListener( 'focus', onFocus ); + ref.current.removeEventListener( 'mousedown', onMouseDown ); }; }, [ hasSelection, clearSelectedBlock ] ); } @@ -34,5 +39,5 @@ export function useBlockSelectionClearer( ref ) { export default function BlockSelectionClearer( props ) { const ref = useRef(); useBlockSelectionClearer( ref ); - return
; + return ; } diff --git a/packages/e2e-tests/specs/editor/various/keyboard-navigable-blocks.test.js b/packages/e2e-tests/specs/editor/various/keyboard-navigable-blocks.test.js index 730af28bdb10a..2b092c9b46690 100644 --- a/packages/e2e-tests/specs/editor/various/keyboard-navigable-blocks.test.js +++ b/packages/e2e-tests/specs/editor/various/keyboard-navigable-blocks.test.js @@ -108,10 +108,10 @@ describe( 'Order of block keyboard navigation', () => { await page.keyboard.type( paragraphBlock ); } - // Clear the selected block and put focus in front of the block list. - await page.evaluate( () => { - document.querySelector( '.editor-styles-wrapper' ).focus(); - } ); + // Clear the selected block. + const paragraph = await page.$( '[data-type="core/paragraph"]' ); + const box = await paragraph.boundingBox(); + await page.mouse.click( box.x - 1, box.y ); await page.keyboard.press( 'Tab' ); await expect( @@ -143,9 +143,13 @@ describe( 'Order of block keyboard navigation', () => { await page.keyboard.type( paragraphBlock ); } - // Clear the selected block and put focus behind the block list. + // Clear the selected block. + const paragraph = await page.$( '[data-type="core/paragraph"]' ); + const box = await paragraph.boundingBox(); + await page.mouse.click( box.x - 1, box.y ); + + // Put focus behind the block list. await page.evaluate( () => { - document.querySelector( '.editor-styles-wrapper' ).focus(); document .querySelector( '.interface-interface-skeleton__sidebar' ) .focus(); diff --git a/packages/edit-post/src/components/visual-editor/index.js b/packages/edit-post/src/components/visual-editor/index.js index cf87daa479eda..0f6d4b73d94f3 100644 --- a/packages/edit-post/src/components/visual-editor/index.js +++ b/packages/edit-post/src/components/visual-editor/index.js @@ -64,7 +64,6 @@ export default function VisualEditor() {