From 3ae5c55ebfd8c54777ab82789883c4ed45f0fef0 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Fri, 6 Jan 2023 09:48:51 +0000 Subject: [PATCH 01/16] Add initial Apply and Cancel buttons and refactor styles --- .../src/components/link-control/index.js | 34 ++++++++++++------- .../src/components/link-control/style.scss | 19 +++-------- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/packages/block-editor/src/components/link-control/index.js b/packages/block-editor/src/components/link-control/index.js index 2d0f0078a9e762..387f35711d2096 100644 --- a/packages/block-editor/src/components/link-control/index.js +++ b/packages/block-editor/src/components/link-control/index.js @@ -6,8 +6,13 @@ import classnames from 'classnames'; /** * WordPress dependencies */ -import { Button, Spinner, Notice, TextControl } from '@wordpress/components'; -import { keyboardReturn } from '@wordpress/icons'; +import { + Button, + ButtonGroup, + Spinner, + Notice, + TextControl, +} from '@wordpress/components'; import { __ } from '@wordpress/i18n'; import { useRef, useState, useEffect } from '@wordpress/element'; import { focus } from '@wordpress/dom'; @@ -299,17 +304,7 @@ function LinkControl( { createSuggestionButtonText } useLabel={ showTextControl } - > -
-
- + /> { errorMessage && ( ) } + + + + ) } diff --git a/packages/block-editor/src/components/link-control/style.scss b/packages/block-editor/src/components/link-control/style.scss index a34d050353f949..e8ac6c3461c3a1 100644 --- a/packages/block-editor/src/components/link-control/style.scss +++ b/packages/block-editor/src/components/link-control/style.scss @@ -77,20 +77,11 @@ $preview-image-height: 140px; } .block-editor-link-control__search-actions { - position: absolute; - /* - * Actions must be positioned on top of URLInput, since the input will grow - * when suggestions are rendered. - * - * Compensate for: - * - Border (1px) - * - Vertically, for the difference in height between the input (40px) and - * the icon buttons. - * - Horizontally, pad to the minimum of: default input padding, or the - * equivalent of the vertical padding. - */ - top: 1px + ( ( 40px - $button-size ) * 0.5 ); - right: $grid-unit-20 + 1px + min($grid-unit-10, ( 40px - $button-size ) * 0.5); + display: flex; + flex-direction: row-reverse; // put "Cancel" on the left but retain DOM order. + justify-content: flex-start; + margin: $grid-unit-20; // allow margin collapse for vertical spacing. + gap: $grid-unit-10; } .components-button .block-editor-link-control__search-submit .has-icon { From 0fe01994041f87ff5e7dadde41596e68b5beb2b0 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Fri, 6 Jan 2023 10:02:42 +0000 Subject: [PATCH 02/16] Add improved cancellation logic --- .../src/components/link-control/index.js | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/packages/block-editor/src/components/link-control/index.js b/packages/block-editor/src/components/link-control/index.js index 387f35711d2096..2606e569ae6e9a 100644 --- a/packages/block-editor/src/components/link-control/index.js +++ b/packages/block-editor/src/components/link-control/index.js @@ -117,7 +117,7 @@ function LinkControl( { value, settings = DEFAULT_LINK_SETTINGS, onChange = noop, - onRemove, + onRemove = noop, noDirectEntry = false, showSuggestions = true, showInitialSuggestions, @@ -195,6 +195,8 @@ function LinkControl( { isEndingEditWithFocus.current = false; }, [ isEditingLink, isCreatingPage ] ); + const hasLinkValue = value?.url?.trim()?.length > 0; + /** * Cancels editing state and marks that focus may need to be restored after * the next render, if focus was within the wrapper when editing finished. @@ -240,6 +242,25 @@ function LinkControl( { } }; + const resetInternalValues = () => { + setInternalUrlInputValue( value?.url ); + setInternalTextInputValue( value?.title ); + }; + + const handleCancel = ( event ) => { + event.preventDefault(); + + // If there is an existing link then revert to the existing + // link and exit editing mode. Otherwise remove the link. + if ( hasLinkValue ) { + // Ensure that any unsubmitted input changes are reset. + resetInternalValues(); + stopEditing(); + } else { + onRemove(); + } + }; + const currentUrlInputValue = propInputValue || internalUrlInputValue; const currentInputIsEmpty = ! currentUrlInputValue?.trim()?.length; @@ -252,7 +273,7 @@ function LinkControl( { // Only show text control once a URL value has been committed // and it isn't just empty whitespace. // See https://github.com/WordPress/gutenberg/pull/33849/#issuecomment-932194927. - const showTextControl = value?.url?.trim()?.length > 0 && hasTextControl; + const showTextControl = hasLinkValue && hasTextControl; return (
{ __( 'Apply' ) } - From 1ec84b191ba6bc262282faa3eb30ac243e0f8d90 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Fri, 6 Jan 2023 10:12:51 +0000 Subject: [PATCH 03/16] Update tests --- .../block-editor/src/components/link-control/index.js | 4 ++-- .../src/components/link-control/test/index.js | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/block-editor/src/components/link-control/index.js b/packages/block-editor/src/components/link-control/index.js index 2606e569ae6e9a..e64900015a1c8c 100644 --- a/packages/block-editor/src/components/link-control/index.js +++ b/packages/block-editor/src/components/link-control/index.js @@ -117,7 +117,7 @@ function LinkControl( { value, settings = DEFAULT_LINK_SETTINGS, onChange = noop, - onRemove = noop, + onRemove, noDirectEntry = false, showSuggestions = true, showInitialSuggestions, @@ -257,7 +257,7 @@ function LinkControl( { resetInternalValues(); stopEditing(); } else { - onRemove(); + onRemove?.(); } }; 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 86eae7289f4f61..67e49fbd283448 100644 --- a/packages/block-editor/src/components/link-control/test/index.js +++ b/packages/block-editor/src/components/link-control/test/index.js @@ -537,7 +537,7 @@ describe( 'Manual link entry', () => { } ); let submitButton = screen.getByRole( 'button', { - name: 'Submit', + name: 'Apply', } ); expect( submitButton ).toBeDisabled(); @@ -555,7 +555,7 @@ describe( 'Manual link entry', () => { await user.keyboard( '[Enter]' ); submitButton = screen.getByRole( 'button', { - name: 'Submit', + name: 'Apply', } ); // Verify the UI hasn't allowed submission. @@ -578,7 +578,7 @@ describe( 'Manual link entry', () => { } ); let submitButton = screen.queryByRole( 'button', { - name: 'Submit', + name: 'Apply', } ); expect( submitButton ).toBeDisabled(); @@ -597,7 +597,7 @@ describe( 'Manual link entry', () => { await user.click( submitButton ); submitButton = screen.queryByRole( 'button', { - name: 'Submit', + name: 'Apply', } ); // Verify the UI hasn't allowed submission. @@ -1859,7 +1859,7 @@ describe( 'Controlling link title text', () => { expect( textInput ).toHaveValue( textValue ); const submitButton = screen.queryByRole( 'button', { - name: 'Submit', + name: 'Apply', } ); await user.click( submitButton ); From b3fda12859cfa74c27f128ddc3743f3627ffe6c5 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Fri, 6 Jan 2023 10:47:18 +0000 Subject: [PATCH 04/16] Add unit tests for Cancellation --- .../src/components/link-control/index.js | 9 +- .../src/components/link-control/test/index.js | 109 ++++++++++++++++++ 2 files changed, 114 insertions(+), 4 deletions(-) diff --git a/packages/block-editor/src/components/link-control/index.js b/packages/block-editor/src/components/link-control/index.js index e64900015a1c8c..cea4edc4263638 100644 --- a/packages/block-editor/src/components/link-control/index.js +++ b/packages/block-editor/src/components/link-control/index.js @@ -250,13 +250,14 @@ function LinkControl( { const handleCancel = ( event ) => { event.preventDefault(); - // If there is an existing link then revert to the existing - // link and exit editing mode. Otherwise remove the link. + // Ensure that any unsubmitted input changes are reset. + resetInternalValues(); + if ( hasLinkValue ) { - // Ensure that any unsubmitted input changes are reset. - resetInternalValues(); + // If there is a link then exist editing mode and show preview. stopEditing(); } else { + // If there is no link value, then remove the link entirely. onRemove?.(); } }; 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 67e49fbd283448..3c21de51c8721f 100644 --- a/packages/block-editor/src/components/link-control/test/index.js +++ b/packages/block-editor/src/components/link-control/test/index.js @@ -608,6 +608,115 @@ describe( 'Manual link entry', () => { ); } ); + describe( 'Handling cancellation', () => { + it( 'should allow cancellation of the link creation process and reset any entered values', async () => { + const user = userEvent.setup(); + const mockOnRemove = jest.fn(); + + render( ); + + // Search Input UI. + const searchInput = screen.getByRole( 'combobox', { + name: 'URL', + } ); + + const cancelButton = screen.queryByRole( 'button', { + name: 'Cancel', + } ); + + expect( cancelButton ).toBeEnabled(); + expect( cancelButton ).toBeVisible(); + + // Simulate adding a link for a term. + await user.type( searchInput, 'https://www.wordpress.org' ); + + // Attempt to submit the empty search value in the input. + await user.click( cancelButton ); + + // Verify the consumer can handle the cancellation. + expect( mockOnRemove ).toHaveBeenCalled(); + + expect( searchInput ).toHaveValue( '' ); + } ); + + it( 'should allow cancellation of the link editing process and reset any entered values', async () => { + const user = userEvent.setup(); + const initialLink = fauxEntitySuggestions[ 0 ]; + + const LinkControlConsumer = () => { + const [ link, setLink ] = useState( initialLink ); + + return ( + { + setLink( suggestion ); + } } + hasTextControl + /> + ); + }; + + render( ); + + let linkPreview = screen.getByLabelText( 'Currently selected' ); + + expect( linkPreview ).toBeInTheDocument(); + + // Click the "Edit" button to trigger into the editing mode. + let editButton = screen.queryByRole( 'button', { + name: 'Edit', + } ); + + await user.click( editButton ); + + let searchInput = screen.getByRole( 'combobox', { + name: 'URL', + } ); + + let textInput = screen.getByRole( 'textbox', { + name: 'Text', + } ); + + // Make a change to the search input. + await user.type( searchInput, 'This URL value was changed!' ); + + // Make a change to the text input. + await user.type( textInput, 'This text value was changed!' ); + + const cancelButton = screen.queryByRole( 'button', { + name: 'Cancel', + } ); + + // Cancel the editing process. + await user.click( cancelButton ); + + linkPreview = screen.getByLabelText( 'Currently selected' ); + + expect( linkPreview ).toBeInTheDocument(); + + // Re-query the edit button as it's been replaced. + editButton = screen.queryByRole( 'button', { + name: 'Edit', + } ); + + await user.click( editButton ); + + // Re-query the inputs as they have been replaced. + searchInput = screen.getByRole( 'combobox', { + name: 'URL', + } ); + + textInput = screen.getByRole( 'textbox', { + name: 'Text', + } ); + + // Expect to see the original link values and **not** the changed values. + expect( searchInput ).toHaveValue( initialLink.url ); + expect( textInput ).toHaveValue( initialLink.text ); + } ); + } ); + describe( 'Alternative link protocols and formats', () => { it.each( [ [ 'mailto:example123456@wordpress.org', 'mailto' ], From dd2177565b606dde4410650d16cac407d64f9831 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Fri, 6 Jan 2023 11:12:31 +0000 Subject: [PATCH 05/16] Fix Media flow tests --- .../src/components/media-replace-flow/test/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-editor/src/components/media-replace-flow/test/index.js b/packages/block-editor/src/components/media-replace-flow/test/index.js index 2d3a9f64fc1983..9d1aef6df76203 100644 --- a/packages/block-editor/src/components/media-replace-flow/test/index.js +++ b/packages/block-editor/src/components/media-replace-flow/test/index.js @@ -137,7 +137,7 @@ describe( 'General media replace flow', () => { await user.click( screen.getByRole( 'button', { - name: 'Submit', + name: 'Apply', } ) ); From ff3f638ba10421bc0cef7c6ddcb2d4bef507dd9d Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Wed, 18 Jan 2023 06:44:54 +0000 Subject: [PATCH 06/16] Add ability to supply callback to be triggered on cancelling --- .../src/components/link-control/index.js | 3 +++ .../src/components/link-control/test/index.js | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/packages/block-editor/src/components/link-control/index.js b/packages/block-editor/src/components/link-control/index.js index cea4edc4263638..52b57c8a5774c7 100644 --- a/packages/block-editor/src/components/link-control/index.js +++ b/packages/block-editor/src/components/link-control/index.js @@ -118,6 +118,7 @@ function LinkControl( { settings = DEFAULT_LINK_SETTINGS, onChange = noop, onRemove, + onCancel, noDirectEntry = false, showSuggestions = true, showInitialSuggestions, @@ -260,6 +261,8 @@ function LinkControl( { // If there is no link value, then remove the link entirely. onRemove?.(); } + + onCancel?.(); }; const currentUrlInputValue = propInputValue || internalUrlInputValue; 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 3c21de51c8721f..009e67e02f2465 100644 --- a/packages/block-editor/src/components/link-control/test/index.js +++ b/packages/block-editor/src/components/link-control/test/index.js @@ -715,6 +715,22 @@ describe( 'Manual link entry', () => { expect( searchInput ).toHaveValue( initialLink.url ); expect( textInput ).toHaveValue( initialLink.text ); } ); + + it( 'should call onCancel callback when cancelling if provided', async () => { + const user = userEvent.setup(); + const mockOnCancel = jest.fn(); + + render( ); + + const cancelButton = screen.queryByRole( 'button', { + name: 'Cancel', + } ); + + await user.click( cancelButton ); + + // Verify the consumer can handle the cancellation. + expect( mockOnCancel ).toHaveBeenCalled(); + } ); } ); describe( 'Alternative link protocols and formats', () => { From 496baac7a1d0b74ba41ff6adf65b9edf82726e05 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Wed, 18 Jan 2023 06:51:44 +0000 Subject: [PATCH 07/16] Fix input padding and spinner positioning --- .../block-editor/src/components/link-control/style.scss | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/packages/block-editor/src/components/link-control/style.scss b/packages/block-editor/src/components/link-control/style.scss index e8ac6c3461c3a1..51682a45c7c20b 100644 --- a/packages/block-editor/src/components/link-control/style.scss +++ b/packages/block-editor/src/components/link-control/style.scss @@ -64,7 +64,6 @@ $preview-image-height: 140px; width: calc(100% - #{$grid-unit-20 * 2}); display: block; padding: 11px $grid-unit-20; - padding-right: ( $button-size * $block-editor-link-control-number-of-actions ); // width of reset and submit buttons margin: 0; position: relative; border: 1px solid $gray-300; @@ -470,14 +469,8 @@ $preview-image-height: 140px; position: absolute; left: auto; bottom: auto; - /* - * Position spinner to the left of the actions. - * - * Compensate for: - * - Input padding right ($button-size) - */ top: calc(50% - #{$spinner-size} / 2); - right: $button-size; + right: $grid-unit-20; } } From 65a67499eeb1e9b0336048f00f98bbbacd9d1ad4 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Wed, 18 Jan 2023 07:51:19 +0000 Subject: [PATCH 08/16] Add test coverage to check optional onCancel is not called if undefined --- .../block-editor/src/components/link-control/test/index.js | 4 ++++ 1 file changed, 4 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 009e67e02f2465..bf48d93305fca6 100644 --- a/packages/block-editor/src/components/link-control/test/index.js +++ b/packages/block-editor/src/components/link-control/test/index.js @@ -612,6 +612,7 @@ describe( 'Manual link entry', () => { it( 'should allow cancellation of the link creation process and reset any entered values', async () => { const user = userEvent.setup(); const mockOnRemove = jest.fn(); + const mockOnCancel = jest.fn(); render( ); @@ -636,6 +637,9 @@ describe( 'Manual link entry', () => { // Verify the consumer can handle the cancellation. expect( mockOnRemove ).toHaveBeenCalled(); + // Ensure optional callback is not called. + expect( mockOnCancel ).not.toHaveBeenCalled(); + expect( searchInput ).toHaveValue( '' ); } ); From 760851e7427dfd8f8efcb5bd5acca5f7b2e3be98 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Wed, 18 Jan 2023 08:00:27 +0000 Subject: [PATCH 09/16] Update button text string in e2e test --- test/e2e/specs/editor/blocks/image.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/specs/editor/blocks/image.spec.js b/test/e2e/specs/editor/blocks/image.spec.js index 209511d2d1cfa5..26db3cb0d42549 100644 --- a/test/e2e/specs/editor/blocks/image.spec.js +++ b/test/e2e/specs/editor/blocks/image.spec.js @@ -486,7 +486,7 @@ test.describe( 'Image', () => { await page.click( 'role=button[name="Edit"i]' ); // Replace the url. await page.fill( 'role=combobox[name="URL"i]', imageUrl ); - await page.click( 'role=button[name="Submit"i]' ); + await page.click( 'role=button[name="Apply"i]' ); const regex = new RegExp( ` From e365cb4bee08abc7375d4a58c5d741cdddc5607f Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Wed, 18 Jan 2023 08:23:54 +0000 Subject: [PATCH 10/16] Fix tab stops in test --- packages/e2e-tests/specs/editor/various/links.test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/e2e-tests/specs/editor/various/links.test.js b/packages/e2e-tests/specs/editor/various/links.test.js index c82e0c78c1dc96..0438627a246ca0 100644 --- a/packages/e2e-tests/specs/editor/various/links.test.js +++ b/packages/e2e-tests/specs/editor/various/links.test.js @@ -528,6 +528,7 @@ describe( 'Links', () => { // Navigate to and toggle the "Open in new tab" checkbox. await page.keyboard.press( 'Tab' ); await page.keyboard.press( 'Tab' ); + await page.keyboard.press( 'Tab' ); await page.keyboard.press( 'Space' ); // Confirm that focus was not prematurely returned to the paragraph on From afec199c7758a1ded28a7bfcf081e08b041d8bb7 Mon Sep 17 00:00:00 2001 From: Ben Dwyer Date: Wed, 18 Jan 2023 17:18:18 +0800 Subject: [PATCH 11/16] Don't propgate the click back to the parent blocks --- packages/block-editor/src/components/link-control/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/block-editor/src/components/link-control/index.js b/packages/block-editor/src/components/link-control/index.js index 52b57c8a5774c7..7ffa6b327029a6 100644 --- a/packages/block-editor/src/components/link-control/index.js +++ b/packages/block-editor/src/components/link-control/index.js @@ -250,6 +250,7 @@ function LinkControl( { const handleCancel = ( event ) => { event.preventDefault(); + event.stopPropagation(); // Ensure that any unsubmitted input changes are reset. resetInternalValues(); From 0ec87aa5d035d10e26e6b51e1776a64d7b4b389e Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Wed, 18 Jan 2023 09:20:02 +0000 Subject: [PATCH 12/16] Fix more tab stops in tests --- packages/e2e-tests/specs/editor/various/links.test.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/e2e-tests/specs/editor/various/links.test.js b/packages/e2e-tests/specs/editor/various/links.test.js index 0438627a246ca0..6db3a6af88a76c 100644 --- a/packages/e2e-tests/specs/editor/various/links.test.js +++ b/packages/e2e-tests/specs/editor/various/links.test.js @@ -122,6 +122,7 @@ describe( 'Links', () => { // Navigate to and toggle the "Open in new tab" checkbox. await page.keyboard.press( 'Tab' ); await page.keyboard.press( 'Tab' ); + await page.keyboard.press( 'Tab' ); await page.keyboard.press( 'Space' ); // Toggle should still have focus and be checked. @@ -135,6 +136,7 @@ describe( 'Links', () => { // Tab back to the Submit and apply the link. await pressKeyWithModifier( 'shift', 'Tab' ); + await pressKeyWithModifier( 'shift', 'Tab' ); await page.keyboard.press( 'Enter' ); // The link should have been inserted. From 50feaff1b8bef6ef2edde0daff40f4416ec55f71 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Thu, 19 Jan 2023 01:22:23 +0000 Subject: [PATCH 13/16] Fix another test tab stops --- packages/e2e-tests/specs/editor/various/links.test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/e2e-tests/specs/editor/various/links.test.js b/packages/e2e-tests/specs/editor/various/links.test.js index 6db3a6af88a76c..44018bae3226ff 100644 --- a/packages/e2e-tests/specs/editor/various/links.test.js +++ b/packages/e2e-tests/specs/editor/various/links.test.js @@ -769,6 +769,7 @@ describe( 'Links', () => { await page.keyboard.press( 'Tab' ); await page.keyboard.press( 'Tab' ); await page.keyboard.press( 'Tab' ); + await page.keyboard.press( 'Tab' ); // Make a selection within the RichText. await pressKeyWithModifier( 'shift', 'ArrowRight' ); From c90077330987375e02049ea77ed64273b0db39de Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Thu, 19 Jan 2023 01:34:10 +0000 Subject: [PATCH 14/16] Fix snapshot missing open in new tab attributes --- .../specs/editor/various/__snapshots__/links.test.js.snap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/e2e-tests/specs/editor/various/__snapshots__/links.test.js.snap b/packages/e2e-tests/specs/editor/various/__snapshots__/links.test.js.snap index 330dfbbe142b08..6ba1f2c0148853 100644 --- a/packages/e2e-tests/specs/editor/various/__snapshots__/links.test.js.snap +++ b/packages/e2e-tests/specs/editor/various/__snapshots__/links.test.js.snap @@ -68,6 +68,6 @@ exports[`Links should contain a label when it should open in a new tab 1`] = ` exports[`Links should contain a label when it should open in a new tab 2`] = ` " -

This is WordPress

+

This is WordPress

" `; From 8cc0fd234ba0881b96baea8083513948d1e5acfc Mon Sep 17 00:00:00 2001 From: Ben Dwyer Date: Thu, 19 Jan 2023 10:47:37 +0800 Subject: [PATCH 15/16] reset the URL to undefined rather than an empty string so that the popover doesn't reopen --- packages/block-library/src/navigation-link/edit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-library/src/navigation-link/edit.js b/packages/block-library/src/navigation-link/edit.js index 87e9cc38afc7c8..853664487179dc 100644 --- a/packages/block-library/src/navigation-link/edit.js +++ b/packages/block-library/src/navigation-link/edit.js @@ -313,7 +313,7 @@ export default function NavigationLinkEdit( { function removeLink() { // Reset all attributes that comprise the link. setAttributes( { - url: '', + url: undefined, label: '', id: '', kind: '', From ee46cf2ae8d2b1753ac8c90ae33fcb5a984a4d8b Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Thu, 19 Jan 2023 11:20:52 +0800 Subject: [PATCH 16/16] =?UTF-8?q?Ensure=20correctly=20resetting=20all=20?= =?UTF-8?q?=E2=80=9Clink=E2=80=9D=20attributes=20to=20true=20default=20sta?= =?UTF-8?q?te?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/block-library/src/navigation-link/edit.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/block-library/src/navigation-link/edit.js b/packages/block-library/src/navigation-link/edit.js index 853664487179dc..47797fa0a9ffbc 100644 --- a/packages/block-library/src/navigation-link/edit.js +++ b/packages/block-library/src/navigation-link/edit.js @@ -312,12 +312,17 @@ export default function NavigationLinkEdit( { */ function removeLink() { // Reset all attributes that comprise the link. + // It is critical that all attributes are reset + // to their default values otherwise this may + // in advertently trigger side effects because + // the values will have "changed". setAttributes( { url: undefined, - label: '', - id: '', - kind: '', - type: '', + label: undefined, + id: undefined, + kind: undefined, + type: undefined, + opensInNewTab: false, } ); // Close the link editing UI.