From 20020aa9194fd3d1ba8f4037268237552cc1353f Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Tue, 20 Jun 2023 14:38:13 +0400 Subject: [PATCH] Link Format: Don't return focus on the selected text 'onFocusOutside' (#51684) * Link Format: Don't return focus on the selected text 'onFocusOutside' * Update e2e tests --- packages/e2e-tests/specs/editor/various/links.test.js | 4 +++- packages/format-library/src/link/index.js | 6 ++++-- packages/format-library/src/link/inline.js | 1 + 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/e2e-tests/specs/editor/various/links.test.js b/packages/e2e-tests/specs/editor/various/links.test.js index 79f2ada80e61f..3be80f786fbc2 100644 --- a/packages/e2e-tests/specs/editor/various/links.test.js +++ b/packages/e2e-tests/specs/editor/various/links.test.js @@ -669,7 +669,9 @@ describe( 'Links', () => { await page.waitForXPath( `//label[text()='Open in new tab']` ); // Move focus back to RichText for the underlying link. - await pressKeyTimes( 'Tab', 4 ); + await pressKeyWithModifier( 'shift', 'Tab' ); + await pressKeyWithModifier( 'shift', 'Tab' ); + await pressKeyWithModifier( 'shift', 'Tab' ); // Make a selection within the RichText. await pressKeyWithModifier( 'shift', 'ArrowRight' ); diff --git a/packages/format-library/src/link/index.js b/packages/format-library/src/link/index.js index 40f1322fcf1c4..c203017feda0f 100644 --- a/packages/format-library/src/link/index.js +++ b/packages/format-library/src/link/index.js @@ -60,9 +60,11 @@ function Edit( { } } - function stopAddingLink() { + function stopAddingLink( returnFocus = true ) { setAddingLink( false ); - onFocus(); + if ( returnFocus ) { + onFocus(); + } } function onRemoveFormat() { diff --git a/packages/format-library/src/link/inline.js b/packages/format-library/src/link/inline.js index 67790c36937f2..064ed81943de1 100644 --- a/packages/format-library/src/link/inline.js +++ b/packages/format-library/src/link/inline.js @@ -255,6 +255,7 @@ function InlineLinkUI( { anchor={ popoverAnchor } focusOnMount={ focusOnMount.current } onClose={ stopAddingLink } + onFocusOutside={ () => stopAddingLink( false ) } placement="bottom" shift >