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

chore: Improve undo/redo no-op #11428

Merged
merged 2 commits into from
Nov 8, 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
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 );