Skip to content

Commit

Permalink
Link Format: Don't return focus on the selected text 'onFocusOutside' (
Browse files Browse the repository at this point in the history
…#51684)

* Link Format: Don't return focus on the selected text 'onFocusOutside'
* Update e2e tests
  • Loading branch information
Mamaduka authored Jun 20, 2023
1 parent 88aa941 commit 20020aa
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
4 changes: 3 additions & 1 deletion packages/e2e-tests/specs/editor/various/links.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Expand Down
6 changes: 4 additions & 2 deletions packages/format-library/src/link/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@ function Edit( {
}
}

function stopAddingLink() {
function stopAddingLink( returnFocus = true ) {
setAddingLink( false );
onFocus();
if ( returnFocus ) {
onFocus();
}
}

function onRemoveFormat() {
Expand Down
1 change: 1 addition & 0 deletions packages/format-library/src/link/inline.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ function InlineLinkUI( {
anchor={ popoverAnchor }
focusOnMount={ focusOnMount.current }
onClose={ stopAddingLink }
onFocusOutside={ () => stopAddingLink( false ) }
placement="bottom"
shift
>
Expand Down

1 comment on commit 20020aa

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 20020aa.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5321541732
📝 Reported issues:

Please sign in to comment.