Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block Library: Handle Popover onClose for LinkControl #19885

Merged
merged 2 commits into from
Jan 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 4 additions & 4 deletions packages/block-library/src/button/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ function URLPicker( { isSelected, url, title, setAttributes, opensInNewTab, onTo
setIsURLPickerOpen( true );
};
const linkControl = isURLPickerOpen && (
<Popover position="bottom center">
<Popover
position="bottom center"
onClose={ () => setIsURLPickerOpen( false ) }
>
<LinkControl
className="wp-block-navigation-link__inline-link-input"
value={ { url, title, opensInNewTab } }
Expand All @@ -111,9 +114,6 @@ function URLPicker( { isSelected, url, title, setAttributes, opensInNewTab, onTo
onToggleOpenInNewTab( newOpensInNewTab );
}
} }
onClose={ () => {
setIsURLPickerOpen( false );
} }
/>
</Popover>
);
Expand Down
6 changes: 4 additions & 2 deletions packages/block-library/src/navigation-link/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,10 @@ function NavigationLinkEdit( {
</span>
}
{ isLinkOpen && (
<Popover position="bottom center">
<Popover
position="bottom center"
onClose={ () => setIsLinkOpen( false ) }
>
<LinkControl
className="wp-block-navigation-link__inline-link-input"
value={ link }
Expand All @@ -202,7 +205,6 @@ function NavigationLinkEdit( {
opensInNewTab: newOpensInNewTab,
id,
} ) }
onClose={ () => setIsLinkOpen( false ) }
/>
</Popover>
) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ exports[`Buttons can jump to the link editor using the keyboard shortcut 1`] = `
<!-- /wp:buttons -->"
`;

exports[`Buttons dismisses link editor when escape is pressed 1`] = `
"<!-- wp:buttons -->
<div class=\\"wp-block-buttons\\"><!-- wp:button -->
<div class=\\"wp-block-button\\"><a class=\\"wp-block-button__link\\">WordPress</a></div>
<!-- /wp:button --></div>
<!-- /wp:buttons -->"
`;

exports[`Buttons has focus on button content 1`] = `
"<!-- wp:buttons -->
<div class=\\"wp-block-buttons\\"><!-- wp:button -->
Expand Down
10 changes: 10 additions & 0 deletions packages/e2e-tests/specs/editor/blocks/buttons.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ describe( 'Buttons', () => {
expect( await getEditedPostContent() ).toMatchSnapshot();
} );

it( 'dismisses link editor when escape is pressed', async () => {
// Regression: https://github.com/WordPress/gutenberg/pull/19885
await insertBlock( 'Buttons' );
await pressKeyWithModifier( 'primary', 'k' );
await page.keyboard.press( 'Escape' );
await page.keyboard.type( 'WordPress' );

expect( await getEditedPostContent() ).toMatchSnapshot();
} );

it( 'can jump to the link editor using the keyboard shortcut', async () => {
await insertBlock( 'Buttons' );
await page.keyboard.type( 'WordPress' );
Expand Down
18 changes: 18 additions & 0 deletions packages/e2e-tests/specs/editor/blocks/navigation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
insertBlock,
pressKeyWithModifier,
setUpResponseMocking,
clickBlockToolbarButton,
} from '@wordpress/e2e-test-utils';

async function mockPagesResponse( pages ) {
Expand Down Expand Up @@ -132,6 +133,23 @@ describe( 'Navigation', () => {
// an issue where the block appender requires two clicks.
await page.click( '.wp-block-navigation .block-list-appender' );

// After adding a new block, search input should be shown immediately.
// Verify that Escape would close the popover.
// Regression: https://github.com/WordPress/gutenberg/pull/19885
const isInURLInput = await page.evaluate( () => (
!! document.activeElement.closest( '.block-editor-url-input' )
) );
expect( isInURLInput ).toBe( true );
await page.keyboard.press( 'Escape' );
const isInLinkRichText = await page.evaluate( () => (
document.activeElement.classList.contains( 'rich-text' ) &&
!! document.activeElement.closest( '.block-editor-block-list__block' )
) );
expect( isInLinkRichText ).toBe( true );

// Now, trigger the link dialog once more.
await clickBlockToolbarButton( 'Link' );

// For the second nav link block use an existing internal page.
// Mock the api response so that it's consistent.
await mockSearchResponse( [ { title: 'Contact Us', slug: 'contact-us' } ] );
Expand Down