From 449dcf3b400f7c5ea90035ceeb5aa560d2ccf82c Mon Sep 17 00:00:00 2001 From: Andrei Draganescu Date: Fri, 26 Jan 2024 16:47:08 +0200 Subject: [PATCH 1/2] set the adding link to false on mouse down to allow the paragraph to capture focus --- packages/format-library/src/link/index.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/packages/format-library/src/link/index.js b/packages/format-library/src/link/index.js index 61b6f974cdce3..2409c7a02b80e 100644 --- a/packages/format-library/src/link/index.js +++ b/packages/format-library/src/link/index.js @@ -62,12 +62,27 @@ function Edit( { setAddingLink( true ); } - editableContentElement.addEventListener( 'click', handleClick ); + const removeAddingLink = () => { + setAddingLink( false ); + }; + + editableContentElement.addEventListener( + 'mousedown', + removeAddingLink + ); + editableContentElement.addEventListener( 'mouseup', handleClick ); return () => { - editableContentElement.removeEventListener( 'click', handleClick ); + editableContentElement.removeEventListener( + 'mousedown', + removeAddingLink + ); + editableContentElement.removeEventListener( + 'mouseup', + handleClick + ); }; - }, [ contentRef, isActive ] ); + }, [ contentRef, isActive, onFocus, addingLink ] ); function addLink( target ) { const text = getTextContent( slice( value ) ); From 4ca9bea88b0dbf4015b9d2787e23245b902a68d7 Mon Sep 17 00:00:00 2001 From: Andrei Draganescu Date: Fri, 26 Jan 2024 16:55:11 +0200 Subject: [PATCH 2/2] remove unused deps, better function naming --- packages/format-library/src/link/index.js | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/packages/format-library/src/link/index.js b/packages/format-library/src/link/index.js index 2409c7a02b80e..bde0b14c5d962 100644 --- a/packages/format-library/src/link/index.js +++ b/packages/format-library/src/link/index.js @@ -48,7 +48,7 @@ function Edit( { return; } - function handleClick( event ) { + function handleMouseUp( event ) { // There is a situation whereby there is an existing link in the rich text // and the user clicks on the leftmost edge of that link and fails to activate // the link format, but the click event still fires on the `` element. @@ -62,27 +62,24 @@ function Edit( { setAddingLink( true ); } - const removeAddingLink = () => { + const handleMouseDown = () => { setAddingLink( false ); }; - editableContentElement.addEventListener( - 'mousedown', - removeAddingLink - ); - editableContentElement.addEventListener( 'mouseup', handleClick ); + editableContentElement.addEventListener( 'mousedown', handleMouseDown ); + editableContentElement.addEventListener( 'mouseup', handleMouseUp ); return () => { editableContentElement.removeEventListener( 'mousedown', - removeAddingLink + handleMouseDown ); editableContentElement.removeEventListener( 'mouseup', - handleClick + handleMouseUp ); }; - }, [ contentRef, isActive, onFocus, addingLink ] ); + }, [ contentRef, isActive ] ); function addLink( target ) { const text = getTextContent( slice( value ) );