From 2803307404b88554be87d37786b49b86502d60aa Mon Sep 17 00:00:00 2001 From: Jorge Costa Date: Fri, 7 Jul 2023 11:59:45 +0100 Subject: [PATCH 1/2] Fix: Remove link action of Link UI for draft pages created from Nav block does not correctly remove link. --- packages/block-editor/src/components/link-control/index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/block-editor/src/components/link-control/index.js b/packages/block-editor/src/components/link-control/index.js index 41455c4ecf9704..8900c6c68086d9 100644 --- a/packages/block-editor/src/components/link-control/index.js +++ b/packages/block-editor/src/components/link-control/index.js @@ -374,7 +374,10 @@ function LinkControl( { onEditClick={ () => setIsEditingLink( true ) } hasRichPreviews={ hasRichPreviews } hasUnlinkControl={ shownUnlinkControl } - onRemove={ onRemove } + onRemove={ () => { + onRemove(); + setIsEditingLink( true ); + } } /> ) } From 7f34dc7331374932e0fc9e009eee3f294510a6bf Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Thu, 13 Jul 2023 14:13:35 +0100 Subject: [PATCH 2/2] Add test coverage --- .../src/components/link-control/test/index.js | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/packages/block-editor/src/components/link-control/test/index.js b/packages/block-editor/src/components/link-control/test/index.js index 82bb82a0cfc51d..d861938c878735 100644 --- a/packages/block-editor/src/components/link-control/test/index.js +++ b/packages/block-editor/src/components/link-control/test/index.js @@ -405,6 +405,32 @@ describe( 'Basic rendering', () => { expect( mockOnRemove ).toHaveBeenCalled(); } ); + + it( 'should revert to "editing" mode when onRemove is triggered', async () => { + const user = userEvent.setup(); + const mockOnRemove = jest.fn(); + + render( + + ); + + const unLinkButton = screen.queryByRole( 'button', { + name: 'Unlink', + } ); + expect( unLinkButton ).toBeVisible(); + + await user.click( unLinkButton ); + + expect( mockOnRemove ).toHaveBeenCalled(); + + // Should revert back to editing mode. + expect( + screen.getByRole( 'combobox', { name: 'Link' } ) + ).toBeVisible(); + } ); } ); } );