Skip to content

Commit

Permalink
chore: Improve undo/redo no-op (#11428)
Browse files Browse the repository at this point in the history
* chore: Improve undo/redo no-op

See: https://github.com/WordPress/gutenberg/pull/11379\#discussion_r230406108

* Do not wrap dispatch undo/redo
  • Loading branch information
tofumatt authored Nov 8, 2018
1 parent 78dd21f commit 4e9d9b3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
16 changes: 6 additions & 10 deletions packages/editor/src/components/editor-history/redo.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ function EditorHistoryRedo( { hasRedo, redo } ) {
icon="redo"
label={ __( 'Redo' ) }
shortcut={ displayShortcut.primaryShift( 'z' ) }
// If there are no redo levels we don't want to actually disable this
// button, because it will remove focus for keyboard users.
// See: https://github.com/WordPress/gutenberg/issues/3486
aria-disabled={ ! hasRedo }
onClick={ redo }
onClick={ hasRedo ? redo : undefined }
className="editor-history__redo"
/>
);
Expand All @@ -24,14 +27,7 @@ export default compose( [
withSelect( ( select ) => ( {
hasRedo: select( 'core/editor' ).hasEditorRedo(),
} ) ),
withDispatch( ( dispatch, ownProps ) => ( {
redo: () => {
// If there are no redo levels this is a no-op, because we don't actually
// disable the button.
// See: https://github.com/WordPress/gutenberg/issues/3486
if ( ownProps.hasRedo ) {
dispatch( 'core/editor' ).redo();
}
},
withDispatch( ( dispatch ) => ( {
redo: dispatch( 'core/editor' ).redo,
} ) ),
] )( EditorHistoryRedo );
16 changes: 6 additions & 10 deletions packages/editor/src/components/editor-history/undo.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ function EditorHistoryUndo( { hasUndo, undo } ) {
icon="undo"
label={ __( 'Undo' ) }
shortcut={ displayShortcut.primary( 'z' ) }
// If there are no undo levels we don't want to actually disable this
// button, because it will remove focus for keyboard users.
// See: https://github.com/WordPress/gutenberg/issues/3486
aria-disabled={ ! hasUndo }
onClick={ undo }
onClick={ hasUndo ? undo : undefined }
className="editor-history__undo"
/>
);
Expand All @@ -24,14 +27,7 @@ export default compose( [
withSelect( ( select ) => ( {
hasUndo: select( 'core/editor' ).hasEditorUndo(),
} ) ),
withDispatch( ( dispatch, ownProps ) => ( {
undo: () => {
// If there are no undo levels this is a no-op, because we don't actually
// disable the button.
// See: https://github.com/WordPress/gutenberg/issues/3486
if ( ownProps.hasUndo ) {
dispatch( 'core/editor' ).undo();
}
},
withDispatch( ( dispatch ) => ( {
undo: dispatch( 'core/editor' ).undo,
} ) ),
] )( EditorHistoryUndo );

0 comments on commit 4e9d9b3

Please sign in to comment.