aria-ease 1.3.0 → 1.3.2
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 +8 -7
- package/Types.d.ts +9 -0
- package/aria-ease.d.ts +15 -4
- package/index.js +3 -1
- package/package.json +1 -1
- package/src/accordion/updateAccordionTriggerAriaAttributes.js +23 -0
- package/src/accordion/updateAccordionTriggerAriaAttributes.ts +28 -0
- package/src/block/makeBlockAccessible.js +1 -1
- package/src/block/makeBlockAccessible.ts +1 -1
- package/src/menu/makeMenuAccessible.js +1 -1
- package/src/menu/makeMenuAccessible.ts +1 -1
- package/src/menu/updateMenuTriggerAriaAttributes.js +1 -1
- package/src/menu/updateMenuTriggerAriaAttributes.ts +1 -1
package/README.md
CHANGED
|
@@ -19,9 +19,9 @@ The updateMenuTriggerAriaAttributes function take two string arguments; the id o
|
|
|
19
19
|
```
|
|
20
20
|
import { makeMenuAccessible, updateMenuTriggerAriaAttributes, cleanUpMenuEventListeners } from 'aria-ease'
|
|
21
21
|
|
|
22
|
-
const
|
|
22
|
+
const MenuExample = () => {
|
|
23
23
|
const toggleMenuDisplay = (event) => {
|
|
24
|
-
if (event.key === 'Enter' || event.key === ' ') {
|
|
24
|
+
if (event.type === 'mousedown' || (event.type === 'keydown' && (event.key === 'Enter' || event.key === ' '))) {
|
|
25
25
|
event.preventDefault();
|
|
26
26
|
const menu = document.querySelector('#custom-menu');
|
|
27
27
|
if (getComputedStyle(menu).display === 'none') {
|
|
@@ -35,17 +35,18 @@ const HomeExampleMenu = () => {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
|
+
|
|
38
39
|
return (
|
|
39
40
|
<div>
|
|
40
41
|
<button
|
|
41
42
|
id="display-button"
|
|
42
|
-
|
|
43
|
+
onMouseDown={toggleMenuDisplay}
|
|
43
44
|
aria-haspopup={true}
|
|
44
45
|
aria-pressed={false}
|
|
45
46
|
aria-expanded={false}
|
|
46
47
|
aria-controls="custom-menu"
|
|
47
48
|
aria-label="Display profile menu"
|
|
48
|
-
className='
|
|
49
|
+
className='menu-example-trigger-button block-interactive'
|
|
49
50
|
onKeyDown={toggleMenuDisplay}
|
|
50
51
|
>
|
|
51
52
|
Display Example Menu
|
|
@@ -59,7 +60,7 @@ const HomeExampleMenu = () => {
|
|
|
59
60
|
)
|
|
60
61
|
}
|
|
61
62
|
|
|
62
|
-
export default
|
|
63
|
+
export default MenuExample
|
|
63
64
|
```
|
|
64
65
|
|
|
65
66
|
Add accessibility to block: block can be entire web page body, tabs, interactive sliders and carousels e.t.c. Basically any component that is permanently displayed and has a list of related interractive children items. The function creates a focus trap within the block and the focus can be navigated using the arrow keys.
|
|
@@ -72,7 +73,7 @@ The makeBlockAccessible function takes two string arguments; the id of the block
|
|
|
72
73
|
import { useEffect } from 'react'
|
|
73
74
|
import { makeBlockAccessible } from "aria-ease"
|
|
74
75
|
|
|
75
|
-
const
|
|
76
|
+
const BlockExample = () => {
|
|
76
77
|
useEffect(() => {
|
|
77
78
|
const cleanUp = makeBlockAccessible('custom-tab', 'custom-tab-item')
|
|
78
79
|
|
|
@@ -90,7 +91,7 @@ const App = () => {
|
|
|
90
91
|
)
|
|
91
92
|
}
|
|
92
93
|
|
|
93
|
-
export default
|
|
94
|
+
export default BlockExample
|
|
94
95
|
```
|
|
95
96
|
|
|
96
97
|
### P.S.
|
package/Types.d.ts
CHANGED
|
@@ -2,8 +2,17 @@ declare global {
|
|
|
2
2
|
type HTMLElement = Element;
|
|
3
3
|
type NodeListOf<HTMLElement> = Iterable<HTMLElement>;
|
|
4
4
|
}
|
|
5
|
+
|
|
6
|
+
interface AccordionStates {
|
|
7
|
+
id: string;
|
|
8
|
+
display: boolean;
|
|
9
|
+
openedAriaLabel: string;
|
|
10
|
+
closedAriaLabel: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
5
13
|
|
|
6
14
|
export {
|
|
7
15
|
HTMLElement,
|
|
8
16
|
NodeListOfHTMLElement,
|
|
17
|
+
AccordionStates
|
|
9
18
|
};
|
package/aria-ease.d.ts
CHANGED
|
@@ -1,26 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Declares the module 'aria-ease' and includes type information and JSDoc comments.
|
|
3
3
|
*/
|
|
4
|
+
|
|
5
|
+
import { AccordionStates } from "./Types";
|
|
6
|
+
|
|
4
7
|
declare module 'aria-ease' {
|
|
5
8
|
/**
|
|
6
9
|
* Adds keyboard interaction to toggle menu. The menu traps focus and can be interacted with using the keyboard. The first item of the menu has focus when menu appears.
|
|
7
10
|
* @param {string} menuId - The id of the menu.
|
|
8
11
|
* @param {string} menuItemClass - The class of the items that are children of the menu.
|
|
9
|
-
|
|
12
|
+
*/
|
|
10
13
|
function makeMenuAccessible(menuId: string, menuItemClass: string): void;
|
|
11
14
|
|
|
12
15
|
/**
|
|
13
16
|
* Adds keyboard interaction to block. The block traps focus and can be interacted with using the keyboard.
|
|
14
17
|
* @param {string} blockId - The id of the block container.
|
|
15
18
|
* @param {string} blockItemClass - The class of the individual block items.
|
|
16
|
-
|
|
19
|
+
*/
|
|
17
20
|
function makeBlockAccessible(blockId: string, blockItemClass: string);
|
|
18
21
|
|
|
19
22
|
/**
|
|
20
23
|
* Updates the aria attributes of the menu trigger button. Trigger button element must possess the following aria attributes; aria-expanded, aria-pressed, aria-label.
|
|
21
24
|
* @param {string} triggerId The id of the trigger button that toggles the menu.
|
|
22
25
|
* @param {string} ariaLabel The aria-label to be updated.
|
|
23
|
-
|
|
26
|
+
*/
|
|
24
27
|
function updateMenuTriggerAriaAttributes(triggerId: string, ariaLabel: string): void;
|
|
25
28
|
|
|
26
29
|
/**
|
|
@@ -29,7 +32,15 @@ declare module 'aria-ease' {
|
|
|
29
32
|
* @param {string} menuItemClass The class of the items that are children of the menu
|
|
30
33
|
*/
|
|
31
34
|
function cleanUpMenuEventListeners(menuId: string, menuItemClass: string): void;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Adds screen reader accessibility to accordions. Updates the aria attributes of the accordion trigger button. Trigger button element must possess the following aria attributes; aria-expanded, aria-pressed, aria-label.
|
|
38
|
+
* @param {AccordionStates[]} accordionStates Array of objects containing accordion state information
|
|
39
|
+
* @param {string} accordionsClass The shared class of all the accordion triggers
|
|
40
|
+
* @param {number} currentClickedTriggerIndex Index of the currently clicked accordion trigger
|
|
41
|
+
*/
|
|
42
|
+
function updateAccordionTriggerAriaAttributes(accordionStates: AccordionStates[], accordionsClass: string, currentClickedTriggerIndex: number): void;
|
|
32
43
|
|
|
33
|
-
export { makeMenuAccessible, makeBlockAccessible, updateMenuTriggerAriaAttributes, cleanUpMenuEventListeners };
|
|
44
|
+
export { makeMenuAccessible, makeBlockAccessible, updateMenuTriggerAriaAttributes, cleanUpMenuEventListeners, updateAccordionTriggerAriaAttributes };
|
|
34
45
|
}
|
|
35
46
|
|
package/index.js
CHANGED
|
@@ -2,10 +2,12 @@ import { makeMenuAccessible } from './src/menu/makeMenuAccessible.js'
|
|
|
2
2
|
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
|
+
import { updateAccordionTriggerAriaAttributes } from './src/accordion/updateAccordionTriggerAriaAttributes.js'
|
|
5
6
|
|
|
6
7
|
export {
|
|
7
8
|
makeMenuAccessible,
|
|
8
9
|
makeBlockAccessible,
|
|
9
10
|
updateMenuTriggerAriaAttributes,
|
|
10
|
-
cleanUpMenuEventListeners
|
|
11
|
+
cleanUpMenuEventListeners,
|
|
12
|
+
updateAccordionTriggerAriaAttributes
|
|
11
13
|
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adds screen reader accessibility to accordions. Updates the aria attributes of the accordion trigger button. Trigger button element must possess the following aria attributes; aria-expanded, aria-pressed, aria-label.
|
|
3
|
+
* @param {AccordionStates[]} accordionStates Array of objects containing accordions state information
|
|
4
|
+
* @param {string} accordionsClass The shared class of all the accordion triggers
|
|
5
|
+
* @param {number} currentClickedTriggerIndex Index of the currently clicked accordion trigger
|
|
6
|
+
*/
|
|
7
|
+
export function updateAccordionTriggerAriaAttributes(accordionStates, accordionsClass, currentClickedTriggerIndex) {
|
|
8
|
+
var allAccordionTrigger = Array.from(document.querySelectorAll(".".concat(accordionsClass)));
|
|
9
|
+
if (!allAccordionTrigger) {
|
|
10
|
+
throw new Error('Invalid trigger class provided.');
|
|
11
|
+
}
|
|
12
|
+
allAccordionTrigger.forEach(function (trigger, index) {
|
|
13
|
+
if (index === currentClickedTriggerIndex) {
|
|
14
|
+
trigger.setAttribute("aria-expanded", accordionStates[index].display ? 'true' : 'false');
|
|
15
|
+
trigger.setAttribute("aria-pressed", accordionStates[index].display ? 'true' : 'false');
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
trigger.setAttribute("aria-expanded", 'false');
|
|
19
|
+
trigger.setAttribute("aria-pressed", 'false');
|
|
20
|
+
}
|
|
21
|
+
trigger.setAttribute("aria-label", accordionStates[index].display ? accordionStates[index].openedAriaLabel : accordionStates[index].closedAriaLabel);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adds screen reader accessibility to accordions. Updates the aria attributes of the accordion trigger button. Trigger button element must possess the following aria attributes; aria-expanded, aria-pressed, aria-label.
|
|
3
|
+
* @param {AccordionStates[]} accordionStates Array of objects containing accordions state information
|
|
4
|
+
* @param {string} accordionsClass The shared class of all the accordion triggers
|
|
5
|
+
* @param {number} currentClickedTriggerIndex Index of the currently clicked accordion trigger
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { HTMLElement, AccordionStates } from "../../Types";
|
|
9
|
+
|
|
10
|
+
export function updateAccordionTriggerAriaAttributes(accordionStates: AccordionStates[], accordionsClass: string, currentClickedTriggerIndex: number): void {
|
|
11
|
+
const allAccordionTrigger: HTMLElement[] = Array.from(document.querySelectorAll(`.${accordionsClass}`));
|
|
12
|
+
|
|
13
|
+
if ( !allAccordionTrigger) {
|
|
14
|
+
throw new Error('Invalid trigger class provided.');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
allAccordionTrigger.forEach((trigger, index) => {
|
|
18
|
+
if (index === currentClickedTriggerIndex) {
|
|
19
|
+
trigger.setAttribute("aria-expanded", accordionStates[index].display ? 'true' : 'false');
|
|
20
|
+
trigger.setAttribute("aria-pressed", accordionStates[index].display ? 'true' : 'false');
|
|
21
|
+
} else {
|
|
22
|
+
trigger.setAttribute("aria-expanded", 'false');
|
|
23
|
+
trigger.setAttribute("aria-pressed", 'false');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
trigger.setAttribute("aria-label", accordionStates[index].display ? accordionStates[index].openedAriaLabel : accordionStates[index].closedAriaLabel);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Adds keyboard interaction to block. The block traps focus and can be interacted with using the keyboard.
|
|
3
3
|
* @param {string} blockId The id of the block
|
|
4
|
-
* @param {string} blockItemClass The class of the items that are children of the block
|
|
4
|
+
* @param {string} blockItemClass The shared class of the items that are children of the block
|
|
5
5
|
*/
|
|
6
6
|
import { handleKeyPress } from '../handleKeyPress';
|
|
7
7
|
var eventListenersAdded = new Set();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Adds keyboard interaction to block. The block traps focus and can be interacted with using the keyboard.
|
|
3
3
|
* @param {string} blockId The id of the block
|
|
4
|
-
* @param {string} blockItemClass The class of the items that are children of the block
|
|
4
|
+
* @param {string} blockItemClass The shared class of the items that are children of the block
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { HTMLElement, NodeListOfHTMLElement } from "../../Types"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Adds keyboard interaction to toggle menu. The menu traps focus and can be interacted with using the keyboard. The first item of the menu has focus when menu appears.
|
|
3
3
|
* @param {string} menuId The id of the menu
|
|
4
|
-
* @param {string} menuItemClass The class of the items that are children of the menu
|
|
4
|
+
* @param {string} menuItemClass The shared class of the items that are children of the menu
|
|
5
5
|
*/
|
|
6
6
|
import { handleKeyPress } from '../handleKeyPress';
|
|
7
7
|
var eventListenersAdded = new Set();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Adds keyboard interaction to toggle menu. The menu traps focus and can be interacted with using the keyboard. The first item of the menu has focus when menu appears.
|
|
3
3
|
* @param {string} menuId The id of the menu
|
|
4
|
-
* @param {string} menuItemClass The class of the items that are children of the menu
|
|
4
|
+
* @param {string} menuItemClass The shared class of the items that are children of the menu
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { HTMLElement, NodeListOfHTMLElement } from '../../Types'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Updates the aria attributes of the menu trigger button. Trigger button element must possess the following aria attributes; aria-expanded, aria-pressed, aria-label.
|
|
2
|
+
* Adds screen reader accessibility to menus. Updates the aria attributes of the menu trigger button. Trigger button element must possess the following aria attributes; aria-expanded, aria-pressed, aria-label.
|
|
3
3
|
* @param {string} triggerId The id of the trigger button that toggles the menu.
|
|
4
4
|
* @param {string} ariaLabel The aria-label to be updated.
|
|
5
5
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Updates the aria attributes of the menu trigger button. Trigger button element must possess the following aria attributes; aria-expanded, aria-pressed, aria-label.
|
|
2
|
+
* Adds screen reader accessibility to menus. Updates the aria attributes of the menu trigger button. Trigger button element must possess the following aria attributes; aria-expanded, aria-pressed, aria-label.
|
|
3
3
|
* @param {string} triggerId The id of the trigger button that toggles the menu.
|
|
4
4
|
* @param {string} ariaLabel The aria-label to be updated.
|
|
5
5
|
*/
|