Skip to content

Commit

Permalink
Accessibility: Announce notices to assertive technologies
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Dec 28, 2017
1 parent 003d533 commit c668bb3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
2 changes: 2 additions & 0 deletions editor/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ export function createNotice( status, content, options = {} ) {
const {
id = uuid(),
isDismissible = true,
spokenMessage,
} = options;
return {
type: 'CREATE_NOTICE',
Expand All @@ -395,6 +396,7 @@ export function createNotice( status, content, options = {} ) {
status,
content,
isDismissible,
spokenMessage,
},
};
}
Expand Down
22 changes: 13 additions & 9 deletions editor/store/effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
getDefaultBlockName,
} from '@wordpress/blocks';
import { __ } from '@wordpress/i18n';
import { speak } from '@wordpress/a11y';

/**
* Internal dependencies
Expand Down Expand Up @@ -140,7 +141,7 @@ export default {
{ ' ' }
{ shouldShowLink && <a href={ post.link }>{ __( 'View post' ) }</a> }
</p>,
{ id: SAVE_POST_NOTICE_ID }
{ id: SAVE_POST_NOTICE_ID, spokenMessage: noticeMessage }
) );
}

Expand Down Expand Up @@ -361,17 +362,16 @@ export default {
updatedId: updatedReusableBlock.id,
id,
} );
dispatch( createSuccessNotice(
__( 'Block updated.' ),
{ id: SAVE_REUSABLE_BLOCK_NOTICE_ID }
) );
const message = __( 'Block updated.' );
dispatch( createSuccessNotice( message, { id: SAVE_REUSABLE_BLOCK_NOTICE_ID } ) );
},
( error ) => {
dispatch( { type: 'SAVE_REUSABLE_BLOCK_FAILURE', id } );
dispatch( createErrorNotice(
get( error.responseJSON, 'message', __( 'An unknown error occured.' ) ),
{ id: SAVE_REUSABLE_BLOCK_NOTICE_ID }
) );
const message = __( 'An unknown error occured.' );
dispatch( createErrorNotice( get( error.responseJSON, 'message', message ), {
id: SAVE_REUSABLE_BLOCK_NOTICE_ID,
spokenMessage: message,
} ) );
}
);
},
Expand All @@ -396,4 +396,8 @@ export default {
APPEND_DEFAULT_BLOCK() {
return insertBlock( createBlock( getDefaultBlockName() ) );
},
CREATE_NOTICE( { notice: { content, spokenMessage } } ) {
const message = spokenMessage || content;
speak( message, 'assertive' );
},
};
3 changes: 3 additions & 0 deletions editor/store/test/effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ describe( 'effects', () => {
id: 'SAVE_POST_NOTICE_ID',
isDismissible: true,
status: 'success',
spokenMessage: 'Post published!',
},
type: 'CREATE_NOTICE',
} ) );
Expand All @@ -371,6 +372,7 @@ describe( 'effects', () => {
id: 'SAVE_POST_NOTICE_ID',
isDismissible: true,
status: 'success',
spokenMessage: 'Post reverted to draft.',
},
type: 'CREATE_NOTICE',
} ) );
Expand All @@ -392,6 +394,7 @@ describe( 'effects', () => {
id: 'SAVE_POST_NOTICE_ID',
isDismissible: true,
status: 'success',
spokenMessage: 'Post updated!',
},
type: 'CREATE_NOTICE',
} ) );
Expand Down

0 comments on commit c668bb3

Please sign in to comment.