Skip to content

Commit

Permalink
Move Link Control action buttons into lower area (#47309)
Browse files Browse the repository at this point in the history
* Match the design by moving buttons

* Update test to match new tab order

* Update another e2e test to match new tab order

* Hide action buttons when not in editing mode
  • Loading branch information
getdave authored Jan 21, 2023
1 parent c3af62b commit e605937
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 32 deletions.
53 changes: 30 additions & 23 deletions packages/block-editor/src/components/link-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ function LinkControl( {
// See https://github.com/WordPress/gutenberg/pull/33849/#issuecomment-932194927.
const showTextControl = hasLinkValue && hasTextControl;

const isEditing = ( isEditingLink || ! value ) && ! isCreatingPage;
return (
<div
tabIndex={ -1 }
Expand All @@ -286,7 +287,7 @@ function LinkControl( {
</div>
) }

{ ( isEditingLink || ! value ) && ! isCreatingPage && (
{ isEditing && (
<>
<div
className={ classnames( {
Expand Down Expand Up @@ -335,19 +336,6 @@ function LinkControl( {
{ errorMessage }
</Notice>
) }
<div className="block-editor-link-control__search-actions">
<Button
variant="primary"
onClick={ handleSubmit }
className="xblock-editor-link-control__search-submit"
disabled={ currentInputIsEmpty } // Disallow submitting empty values.
>
{ __( 'Apply' ) }
</Button>
<Button variant="tertiary" onClick={ handleCancel }>
{ __( 'Cancel' ) }
</Button>
</div>
</>
) }

Expand All @@ -362,15 +350,34 @@ function LinkControl( {
/>
) }

{ showSettingsDrawer && (
<div className="block-editor-link-control__tools">
<LinkControlSettingsDrawer
value={ value }
settings={ settings }
onChange={ onChange }
/>
</div>
) }
<div className="block-editor-link-control__drawer">
{ showSettingsDrawer && (
<div className="block-editor-link-control__tools">
<LinkControlSettingsDrawer
value={ value }
settings={ settings }
onChange={ onChange }
/>
</div>
) }

{ isEditing && (
<div className="block-editor-link-control__search-actions">
<Button
variant="primary"
onClick={ handleSubmit }
className="xblock-editor-link-control__search-submit"
disabled={ currentInputIsEmpty } // Disallow submitting empty values.
>
{ __( 'Apply' ) }
</Button>
<Button variant="tertiary" onClick={ handleCancel }>
{ __( 'Cancel' ) }
</Button>
</div>
) }
</div>

{ renderControlBottom && renderControlBottom() }
</div>
);
Expand Down
4 changes: 2 additions & 2 deletions packages/block-editor/src/components/link-control/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ $preview-image-height: 140px;
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;
}

Expand Down Expand Up @@ -427,9 +426,10 @@ $preview-image-height: 140px;
padding: 10px;
}

.block-editor-link-control__tools {
.block-editor-link-control__drawer {
display: flex;
align-items: center;
justify-content: space-between;
border-top: $border-width solid $gray-300;
margin: 0;
padding: $grid-unit-20;
Expand Down
10 changes: 3 additions & 7 deletions packages/e2e-tests/specs/editor/various/links.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ 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.
Expand All @@ -135,8 +133,7 @@ describe( 'Links', () => {
expect( await getEditedPostContent() ).toMatchSnapshot();

// Tab back to the Submit and apply the link.
await pressKeyWithModifier( 'shift', 'Tab' );
await pressKeyWithModifier( 'shift', 'Tab' );
await page.keyboard.press( 'Tab' );
await page.keyboard.press( 'Enter' );

// The link should have been inserted.
Expand Down Expand Up @@ -529,8 +526,6 @@ 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
Expand All @@ -539,7 +534,8 @@ describe( 'Links', () => {

// Close dialog. Expect that "Open in new tab" would have been applied
// immediately.
await page.keyboard.press( 'Tab' );

await pressKeyWithModifier( 'shift', 'Tab' );
await page.keyboard.press( 'Enter' );

// Wait for Gutenberg to finish the job.
Expand Down

1 comment on commit e605937

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in e605937.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/3972918414
📝 Reported issues:

Please sign in to comment.