Skip to content

Commit

Permalink
Close block settings menu after removing block (#15543)
Browse files Browse the repository at this point in the history
* Close block settings menu after removing block

* Undo change to BlockToolbar component

* Also close settings menu after other items

See #15313

* Do not show BlockSettingsMenu if block is invalid

* Use flow()

* Block Editor: Select previous / next only when exists

* Remove now unneeded isValid check
  • Loading branch information
swissspidy authored and gziolo committed May 23, 2019
1 parent 1a20e15 commit ce29311
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* External dependencies
*/
import classnames from 'classnames';
import { castArray } from 'lodash';
import { castArray, flow } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -70,7 +70,7 @@ export function BlockSettingsMenu( { clientIds, onSelect } ) {
{ ! isLocked && canDuplicate && (
<MenuItem
className="editor-block-settings-menu__control block-editor-block-settings-menu__control"
onClick={ onDuplicate }
onClick={ flow( onClose, onDuplicate ) }
icon="admin-page"
shortcut={ shortcuts.duplicate.display }
>
Expand All @@ -81,15 +81,15 @@ export function BlockSettingsMenu( { clientIds, onSelect } ) {
<>
<MenuItem
className="editor-block-settings-menu__control block-editor-block-settings-menu__control"
onClick={ onInsertBefore }
onClick={ flow( onClose, onInsertBefore ) }
icon="insert-before"
shortcut={ shortcuts.insertBefore.display }
>
{ __( 'Insert Before' ) }
</MenuItem>
<MenuItem
className="editor-block-settings-menu__control block-editor-block-settings-menu__control"
onClick={ onInsertAfter }
onClick={ flow( onClose, onInsertAfter ) }
icon="insert-after"
shortcut={ shortcuts.insertAfter.display }
>
Expand All @@ -108,7 +108,7 @@ export function BlockSettingsMenu( { clientIds, onSelect } ) {
{ ! isLocked && (
<MenuItem
className="editor-block-settings-menu__control block-editor-block-settings-menu__control"
onClick={ onRemove }
onClick={ flow( onClose, onRemove ) }
icon="trash"
shortcut={ shortcuts.removeBlock.display }
>
Expand Down
8 changes: 6 additions & 2 deletions packages/block-editor/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ export function* selectPreviousBlock( clientId ) {
clientId
);

yield selectBlock( previousBlockClientId, -1 );
if ( previousBlockClientId ) {
yield selectBlock( previousBlockClientId, -1 );
}
}

/**
Expand All @@ -147,7 +149,9 @@ export function* selectNextBlock( clientId ) {
clientId
);

yield selectBlock( nextBlockClientId );
if ( nextBlockClientId ) {
yield selectBlock( nextBlockClientId );
}
}

/**
Expand Down

0 comments on commit ce29311

Please sign in to comment.