From 29177dc17ecdb6ea8dd4770e28e5087e033e4358 Mon Sep 17 00:00:00 2001 From: Dave Smith Date: Fri, 30 Jul 2021 09:52:03 +0100 Subject: [PATCH] Unable Unlink UI to allow users to remove existing links --- .../block-library/src/navigation-link/edit.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/packages/block-library/src/navigation-link/edit.js b/packages/block-library/src/navigation-link/edit.js index f390210bf19330..e22f9b0d0f28e4 100644 --- a/packages/block-library/src/navigation-link/edit.js +++ b/packages/block-library/src/navigation-link/edit.js @@ -419,6 +419,23 @@ export default function NavigationLinkEdit( { selection.addRange( range ); } + /** + * Removes the current link if set. + */ + function removeLink() { + // Reset all attributes that comprise the link. + setAttributes( { + url: '', + label: '', + id: '', + kind: '', + type: '', + } ); + + // Close the link editing UI. + setIsLinkOpen( false ); + } + let userCanCreate = false; if ( ! type || type === 'page' ) { userCanCreate = userCanCreatePages; @@ -690,6 +707,7 @@ export default function NavigationLinkEdit( { attributes ) } + onRemove={ removeLink } /> ) }