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

Fix escape key failing to close inline link popover #11806

Merged
merged 2 commits into from
Nov 16, 2018
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: 2 additions & 6 deletions packages/format-library/src/link/inline.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
ToggleControl,
withSpokenMessages,
} from '@wordpress/components';
import { ESCAPE, LEFT, RIGHT, UP, DOWN, BACKSPACE, ENTER } from '@wordpress/keycodes';
import { LEFT, RIGHT, UP, DOWN, BACKSPACE, ENTER } from '@wordpress/keycodes';
import { prependHTTP, safeDecodeURI, filterURLForDisplay } from '@wordpress/url';
import {
create,
Expand Down Expand Up @@ -143,11 +143,6 @@ class InlineLinkUI extends Component {
}

onKeyDown( event ) {
if ( event.keyCode === ESCAPE ) {
event.stopPropagation();
this.resetState();
}

if ( [ LEFT, DOWN, RIGHT, UP, BACKSPACE, ENTER ].indexOf( event.keyCode ) > -1 ) {
// Stop the key event from propagating up to ObserveTyping.startTypingInTextField.
event.stopPropagation();
Expand Down Expand Up @@ -234,6 +229,7 @@ class InlineLinkUI extends Component {
>
<URLPopover
onClickOutside={ this.onClickOutside }
onClose={ this.resetState }
focusOnMount={ showInput ? 'firstElement' : false }
renderSettings={ () => (
<ToggleControl
Expand Down
15 changes: 15 additions & 0 deletions test/e2e/specs/links.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,21 @@ describe( 'Links', () => {
// Expect the the escape key to dismiss the popover normally.
await page.keyboard.press( 'Escape' );
expect( await page.$( '.editor-url-popover' ) ).toBeNull();

// Press Cmd+K to insert a link
await pressWithModifier( META_KEY, 'K' );

// Wait for the URL field to auto-focus
await waitForAutoFocus();
expect( await page.$( '.editor-url-popover' ) ).not.toBeNull();

// Tab to the settings icon button.
await page.keyboard.press( 'Tab' );
await page.keyboard.press( 'Tab' );

// Expect the the escape key to dismiss the popover normally.
await page.keyboard.press( 'Escape' );
expect( await page.$( '.editor-url-popover' ) ).toBeNull();
} );

it( 'can be modified using the keyboard once a link has been set', async () => {
Expand Down