aria-ease 1.2.8 → 1.3.0
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
CHANGED
|
@@ -17,21 +17,24 @@ The updateMenuTriggerAriaAttributes function take two string arguments; the id o
|
|
|
17
17
|
#### Usage
|
|
18
18
|
|
|
19
19
|
```
|
|
20
|
-
import { makeMenuAccessible, updateMenuTriggerAriaAttributes } from
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
const toggleMenuDisplay = ()
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
menu
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
20
|
+
import { makeMenuAccessible, updateMenuTriggerAriaAttributes, cleanUpMenuEventListeners } from 'aria-ease'
|
|
21
|
+
|
|
22
|
+
const HomeExampleMenu = () => {
|
|
23
|
+
const toggleMenuDisplay = (event) => {
|
|
24
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
25
|
+
event.preventDefault();
|
|
26
|
+
const menu = document.querySelector('#custom-menu');
|
|
27
|
+
if (getComputedStyle(menu).display === 'none') {
|
|
28
|
+
menu.style.display = 'block';
|
|
29
|
+
makeMenuAccessible('custom-menu', 'profile-menu-item');
|
|
30
|
+
updateMenuTriggerAriaAttributes('display-button', 'Hide profile menu');
|
|
31
|
+
} else {
|
|
32
|
+
cleanUpMenuEventListeners('custom-menu', 'profile-menu-item');
|
|
33
|
+
menu.style.display = 'none';
|
|
34
|
+
updateMenuTriggerAriaAttributes('display-button', 'Display profile menu');
|
|
35
|
+
}
|
|
32
36
|
}
|
|
33
|
-
}
|
|
34
|
-
|
|
37
|
+
};
|
|
35
38
|
return (
|
|
36
39
|
<div>
|
|
37
40
|
<button
|
|
@@ -42,19 +45,21 @@ const App = () => {
|
|
|
42
45
|
aria-expanded={false}
|
|
43
46
|
aria-controls="custom-menu"
|
|
44
47
|
aria-label="Display profile menu"
|
|
48
|
+
className='home-menu-example-trigger-button block-interactive'
|
|
49
|
+
onKeyDown={toggleMenuDisplay}
|
|
45
50
|
>
|
|
46
|
-
Display
|
|
51
|
+
Display Example Menu
|
|
47
52
|
</button>
|
|
48
53
|
<div id="custom-menu" role="menu" aria-labelledby="display-button" style={{display: 'none', marginTop: '5px'}}>
|
|
49
|
-
<button role="menuitem" className="profile-menu-item">One</button>
|
|
50
|
-
<button role="menuitem" className="profile-menu-item">Two</button>
|
|
51
|
-
<button role="menuitem" className="profile-menu-item">Three</button>
|
|
54
|
+
<button role="menuitem" className="profile-menu-item" onClick={() => alert('Button clicked')}>One</button>
|
|
55
|
+
<button role="menuitem" className="profile-menu-item" onClick={() => alert('Button clicked')}>Two</button>
|
|
56
|
+
<button role="menuitem" className="profile-menu-item" onClick={() => alert('Button clicked')}>Three</button>
|
|
52
57
|
</div>
|
|
53
58
|
</div>
|
|
54
59
|
)
|
|
55
60
|
}
|
|
56
61
|
|
|
57
|
-
export default
|
|
62
|
+
export default HomeExampleMenu
|
|
58
63
|
```
|
|
59
64
|
|
|
60
65
|
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.
|
|
@@ -69,7 +74,9 @@ import { makeBlockAccessible } from "aria-ease"
|
|
|
69
74
|
|
|
70
75
|
const App = () => {
|
|
71
76
|
useEffect(() => {
|
|
72
|
-
makeBlockAccessible('custom-tab', 'custom-tab-item')
|
|
77
|
+
const cleanUp = makeBlockAccessible('custom-tab', 'custom-tab-item')
|
|
78
|
+
|
|
79
|
+
return cleanUp
|
|
73
80
|
},[])
|
|
74
81
|
|
|
75
82
|
return (
|
package/aria-ease.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ declare module 'aria-ease' {
|
|
|
14
14
|
* @param {string} blockId - The id of the block container.
|
|
15
15
|
* @param {string} blockItemClass - The class of the individual block items.
|
|
16
16
|
*/
|
|
17
|
-
function makeBlockAccessible(blockId: string, blockItemClass: string)
|
|
17
|
+
function makeBlockAccessible(blockId: string, blockItemClass: string);
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* Updates the aria attributes of the menu trigger button. Trigger button element must possess the following aria attributes; aria-expanded, aria-pressed, aria-label.
|
package/package.json
CHANGED
|
@@ -14,4 +14,12 @@ export function makeBlockAccessible(blockId, blockItemClass) {
|
|
|
14
14
|
blockItem.addEventListener('keydown', function (event) { return handleKeyPress(event, blockItems, blockItemIndex); });
|
|
15
15
|
}
|
|
16
16
|
});
|
|
17
|
+
return function cleanUpBlockEventListeners() {
|
|
18
|
+
blockItems.forEach(function (blockItem, blockItemIndex) {
|
|
19
|
+
if (eventListenersAdded.has(blockItem)) {
|
|
20
|
+
blockItem.removeEventListener('keydown', function (event) { return handleKeyPress(event, blockItems, blockItemIndex); });
|
|
21
|
+
eventListenersAdded.delete(blockItem);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
};
|
|
17
25
|
}
|
|
@@ -9,15 +9,23 @@ import { handleKeyPress } from '../handleKeyPress';
|
|
|
9
9
|
|
|
10
10
|
let eventListenersAdded: Set<HTMLElement> = new Set();
|
|
11
11
|
|
|
12
|
-
export function makeBlockAccessible(blockId: string, blockItemClass: string)
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
export function makeBlockAccessible(blockId: string, blockItemClass: string) {
|
|
13
|
+
const blockDiv: HTMLElement = document.querySelector(`#${blockId}`) as HTMLElement
|
|
14
|
+
const blockItems: NodeListOfHTMLElement = blockDiv.querySelectorAll(`.${blockItemClass}`)
|
|
15
15
|
|
|
16
|
+
blockItems.forEach((blockItem: HTMLElement, blockItemIndex: number): void => {
|
|
17
|
+
if (!eventListenersAdded.has(blockItem)) {
|
|
18
|
+
eventListenersAdded.add(blockItem);
|
|
19
|
+
blockItem.addEventListener('keydown', (event: KeyboardEvent) => handleKeyPress(event, blockItems, blockItemIndex));
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
return function cleanUpBlockEventListeners(): void {
|
|
16
24
|
blockItems.forEach((blockItem: HTMLElement, blockItemIndex: number): void => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
25
|
+
if (eventListenersAdded.has(blockItem)) {
|
|
26
|
+
blockItem.removeEventListener('keydown', (event: KeyboardEvent) => handleKeyPress(event, blockItems, blockItemIndex));
|
|
27
|
+
eventListenersAdded.delete(blockItem);
|
|
28
|
+
}
|
|
21
29
|
});
|
|
22
|
-
|
|
30
|
+
};
|
|
23
31
|
}
|
|
@@ -10,13 +10,11 @@ export function makeMenuAccessible(menuId, menuItemClass) {
|
|
|
10
10
|
var menuItems = menuDiv.querySelectorAll(".".concat(menuItemClass));
|
|
11
11
|
var triggerId = menuDiv.getAttribute('aria-labelledby');
|
|
12
12
|
var triggerButton = document.querySelector("#".concat(triggerId));
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
});
|
|
21
|
-
}
|
|
13
|
+
menuItems.item(0).focus();
|
|
14
|
+
menuItems.forEach(function (menuItem, menuItemIndex) {
|
|
15
|
+
if (!eventListenersAdded.has(menuItem)) {
|
|
16
|
+
eventListenersAdded.add(menuItem);
|
|
17
|
+
menuItem.addEventListener('keydown', function (event) { return handleKeyPress(event, menuItems, menuItemIndex, menuDiv, triggerButton); });
|
|
18
|
+
}
|
|
19
|
+
});
|
|
22
20
|
}
|
|
@@ -16,13 +16,11 @@ export function makeMenuAccessible(menuId: string, menuItemClass: string): void
|
|
|
16
16
|
const triggerId: string = menuDiv.getAttribute('aria-labelledby') as string
|
|
17
17
|
const triggerButton: HTMLElement = document.querySelector(`#${triggerId}`) as HTMLElement
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
})
|
|
27
|
-
}
|
|
19
|
+
menuItems.item(0).focus();
|
|
20
|
+
menuItems.forEach((menuItem: HTMLElement, menuItemIndex: number): void => {
|
|
21
|
+
if (!eventListenersAdded.has(menuItem)) {
|
|
22
|
+
eventListenersAdded.add(menuItem);
|
|
23
|
+
menuItem.addEventListener('keydown', (event: KeyboardEvent): void => handleKeyPress(event, menuItems, menuItemIndex, menuDiv, triggerButton))
|
|
24
|
+
}
|
|
25
|
+
})
|
|
28
26
|
}
|