Skip to content

Commit

Permalink
Deactivate link in buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
ntsekouras committed Jun 25, 2020
1 parent d684f82 commit ccda6d9
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions packages/block-library/src/button/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
__experimentalLinkControl as LinkControl,
} from '@wordpress/block-editor';
import { rawShortcut, displayShortcut } from '@wordpress/keycodes';
import { link } from '@wordpress/icons';
import { link, linkOff } from '@wordpress/icons';
import { createBlock } from '@wordpress/blocks';

/**
Expand Down Expand Up @@ -70,13 +70,15 @@ function URLPicker( {
onToggleOpenInNewTab,
} ) {
const [ isURLPickerOpen, setIsURLPickerOpen ] = useState( false );
const urlIsSet = !! url;
const urlIsSetandSelected = urlIsSet && isSelected;
const openLinkControl = () => {
setIsURLPickerOpen( true );

// prevents default behaviour for event
return false;
};
const linkControl = isURLPickerOpen && (
const linkControl = ( isURLPickerOpen || urlIsSetandSelected ) && (
<Popover
position="bottom center"
onClose={ () => setIsURLPickerOpen( false ) }
Expand All @@ -101,13 +103,31 @@ function URLPicker( {
<>
<BlockControls>
<ToolbarGroup>
<ToolbarButton
name="link"
icon={ link }
title={ __( 'Link' ) }
shortcut={ displayShortcut.primary( 'k' ) }
onClick={ openLinkControl }
/>
{ ! urlIsSet && (
<ToolbarButton
name="link"
icon={ link }
title={ __( 'Link' ) }
shortcut={ displayShortcut.primary( 'k' ) }
onClick={ openLinkControl }
/>
) }
{ urlIsSetandSelected && (
<ToolbarButton
name="link"
icon={ linkOff }
title={ __( 'Unlink' ) }
shortcut={ displayShortcut.primaryShift( 'k' ) }
onClick={ () =>
setAttributes( {
url: undefined,
linkTarget: undefined,
rel: undefined,
} )
}
isActive={ true }
/>
) }
</ToolbarGroup>
</BlockControls>
{ isSelected && (
Expand Down

0 comments on commit ccda6d9

Please sign in to comment.