aria-ease 1.3.6 → 1.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Types.d.ts +8 -1
- package/aria-ease.d.ts +10 -2
- package/index.js +3 -1
- package/package.json +1 -1
- package/src/accordion/updateAccordionTriggerAriaAttributes.ts +6 -7
- package/src/checkbox/updateCheckboxAriaAttributes.js +18 -0
- package/src/checkbox/updateCheckboxAriaAttributes.ts +23 -0
- package/src/handleKeyPress.js +0 -8
- package/src/handleKeyPress.ts +1 -7
package/Types.d.ts
CHANGED
|
@@ -8,10 +8,17 @@ interface AccordionStates {
|
|
|
8
8
|
openedAriaLabel: string;
|
|
9
9
|
closedAriaLabel: string;
|
|
10
10
|
}
|
|
11
|
+
|
|
12
|
+
interface CheckboxStates {
|
|
13
|
+
pressed: boolean;
|
|
14
|
+
checkedAriaLabel: string;
|
|
15
|
+
uncheckedAriaLabel: string;
|
|
16
|
+
}
|
|
11
17
|
|
|
12
18
|
|
|
13
19
|
export {
|
|
14
20
|
HTMLElement,
|
|
15
21
|
NodeListOfHTMLElement,
|
|
16
|
-
AccordionStates
|
|
22
|
+
AccordionStates,
|
|
23
|
+
CheckboxStates
|
|
17
24
|
};
|
package/aria-ease.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Declares the module 'aria-ease' and includes type information and JSDoc comments.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import { AccordionStates } from "./Types";
|
|
5
|
+
import { AccordionStates, CheckboxStates } from "./Types";
|
|
6
6
|
|
|
7
7
|
declare module 'aria-ease' {
|
|
8
8
|
/**
|
|
@@ -41,7 +41,15 @@ declare module 'aria-ease' {
|
|
|
41
41
|
* @param {number} currentClickedTriggerIndex Index of the currently clicked accordion trigger
|
|
42
42
|
*/
|
|
43
43
|
function updateAccordionTriggerAriaAttributes(accordionStates: AccordionStates[], accordionsClass: string, currentClickedTriggerIndex: number): void;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Adds screen reader accessibility to checkboxes. Updates the aria attributes of the checkbox. Checkbox element must possess the following aria attributes; aria-pressed and aria-label.
|
|
47
|
+
* @param {CheckboxStates[]} checkboxStates Array of objects containing checkboxes state information
|
|
48
|
+
* @param {string} checkboxesClass The shared class of all the checkboxes
|
|
49
|
+
* @param {number} currentPressedCheckboxIndex Index of the currently checked or unchecked checkbox
|
|
50
|
+
*/
|
|
51
|
+
function updateCheckboxAriaAttributes(checkboxStates: CheckboxStates[], checkboxesClass: string, currentPressedCheckboxIndex: number): void;
|
|
44
52
|
|
|
45
|
-
export { makeMenuAccessible, makeBlockAccessible, updateMenuTriggerAriaAttributes, cleanUpMenuEventListeners, updateAccordionTriggerAriaAttributes };
|
|
53
|
+
export { makeMenuAccessible, makeBlockAccessible, updateMenuTriggerAriaAttributes, cleanUpMenuEventListeners, updateAccordionTriggerAriaAttributes, updateCheckboxAriaAttributes };
|
|
46
54
|
}
|
|
47
55
|
|
package/index.js
CHANGED
|
@@ -3,11 +3,13 @@ import { makeBlockAccessible } from './src/block/makeBlockAccessible.js'
|
|
|
3
3
|
import { updateMenuTriggerAriaAttributes } from './src/menu/updateMenuTriggerAriaAttributes.js'
|
|
4
4
|
import { cleanUpMenuEventListeners } from './src/menu/cleanUpMenuEventListeners.js'
|
|
5
5
|
import { updateAccordionTriggerAriaAttributes } from './src/accordion/updateAccordionTriggerAriaAttributes.js'
|
|
6
|
+
import { updateCheckboxAriaAttributes } from './src/checkbox/updateCheckboxAriaAttributes.js'
|
|
6
7
|
|
|
7
8
|
export {
|
|
8
9
|
makeMenuAccessible,
|
|
9
10
|
makeBlockAccessible,
|
|
10
11
|
updateMenuTriggerAriaAttributes,
|
|
11
12
|
cleanUpMenuEventListeners,
|
|
12
|
-
updateAccordionTriggerAriaAttributes
|
|
13
|
+
updateAccordionTriggerAriaAttributes,
|
|
14
|
+
updateCheckboxAriaAttributes
|
|
13
15
|
}
|
package/package.json
CHANGED
|
@@ -15,12 +15,11 @@ export function updateAccordionTriggerAriaAttributes(accordionStates: AccordionS
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
allAccordionTrigger.forEach((trigger, index) => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
trigger.setAttribute("aria-label", accordionStates[index].display ? accordionStates[index].openedAriaLabel : accordionStates[index].closedAriaLabel);
|
|
18
|
+
if (index === currentClickedTriggerIndex) {
|
|
19
|
+
trigger.setAttribute("aria-expanded", accordionStates[index].display ? 'true' : 'false');
|
|
20
|
+
} else {
|
|
21
|
+
trigger.setAttribute("aria-expanded", 'false');
|
|
22
|
+
}
|
|
23
|
+
trigger.setAttribute("aria-label", accordionStates[index].display ? accordionStates[index].openedAriaLabel : accordionStates[index].closedAriaLabel);
|
|
25
24
|
});
|
|
26
25
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adds screen reader accessibility to checkboxes. Updates the aria attributes of the checkbox. Checkbox element must possess the following aria attributes; aria-pressed and aria-label.
|
|
3
|
+
* @param {CheckboxStates[]} checkboxStates Array of objects containing checkboxes state information
|
|
4
|
+
* @param {string} checkboxesClass The shared class of all the checkboxes
|
|
5
|
+
* @param {number} currentPressedCheckboxIndex Index of the currently checked or unchecked checkbox
|
|
6
|
+
*/
|
|
7
|
+
export function updateCheckboxAriaAttributes(checkboxStates, checkboxesClass, currentPressedCheckboxIndex) {
|
|
8
|
+
var allCheckboxes = Array.from(document.querySelectorAll(".".concat(checkboxesClass)));
|
|
9
|
+
if (!allCheckboxes) {
|
|
10
|
+
throw new Error('Invalid checkboxes class provided.');
|
|
11
|
+
}
|
|
12
|
+
allCheckboxes.forEach(function (checkbox, index) {
|
|
13
|
+
if (index === currentPressedCheckboxIndex) {
|
|
14
|
+
checkbox.setAttribute("aria-pressed", checkboxStates[index].pressed ? 'true' : 'false');
|
|
15
|
+
checkbox.setAttribute("aria-label", checkboxStates[index].pressed ? checkboxStates[index].checkedAriaLabel : checkboxStates[index].uncheckedAriaLabel);
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adds screen reader accessibility to checkboxes. Updates the aria attributes of the checkbox. Checkbox element must possess the following aria attributes; aria-pressed and aria-label.
|
|
3
|
+
* @param {CheckboxStates[]} checkboxStates Array of objects containing checkboxes state information
|
|
4
|
+
* @param {string} checkboxesClass The shared class of all the checkboxes
|
|
5
|
+
* @param {number} currentPressedCheckboxIndex Index of the currently checked or unchecked checkbox
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { HTMLElement, CheckboxStates } from "../../Types";
|
|
9
|
+
|
|
10
|
+
export function updateCheckboxAriaAttributes(checkboxStates: CheckboxStates[], checkboxesClass: string, currentPressedCheckboxIndex: number): void {
|
|
11
|
+
const allCheckboxes: HTMLElement[] = Array.from(document.querySelectorAll(`.${checkboxesClass}`));
|
|
12
|
+
|
|
13
|
+
if ( !allCheckboxes) {
|
|
14
|
+
throw new Error('Invalid checkboxes class provided.');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
allCheckboxes.forEach((checkbox, index) => {
|
|
18
|
+
if (index === currentPressedCheckboxIndex) {
|
|
19
|
+
checkbox.setAttribute("aria-pressed", checkboxStates[index].pressed ? 'true' : 'false');
|
|
20
|
+
checkbox.setAttribute("aria-label", checkboxStates[index].pressed ? checkboxStates[index].checkedAriaLabel : checkboxStates[index].uncheckedAriaLabel);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
package/src/handleKeyPress.js
CHANGED
|
@@ -46,14 +46,6 @@ export function handleKeyPress(event, elementItems, elementItemIndex, menuElemen
|
|
|
46
46
|
window.location.href = elementItems.item(elementItemIndex).href;
|
|
47
47
|
break;
|
|
48
48
|
}
|
|
49
|
-
else if (elementItems.item(elementItemIndex).type === 'radio') {
|
|
50
|
-
elementItems.item(elementItemIndex).checked = true;
|
|
51
|
-
break;
|
|
52
|
-
}
|
|
53
|
-
else if (elementItems.item(elementItemIndex).type === 'checkbox') {
|
|
54
|
-
elementItems.item(elementItemIndex).checked = !elementItems.item(elementItemIndex).checked;
|
|
55
|
-
break;
|
|
56
|
-
}
|
|
57
49
|
break;
|
|
58
50
|
default:
|
|
59
51
|
break;
|
package/src/handleKeyPress.ts
CHANGED
|
@@ -41,17 +41,11 @@ export function handleKeyPress(event: KeyboardEvent, elementItems: NodeListOfHTM
|
|
|
41
41
|
case ' ':
|
|
42
42
|
event.preventDefault()
|
|
43
43
|
if(elementItems.item(elementItemIndex).tagName === 'BUTTON') {
|
|
44
|
-
elementItems.item(elementItemIndex).click()
|
|
44
|
+
elementItems.item(elementItemIndex).click();
|
|
45
45
|
break;
|
|
46
46
|
} else if (elementItems.item(elementItemIndex).tagName === 'A') {
|
|
47
47
|
window.location.href = elementItems.item(elementItemIndex).href;
|
|
48
48
|
break;
|
|
49
|
-
} else if (elementItems.item(elementItemIndex).type === 'radio') {
|
|
50
|
-
elementItems.item(elementItemIndex).checked = true
|
|
51
|
-
break;
|
|
52
|
-
} else if (elementItems.item(elementItemIndex).type === 'checkbox') {
|
|
53
|
-
elementItems.item(elementItemIndex).checked = !elementItems.item(elementItemIndex).checked
|
|
54
|
-
break;
|
|
55
49
|
}
|
|
56
50
|
break;
|
|
57
51
|
default:
|