MDL-74073 courseformat: Toggle Collapse/Expand all via space key

* Add 'space' keydown event handler on the Collapse/Expand all element
on the course homepage.
* Set aria-expanded attribute of the Expand/Collapse all element
accordingly

Reference:
https://www.w3.org/TR/wai-aria-practices-1.1/#disclosure
This commit is contained in:
Jun Pataleta 2022-03-04 23:24:29 +08:00
parent ed55f45754
commit b9ff0ff99b
3 changed files with 10 additions and 2 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -106,6 +106,12 @@ export default class Component extends BaseComponent {
const toogleAll = this.getElement(this.selectors.TOGGLEALL);
if (toogleAll) {
this.addEventListener(toogleAll, 'click', this._allSectionToggler);
this.addEventListener(toogleAll, 'keydown', e => {
// Collapse/expand all sections when Space key is pressed on the toggle button.
if (e.key === ' ') {
this._allSectionToggler(e);
}
});
this._refreshAllSectionsToggler(state);
}
@ -263,9 +269,11 @@ export default class Component extends BaseComponent {
);
if (allcollapsed) {
target.classList.add(this.classes.COLLAPSED);
target.setAttribute('aria-expanded', false);
}
if (allexpanded) {
target.classList.remove(this.classes.COLLAPSED);
target.setAttribute('aria-expanded', true);
}
}