Skip to content

Commit

Permalink
The href attribute triggers the browser's native HTML drag operations.
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
ramonjd committed Oct 18, 2021
1 parent b64b71d commit 23f812f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Expand Up @@ -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 (
Expand All @@ -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 }` }
Expand Down
Expand Up @@ -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' );
Expand Down

0 comments on commit 23f812f

Please sign in to comment.