Skip to content

Commit

Permalink
Don't show Link preview when no selection (#58771)
Browse files Browse the repository at this point in the history
* close link UI if no text selection after link is added

* always remove the edit UI, and focus the current edited content, after the 1st render with no active edit

Co-authored-by: draganescu <andraganescu@git.wordpress.org>
Co-authored-by: getdave <get_dave@git.wordpress.org>
Co-authored-by: scruffian <scruffian@git.wordpress.org>
Co-authored-by: richtabor <richtabor@git.wordpress.org>
Co-authored-by: jeryj <jeryj@git.wordpress.org>
  • Loading branch information
6 people authored Feb 9, 2024
1 parent 6b789f2 commit 260bde6
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/format-library/src/link/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ function Edit( {
return;
}

// Close the Link popover if there is no active selection
// after the link was added - this can happen if the user
// adds a link without any text selected.
// We assume that if there is no active selection after
// link insertion there are no active formats.
if ( ! value.activeFormats ) {
editableContentElement.focus();
setAddingLink( false );
return;
}

function handleClick( 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
Expand All @@ -67,7 +78,7 @@ function Edit( {
return () => {
editableContentElement.removeEventListener( 'click', handleClick );
};
}, [ contentRef, isActive ] );
}, [ contentRef, isActive, addingLink, value ] );

function addLink( target ) {
const text = getTextContent( slice( value ) );
Expand Down

0 comments on commit 260bde6

Please sign in to comment.