Skip to content

Commit

Permalink
fix: improve screen reader behaviour (fixes #131, fixes #200) (#235)
Browse files Browse the repository at this point in the history
* fix: add screen reader feedback for deselect all button (fix #131)
* fix: announce notifications (resolves #200)
  • Loading branch information
Ned Zimmerman authored Mar 28, 2020
1 parent 6dfb18b commit c9147b7
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 1 deletion.
47 changes: 47 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
},
"dependencies": {
"@platform-coop-toolkit/pinecone": "^1.0.0-alpha.11",
"@wordpress/a11y": "^2.7.0",
"cookies.js": "^2.1.15"
},
"devDependencies": {
Expand Down
6 changes: 6 additions & 0 deletions resources/assets/scripts/routes/archive.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import addNotification from '../util/addNotification';
import Cookies from 'cookies.js';
import Pinecone from '@platform-coop-toolkit/pinecone';
import { __, sprintf } from '@wordpress/i18n';
import { speak } from '@wordpress/a11y';

export default {
init() {
Expand All @@ -20,6 +21,11 @@ export default {
if ( 0 < deselectButtons.length ) {
Array.prototype.forEach.call( deselectButtons, btn => {
new Pinecone.DeselectAll( btn );
const filterGroup = btn.parentNode.parentNode;
const filterGroupLabel = filterGroup.firstElementChild.textContent;
btn.onclick = () => {
speak(sprintf(__('All %s have been deselected', 'coop-library'), filterGroupLabel));
}
} );
}

Expand Down
7 changes: 6 additions & 1 deletion resources/assets/scripts/util/addNotification.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { __ } from '@wordpress/i18n';
import { speak } from '@wordpress/a11y';

/**
* Add a notification.
Expand Down Expand Up @@ -26,16 +27,20 @@ export default (title, content, type) => {
}

const alert = `
<div class="notification notification--${type}" role="alert">
<div class="notification notification--${type}">
<button class="button button--borderless"><svg class="icon icon--close" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path id="close" d="m11.41 10 4.3-4.29a1 1 0 1 0 -1.42-1.42l-4.29 4.3-4.29-4.3a1 1 0 0 0 -1.42 1.42l4.3 4.29-4.3 4.29a1 1 0 0 0 0 1.42 1 1 0 0 0 1.42 0l4.29-4.3 4.29 4.3a1 1 0 0 0 1.42 0 1 1 0 0 0 0-1.42z" fill="currentColor"/></svg>
<span class="screen-reader-text">${__('Close notification', 'coop-library')}</span></button>
<p class="notification__title">${icon} ${title}</p>
<div class="notification__content">${content}</div>
</div>
`;

speak(content, 'assertive');

if (pageHeader.nextElementSibling.classList.contains('notification')) {
pageHeader.nextElementSibling.parentNode.removeChild(pageHeader.nextElementSibling);
}
pageHeader.insertAdjacentHTML('afterend', alert);


};

0 comments on commit c9147b7

Please sign in to comment.