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

Accessibility: Announce notices to assertive technologies #4192

Merged
merged 1 commit into from
Jan 2, 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
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!',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be localized.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, these are only tests. The message is localized :)

},
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