Skip to content

Commit

Permalink
Merge pull request #1146 from WordPress/bug/778-abort-link
Browse files Browse the repository at this point in the history
Add unlink button to escape out of adding link
  • Loading branch information
mkaz authored Jun 16, 2017
2 parents 9ec4261 + 1882f05 commit a9b0950
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions blocks/editable/format-toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* WordPress dependencies
*/
import { IconButton, Toolbar } from 'components';
import { ESCAPE } from 'utils/keycodes';

const FORMATTING_CONTROLS = [
{
Expand Down Expand Up @@ -36,6 +37,11 @@ class FormatToolbar extends wp.element.Component {
this.dropLink = this.dropLink.bind( this );
this.submitLink = this.submitLink.bind( this );
this.updateLinkValue = this.updateLinkValue.bind( this );
this.onKeyPress = this.onKeyPress.bind( this );
}

componentDidMount() {
document.addEventListener( 'keypress', this.onKeyPress );
}

componentWillUnmout() {
Expand All @@ -44,6 +50,15 @@ class FormatToolbar extends wp.element.Component {
}
}

onKeyPress( event ) {
if ( event.keyCode === ESCAPE ) {
if ( this.state.isEditingLink ) {
event.preventDefault();
this.dropLink();
}
}
}

componentWillReceiveProps( nextProps ) {
const newState = {
linkValue: nextProps.formats.link ? nextProps.formats.link.value : '',
Expand Down Expand Up @@ -143,6 +158,7 @@ class FormatToolbar extends wp.element.Component {
placeholder={ wp.i18n.__( 'Paste URL or type' ) }
/>
<IconButton icon="editor-break" type="submit" />
<IconButton icon="editor-unlink" onClick={ this.dropLink } />
</form>
}

Expand Down

0 comments on commit a9b0950

Please sign in to comment.