aria-ease 1.3.7 → 1.3.9
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/README.md +2 -3
- package/Types.d.ts +8 -2
- package/aria-ease.d.ts +20 -5
- package/index.js +3 -1
- package/package.json +1 -1
- package/src/checkbox/updateCheckboxAriaAttributes.js +4 -3
- package/src/checkbox/updateCheckboxAriaAttributes.ts +4 -4
- package/src/radio/updateRadioAriaAttributes.js +23 -0
- package/src/radio/updateRadioAriaAttributes.ts +27 -0
package/README.md
CHANGED
|
@@ -77,9 +77,8 @@ import { makeBlockAccessible } from "aria-ease"
|
|
|
77
77
|
|
|
78
78
|
const BlockExample = () => {
|
|
79
79
|
useEffect(() => {
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
return cleanUp
|
|
80
|
+
const accessibleBlock = makeBlockAccessible('custom-tab', 'custom-tab-item');
|
|
81
|
+
return accessibleBlock
|
|
83
82
|
},[])
|
|
84
83
|
|
|
85
84
|
return (
|
package/Types.d.ts
CHANGED
|
@@ -10,15 +10,21 @@ interface AccordionStates {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
interface CheckboxStates {
|
|
13
|
-
|
|
13
|
+
checked: boolean;
|
|
14
14
|
checkedAriaLabel: string;
|
|
15
15
|
uncheckedAriaLabel: string;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
interface RadioStates {
|
|
19
|
+
checked: boolean;
|
|
20
|
+
checkedAriaLabel: string;
|
|
21
|
+
uncheckedAriaLabel: string;
|
|
22
|
+
}
|
|
18
23
|
|
|
19
24
|
export {
|
|
20
25
|
HTMLElement,
|
|
21
26
|
NodeListOfHTMLElement,
|
|
22
27
|
AccordionStates,
|
|
23
|
-
CheckboxStates
|
|
28
|
+
CheckboxStates,
|
|
29
|
+
RadioStates
|
|
24
30
|
};
|
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, CheckboxStates } from "./Types";
|
|
5
|
+
import { AccordionStates, CheckboxStates, RadioStates } from "./Types";
|
|
6
6
|
|
|
7
7
|
declare module 'aria-ease' {
|
|
8
8
|
/**
|
|
@@ -43,13 +43,28 @@ declare module 'aria-ease' {
|
|
|
43
43
|
function updateAccordionTriggerAriaAttributes(accordionStates: AccordionStates[], accordionsClass: string, currentClickedTriggerIndex: number): void;
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
|
-
* Adds screen reader accessibility to checkboxes. Updates the aria attributes of the checkbox. Checkbox element must possess the following aria attributes; aria-
|
|
46
|
+
* Adds screen reader accessibility to checkboxes. Updates the aria attributes of the checkbox. Checkbox element must possess the following aria attributes; aria-checked and aria-label.
|
|
47
47
|
* @param {CheckboxStates[]} checkboxStates Array of objects containing checkboxes state information
|
|
48
48
|
* @param {string} checkboxesClass The shared class of all the checkboxes
|
|
49
49
|
* @param {number} currentPressedCheckboxIndex Index of the currently checked or unchecked checkbox
|
|
50
50
|
*/
|
|
51
51
|
function updateCheckboxAriaAttributes(checkboxStates: CheckboxStates[], checkboxesClass: string, currentPressedCheckboxIndex: number): void;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Adds screen reader accessibility to radio buttons. Updates the aria attributes of the radio button. Radio element must possess the following aria attributes; aria-checked and aria-label.
|
|
55
|
+
* @param {RadioStates[]} radioStates Array of objects containing radio buttons state information
|
|
56
|
+
* @param {string} radiosClass The shared class of all the radio buttons
|
|
57
|
+
* @param {number} currentPressedRadioIndex Index of the currently checked or unchecked radio button
|
|
58
|
+
*/
|
|
59
|
+
function updateRadioAriaAttributes(radioStates: RadioStates[], radiosClass: string, currentPressedRadioIndex: number): void;
|
|
52
60
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
61
|
+
export {
|
|
62
|
+
makeMenuAccessible,
|
|
63
|
+
makeBlockAccessible,
|
|
64
|
+
updateMenuTriggerAriaAttributes,
|
|
65
|
+
cleanUpMenuEventListeners,
|
|
66
|
+
updateAccordionTriggerAriaAttributes,
|
|
67
|
+
updateCheckboxAriaAttributes,
|
|
68
|
+
updateRadioAriaAttributes
|
|
69
|
+
};
|
|
70
|
+
}
|
package/index.js
CHANGED
|
@@ -4,6 +4,7 @@ import { updateMenuTriggerAriaAttributes } from './src/menu/updateMenuTriggerAri
|
|
|
4
4
|
import { cleanUpMenuEventListeners } from './src/menu/cleanUpMenuEventListeners.js'
|
|
5
5
|
import { updateAccordionTriggerAriaAttributes } from './src/accordion/updateAccordionTriggerAriaAttributes.js'
|
|
6
6
|
import { updateCheckboxAriaAttributes } from './src/checkbox/updateCheckboxAriaAttributes.js'
|
|
7
|
+
import { updateRadioAriaAttributes } from './src/radio/updateRadioAriaAttributes.js'
|
|
7
8
|
|
|
8
9
|
export {
|
|
9
10
|
makeMenuAccessible,
|
|
@@ -11,5 +12,6 @@ export {
|
|
|
11
12
|
updateMenuTriggerAriaAttributes,
|
|
12
13
|
cleanUpMenuEventListeners,
|
|
13
14
|
updateAccordionTriggerAriaAttributes,
|
|
14
|
-
updateCheckboxAriaAttributes
|
|
15
|
+
updateCheckboxAriaAttributes,
|
|
16
|
+
updateRadioAriaAttributes
|
|
15
17
|
}
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Adds screen reader accessibility to checkboxes. Updates the aria attributes of the checkbox. Checkbox element must possess the following aria attributes; aria-
|
|
2
|
+
* Adds screen reader accessibility to checkboxes. Updates the aria attributes of the checkbox. Checkbox element must possess the following aria attributes; aria-checked and aria-label.
|
|
3
3
|
* @param {CheckboxStates[]} checkboxStates Array of objects containing checkboxes state information
|
|
4
4
|
* @param {string} checkboxesClass The shared class of all the checkboxes
|
|
5
5
|
* @param {number} currentPressedCheckboxIndex Index of the currently checked or unchecked checkbox
|
|
@@ -9,10 +9,11 @@ export function updateCheckboxAriaAttributes(checkboxStates, checkboxesClass, cu
|
|
|
9
9
|
if (!allCheckboxes) {
|
|
10
10
|
throw new Error('Invalid checkboxes class provided.');
|
|
11
11
|
}
|
|
12
|
+
;
|
|
12
13
|
allCheckboxes.forEach(function (checkbox, index) {
|
|
13
14
|
if (index === currentPressedCheckboxIndex) {
|
|
14
|
-
checkbox.setAttribute("aria-
|
|
15
|
-
checkbox.setAttribute("aria-label", checkboxStates[index].
|
|
15
|
+
checkbox.setAttribute("aria-checked", checkboxStates[index].checked ? 'true' : 'false');
|
|
16
|
+
checkbox.setAttribute("aria-label", checkboxStates[index].checked ? checkboxStates[index].checkedAriaLabel : checkboxStates[index].uncheckedAriaLabel);
|
|
16
17
|
}
|
|
17
18
|
});
|
|
18
19
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Adds screen reader accessibility to checkboxes. Updates the aria attributes of the checkbox. Checkbox element must possess the following aria attributes; aria-
|
|
2
|
+
* Adds screen reader accessibility to checkboxes. Updates the aria attributes of the checkbox. Checkbox element must possess the following aria attributes; aria-checked and aria-label.
|
|
3
3
|
* @param {CheckboxStates[]} checkboxStates Array of objects containing checkboxes state information
|
|
4
4
|
* @param {string} checkboxesClass The shared class of all the checkboxes
|
|
5
5
|
* @param {number} currentPressedCheckboxIndex Index of the currently checked or unchecked checkbox
|
|
@@ -12,12 +12,12 @@ export function updateCheckboxAriaAttributes(checkboxStates: CheckboxStates[], c
|
|
|
12
12
|
|
|
13
13
|
if ( !allCheckboxes) {
|
|
14
14
|
throw new Error('Invalid checkboxes class provided.');
|
|
15
|
-
}
|
|
15
|
+
};
|
|
16
16
|
|
|
17
17
|
allCheckboxes.forEach((checkbox, index) => {
|
|
18
18
|
if (index === currentPressedCheckboxIndex) {
|
|
19
|
-
checkbox.setAttribute("aria-
|
|
20
|
-
checkbox.setAttribute("aria-label", checkboxStates[index].
|
|
19
|
+
checkbox.setAttribute("aria-checked", checkboxStates[index].checked ? 'true' : 'false');
|
|
20
|
+
checkbox.setAttribute("aria-label", checkboxStates[index].checked ? checkboxStates[index].checkedAriaLabel : checkboxStates[index].uncheckedAriaLabel);
|
|
21
21
|
}
|
|
22
22
|
});
|
|
23
23
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adds screen reader accessibility to radio buttons. Updates the aria attributes of the radio button. Radio element must possess the following aria attributes; aria-checked and aria-label.
|
|
3
|
+
* @param {RadioStates[]} radioStates Array of objects containing radio buttons state information
|
|
4
|
+
* @param {string} radiosClass The shared class of all the radio buttons
|
|
5
|
+
* @param {number} currentPressedRadioIndex Index of the currently checked or unchecked radio button
|
|
6
|
+
*/
|
|
7
|
+
export function updateRadioAriaAttributes(radioStates, radiosClass, currentPressedRadioIndex) {
|
|
8
|
+
var allRadios = Array.from(document.querySelectorAll(".".concat(radiosClass)));
|
|
9
|
+
if (!allRadios) {
|
|
10
|
+
throw new Error('Invalid radios class provided.');
|
|
11
|
+
}
|
|
12
|
+
allRadios.forEach(function (radio, index) {
|
|
13
|
+
if (index === currentPressedRadioIndex) {
|
|
14
|
+
radio.setAttribute("aria-checked", radioStates[index].checked ? 'true' : 'false');
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
if (radio.getAttribute("aria-checked") === "true") {
|
|
18
|
+
radio.setAttribute("aria-checked", 'false');
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
radio.setAttribute("aria-label", radioStates[index].checked ? radioStates[index].checkedAriaLabel : radioStates[index].uncheckedAriaLabel);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adds screen reader accessibility to radio buttons. Updates the aria attributes of the radio button. Radio element must possess the following aria attributes; aria-checked and aria-label.
|
|
3
|
+
* @param {RadioStates[]} radioStates Array of objects containing radio buttons state information
|
|
4
|
+
* @param {string} radiosClass The shared class of all the radio buttons
|
|
5
|
+
* @param {number} currentPressedRadioIndex Index of the currently checked or unchecked radio button
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { HTMLElement, RadioStates } from "../../Types";
|
|
9
|
+
|
|
10
|
+
export function updateRadioAriaAttributes(radioStates: RadioStates[], radiosClass: string, currentPressedRadioIndex: number): void {
|
|
11
|
+
const allRadios: HTMLElement[] = Array.from(document.querySelectorAll(`.${radiosClass}`));
|
|
12
|
+
|
|
13
|
+
if ( !allRadios) {
|
|
14
|
+
throw new Error('Invalid radios class provided.');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
allRadios.forEach((radio, index) => {
|
|
18
|
+
if (index === currentPressedRadioIndex) {
|
|
19
|
+
radio.setAttribute("aria-checked", radioStates[index].checked ? 'true' : 'false');
|
|
20
|
+
} else {
|
|
21
|
+
if(radio.getAttribute("aria-checked") === "true") {
|
|
22
|
+
radio.setAttribute("aria-checked", 'false');
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
radio.setAttribute("aria-label", radioStates[index].checked ? radioStates[index].checkedAriaLabel : radioStates[index].uncheckedAriaLabel);
|
|
26
|
+
});
|
|
27
|
+
}
|