Skip to content

Commit

Permalink
Update Link UI design for preview action buttons to use icons for edi…
Browse files Browse the repository at this point in the history
…t and unlink (#35833)

* Add unlink and edit buttons in icon form

* Use a11y means to selecting Edit button

* Fix e2e tests by targetting aria label
  • Loading branch information
getdave authored Oct 25, 2021
1 parent 0f08b2e commit cec3b9b
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 23 deletions.
14 changes: 3 additions & 11 deletions packages/block-editor/src/components/link-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,26 +270,18 @@ function LinkControl( {
value={ value }
onEditClick={ () => setIsEditingLink( true ) }
hasRichPreviews={ hasRichPreviews }
hasUnlinkControl={ shownUnlinkControl }
onRemove={ onRemove }
/>
) }

{ ( showSettingsDrawer || shownUnlinkControl ) && (
{ showSettingsDrawer && (
<div className="block-editor-link-control__tools">
<LinkControlSettingsDrawer
value={ value }
settings={ settings }
onChange={ onChange }
/>
{ shownUnlinkControl && (
<Button
className="block-editor-link-control__unlink"
isDestructive
variant="link"
onClick={ onRemove }
>
{ __( 'Unlink' ) }
</Button>
) }
</div>
) }
</div>
Expand Down
23 changes: 17 additions & 6 deletions packages/block-editor/src/components/link-control/link-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
__experimentalText as Text,
} from '@wordpress/components';
import { filterURLForDisplay, safeDecodeURI } from '@wordpress/url';
import { Icon, globe, info } from '@wordpress/icons';
import { Icon, globe, info, linkOff, edit } from '@wordpress/icons';

/**
* Internal dependencies
Expand All @@ -26,6 +26,8 @@ export default function LinkPreview( {
value,
onEditClick,
hasRichPreviews = false,
hasUnlinkControl = false,
onRemove,
} ) {
// Avoid fetching if rich previews are not desired.
const showRichPreviews = hasRichPreviews ? value?.url : null;
Expand Down Expand Up @@ -102,12 +104,21 @@ export default function LinkPreview( {
</span>

<Button
variant="secondary"
onClick={ () => onEditClick() }
icon={ edit }
label={ __( 'Edit' ) }
className="block-editor-link-control__search-item-action"
>
{ __( 'Edit' ) }
</Button>
onClick={ onEditClick }
iconSize={ 24 }
/>
{ hasUnlinkControl && (
<Button
icon={ linkOff }
label={ __( 'Unlink' ) }
className="block-editor-link-control__search-item-action block-editor-link-control__unlink"
onClick={ onRemove }
iconSize={ 24 }
/>
) }
<ViewerSlot fillProps={ value } />
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ describe( 'Basic rendering', () => {
} );

// Click the "Edit" button to trigger into the editing mode.
const editButton = Array.from(
container.querySelectorAll( 'button' )
).find( ( button ) => button.innerHTML.includes( 'Edit' ) );
const editButton = queryByRole( container, 'button', {
name: 'Edit',
} );

act( () => {
Simulate.click( editButton );
Expand Down
6 changes: 5 additions & 1 deletion packages/e2e-tests/specs/editor/blocks/image.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,11 @@ describe( 'Image', () => {

// Replace uploaded image with an URL.
await clickButton( 'Replace' );
await clickButton( 'Edit' );

const [ editButton ] = await page.$x(
'//button[contains(@aria-label, "Edit")]'
);
await editButton.click();

await page.waitForSelector( '.block-editor-url-input__input' );
await page.evaluate(
Expand Down
8 changes: 6 additions & 2 deletions packages/e2e-tests/specs/editor/various/links.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,9 @@ describe( 'Links', () => {
await createAndReselectLink();

// Click on the Edit button
const [ editButton ] = await page.$x( '//button[text()="Edit"]' );
const [ editButton ] = await page.$x(
'//button[contains(@aria-label, "Edit")]'
);
await editButton.click();

// Wait for the URL field to auto-focus
Expand Down Expand Up @@ -329,7 +331,9 @@ describe( 'Links', () => {
await page.keyboard.press( 'ArrowLeft' );
await page.keyboard.press( 'ArrowRight' );
await showBlockToolbar();
const [ editButton ] = await page.$x( '//button[text()="Edit"]' );
const [ editButton ] = await page.$x(
'//button[contains(@aria-label, "Edit")]'
);
await editButton.click();
await waitForAutoFocus();
await page.keyboard.type( '/handbook' );
Expand Down

0 comments on commit cec3b9b

Please sign in to comment.