From 23f812f8d5468978d556a090d11b653aadcddd15 Mon Sep 17 00:00:00 2001 From: ramonjd Date: Mon, 18 Oct 2021 13:18:46 +1100 Subject: [PATCH] The `href` attribute triggers the browser's native HTML drag operations. When the link is dragged, the element's outerHTML is set in DataTransfer object as text/html. We need to clear any HTML drag data to prevent `pasteHandler` from calling inside `useOnBlockDrop`. --- .../components/list-view/block-select-button.js | 15 ++++++++++----- .../various/block-hierarchy-navigation.test.js | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/packages/block-editor/src/components/list-view/block-select-button.js b/packages/block-editor/src/components/list-view/block-select-button.js index a3fb99582edecc..303c1ddc4a70f0 100644 --- a/packages/block-editor/src/components/list-view/block-select-button.js +++ b/packages/block-editor/src/components/list-view/block-select-button.js @@ -46,9 +46,14 @@ function ListViewBlockSelectButton( siblingBlockCount, level ); - const onClickHandler = ( event ) => { - onClick(); - event.preventDefault(); + + // The `href` attribute triggers the browser's native HTML drag operations. + // When the link is dragged, the element's outerHTML is set in DataTransfer object as text/html. + // We need to clear any HTML drag data to prevent `pasteHandler` from firing + // inside the `useOnBlockDrop` hook. + const onDragStartHandler = ( event ) => { + event.dataTransfer.clearData(); + onDragStart( event ); }; return ( @@ -58,12 +63,12 @@ function ListViewBlockSelectButton( 'block-editor-list-view-block-select-button', className ) } - onClick={ onClickHandler } + onClick={ onClick } aria-describedby={ descriptionId } ref={ ref } tabIndex={ tabIndex } onFocus={ onFocus } - onDragStart={ onDragStart } + onDragStart={ onDragStartHandler } onDragEnd={ onDragEnd } draggable={ draggable } href={ `#block-${ clientId }` } diff --git a/packages/e2e-tests/specs/editor/various/block-hierarchy-navigation.test.js b/packages/e2e-tests/specs/editor/various/block-hierarchy-navigation.test.js index fd4de7ba31d320..69611a0eebfd9d 100644 --- a/packages/e2e-tests/specs/editor/various/block-hierarchy-navigation.test.js +++ b/packages/e2e-tests/specs/editor/various/block-hierarchy-navigation.test.js @@ -155,7 +155,7 @@ describe( 'Navigating the block hierarchy', () => { // Return to first block. await openListViewSidebar(); await page.keyboard.press( 'ArrowUp' ); - await page.keyboard.press( 'Space' ); + await page.keyboard.press( 'Enter' ); // Replace its content. await pressKeyWithModifier( 'primary', 'a' );