Skip to content

Commit

Permalink
fix: Use aria-disabled instead of disabled for undo/redo (#11379)
Browse files Browse the repository at this point in the history
Fixes #3486
  • Loading branch information
tofumatt authored Nov 2, 2018
1 parent fbc093a commit ccb199e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
13 changes: 10 additions & 3 deletions packages/editor/src/components/editor-history/redo.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function EditorHistoryRedo( { hasRedo, redo } ) {
icon="redo"
label={ __( 'Redo' ) }
shortcut={ displayShortcut.primaryShift( 'z' ) }
disabled={ ! hasRedo }
aria-disabled={ ! hasRedo }
onClick={ redo }
className="editor-history__redo"
/>
Expand All @@ -24,7 +24,14 @@ export default compose( [
withSelect( ( select ) => ( {
hasRedo: select( 'core/editor' ).hasEditorRedo(),
} ) ),
withDispatch( ( dispatch ) => ( {
redo: () => dispatch( 'core/editor' ).redo(),
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();
}
},
} ) ),
] )( EditorHistoryRedo );
13 changes: 10 additions & 3 deletions packages/editor/src/components/editor-history/undo.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function EditorHistoryUndo( { hasUndo, undo } ) {
icon="undo"
label={ __( 'Undo' ) }
shortcut={ displayShortcut.primary( 'z' ) }
disabled={ ! hasUndo }
aria-disabled={ ! hasUndo }
onClick={ undo }
className="editor-history__undo"
/>
Expand All @@ -24,7 +24,14 @@ export default compose( [
withSelect( ( select ) => ( {
hasUndo: select( 'core/editor' ).hasEditorUndo(),
} ) ),
withDispatch( ( dispatch ) => ( {
undo: () => dispatch( 'core/editor' ).undo(),
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();
}
},
} ) ),
] )( EditorHistoryUndo );
4 changes: 2 additions & 2 deletions test/e2e/specs/new-post.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ describe( 'new editor state', () => {
} );

it( 'should have no history', async () => {
const undoButton = await page.$( '.editor-history__undo:not( :disabled )' );
const redoButton = await page.$( '.editor-history__redo:not( :disabled )' );
const undoButton = await page.$( '.editor-history__undo[aria-disabled="false"]' );
const redoButton = await page.$( '.editor-history__redo[aria-disabled="false"]' );

expect( undoButton ).toBeNull();
expect( redoButton ).toBeNull();
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/specs/undo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe( 'undo', () => {
await pressWithModifier( META_KEY, 'z' ); // Undo 1st block.

// After undoing every action, there should be no more undo history.
await page.waitForSelector( '.editor-history__undo:disabled' );
await page.waitForSelector( '.editor-history__undo[aria-disabled="true"]' );

expect( await getEditedPostContent() ).toBe( '' );
} );
Expand Down

0 comments on commit ccb199e

Please sign in to comment.