Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add dedicated opt in prop for removing links
  • Loading branch information
getdave committed Jun 29, 2021
commit cd648452de723d085d0525458e680b8e87611811
29 changes: 16 additions & 13 deletions packages/block-editor/src/components/link-control/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { noop } from 'lodash';
import { noop, isFunction } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -106,6 +106,7 @@ function LinkControl( {
value,
settings,
onChange = noop,
onRemove,
noDirectEntry = false,
showSuggestions = true,
showInitialSuggestions,
Expand Down Expand Up @@ -266,18 +267,20 @@ function LinkControl( {
settings={ settings }
onChange={ onChange }
/>
{ value && ! isEditingLink && ! isCreatingPage && (
<Button
className="block-editor-link-control__unlink"
isDestructive
variant="link"
onClick={ () => {
onChange( null );
} }
>
{ __( 'Unlink' ) }
</Button>
) }
{ onRemove &&
isFunction( onRemove ) &&
value &&
! isEditingLink &&
! isCreatingPage && (
<Button
className="block-editor-link-control__unlink"
isDestructive
variant="link"
onClick={ onRemove }
>
{ __( 'Unlink' ) }
</Button>
) }
</div>
</div>
);
Expand Down
15 changes: 9 additions & 6 deletions packages/format-library/src/link/inline.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,16 @@ function InlineLinkUI( {
...nextLinkValue,
};

function removeLink() {
const newValue = removeFormat( value, 'core/link' );
onChange( newValue );
stopAddingLink();
speak( __( 'Link removed.' ), 'assertive' );
}

function onChangeLink( nextValue ) {
// null values trigger removal of link format.
if ( null === nextValue ) {
const newValue = removeFormat( value, 'core/link' );
onChange( newValue );
stopAddingLink();
speak( __( 'Link removed.' ), 'assertive' );
return;
return removeLink();
}

// Merge with values from state, both for the purpose of assigning the
Expand Down Expand Up @@ -149,6 +151,7 @@ function InlineLinkUI( {
<LinkControl
value={ linkValue }
onChange={ onChangeLink }
onRemove={ removeLink }
forceIsEditingLink={ addingLink }
hasRichPreviews
/>
Expand Down