aria-ease 1.4.0 → 1.4.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 +16 -16
- package/aria-ease.d.ts +6 -6
- package/package.json +1 -1
- package/src/block/makeBlockAccessible.js +3 -3
- package/src/block/makeBlockAccessible.ts +3 -3
- package/src/menu/cleanUpMenuEventListeners.js +2 -2
- package/src/menu/cleanUpMenuEventListeners.ts +2 -2
- package/src/menu/makeMenuAccessible.js +3 -3
- package/src/menu/makeMenuAccessible.ts +3 -3
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ The package currently has support for 5 components: accordions, blocks, checkbox
|
|
|
14
14
|
|
|
15
15
|
Add accessibility to menu: menu can be a dropdown, side menu, slide navigation e.t.c. Basically any component that toggles display and has a list of interactive children items. The function creates a focus trap within the menu and focus can be navigated using the arrow keys. The escape key also closes the menu and returns the focus back to the trigger.
|
|
16
16
|
|
|
17
|
-
The makeMenuAccessible function takes two string arguments; the id of the menu, the class name of the children
|
|
17
|
+
The makeMenuAccessible function takes two string arguments; the id of the menu, the class name of the children items of the menu. And should only be invoked after the menu has become visible or added to the DOM. When the menu is visible the first item of the menu is in focus and focus can be navigated using the Arrow keys. The Space and Enter keys clicks the menu item if they are buttons or links element. The Escape key closes the menu, and returns the focus back to the button that toggles the menu. The Tab key exits the trap.
|
|
18
18
|
|
|
19
19
|
The updateMenuTriggerAriaAttributes function take two string arguments; the id of the menu trigger, and the aria-label that will replace the current one in the DOM. Behind the scene the aria-expanded and aria-attributes are also updated based on the visibility of the menu.
|
|
20
20
|
|
|
@@ -27,13 +27,13 @@ const MenuExample = () => {
|
|
|
27
27
|
const toggleMenuDisplay = (event) => {
|
|
28
28
|
if (event.type === 'mousedown' || (event.type === 'keydown' && (event.key === 'Enter' || event.key === ' '))) {
|
|
29
29
|
event.preventDefault();
|
|
30
|
-
const menu = document.querySelector('#
|
|
30
|
+
const menu = document.querySelector('#menu-div');
|
|
31
31
|
if (getComputedStyle(menu).display === 'none') {
|
|
32
32
|
menu.style.display = 'block';
|
|
33
|
-
makeMenuAccessible('
|
|
33
|
+
makeMenuAccessible('menu-div', 'menu-interactive-items');
|
|
34
34
|
updateMenuTriggerAriaAttributes('display-button', 'Close profile menu');
|
|
35
35
|
} else {
|
|
36
|
-
cleanUpMenuEventListeners('
|
|
36
|
+
cleanUpMenuEventListeners('menu-div', 'menu-interactive-items');
|
|
37
37
|
menu.style.display = 'none';
|
|
38
38
|
updateMenuTriggerAriaAttributes('display-button', 'Close profile menu');
|
|
39
39
|
}
|
|
@@ -48,17 +48,17 @@ const MenuExample = () => {
|
|
|
48
48
|
aria-haspopup={true}
|
|
49
49
|
role="button"
|
|
50
50
|
aria-expanded={false}
|
|
51
|
-
aria-controls="
|
|
51
|
+
aria-controls="menu-div"
|
|
52
52
|
aria-label="Display profile menu"
|
|
53
|
-
className='menu-example-trigger-button
|
|
53
|
+
className='menu-example-trigger-button'
|
|
54
54
|
onKeyDown={toggleMenuDisplay}
|
|
55
55
|
>
|
|
56
56
|
Display Example Menu
|
|
57
57
|
</button>
|
|
58
|
-
<div id="
|
|
59
|
-
<button role="menuitem" className="
|
|
60
|
-
<button role="menuitem" className="
|
|
61
|
-
<button role="menuitem" className="
|
|
58
|
+
<div id="menu-div" role="menu" aria-labelledby="display-button" style={{display: 'none', marginTop: '5px'}}>
|
|
59
|
+
<button role="menuitem" className="menu-interactive-items" onClick={() => alert('Button clicked')}>One</button>
|
|
60
|
+
<button role="menuitem" className="menu-interactive-items" onClick={() => alert('Button clicked')}>Two</button>
|
|
61
|
+
<button role="menuitem" className="menu-interactive-items" onClick={() => alert('Button clicked')}>Three</button>
|
|
62
62
|
</div>
|
|
63
63
|
</div>
|
|
64
64
|
)
|
|
@@ -69,7 +69,7 @@ export default MenuExample
|
|
|
69
69
|
|
|
70
70
|
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.
|
|
71
71
|
|
|
72
|
-
The makeBlockAccessible function takes two string arguments; the id of the block main div, and the class name of the children
|
|
72
|
+
The makeBlockAccessible function takes two string arguments; the id of the block main div, and the class name of the children items of the div. The function should be called on page render, so the event listeners get activated. On click of a button, the clicked button gets focused and the focus can be navigated using the arrow keys.
|
|
73
73
|
|
|
74
74
|
#### Usage
|
|
75
75
|
|
|
@@ -79,16 +79,16 @@ import { makeBlockAccessible } from "aria-ease"
|
|
|
79
79
|
|
|
80
80
|
const BlockExample = () => {
|
|
81
81
|
useEffect(() => {
|
|
82
|
-
const accessibleBlock = makeBlockAccessible('
|
|
82
|
+
const accessibleBlock = makeBlockAccessible('block-div', 'block-div-interactive-items');
|
|
83
83
|
return accessibleBlock;
|
|
84
84
|
},[])
|
|
85
85
|
|
|
86
86
|
return (
|
|
87
87
|
<div>
|
|
88
|
-
<div id="
|
|
89
|
-
<button className="
|
|
90
|
-
<button className="
|
|
91
|
-
<button className="
|
|
88
|
+
<div id="block-div">
|
|
89
|
+
<button className="block-div-interactive-items">One</button>
|
|
90
|
+
<button className="block-div-interactive-items">Two</button>
|
|
91
|
+
<button className="block-div-interactive-items">Three</button>
|
|
92
92
|
</div>
|
|
93
93
|
</div>
|
|
94
94
|
)
|
package/aria-ease.d.ts
CHANGED
|
@@ -8,16 +8,16 @@ declare module 'aria-ease' {
|
|
|
8
8
|
/**
|
|
9
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.
|
|
10
10
|
* @param {string} menuId - The id of the menu.
|
|
11
|
-
* @param {string}
|
|
11
|
+
* @param {string} menuItemsClass - The class of the items that are children of the menu.
|
|
12
12
|
*/
|
|
13
|
-
function makeMenuAccessible(menuId: string,
|
|
13
|
+
function makeMenuAccessible(menuId: string, menuItemsClass: string): void;
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* Adds keyboard interaction to block. The block traps focus and can be interacted with using the keyboard.
|
|
17
17
|
* @param {string} blockId - The id of the block container.
|
|
18
|
-
* @param {string}
|
|
18
|
+
* @param {string} blockItemsClass - The class of the individual block items.
|
|
19
19
|
*/
|
|
20
|
-
function makeBlockAccessible(blockId: string,
|
|
20
|
+
function makeBlockAccessible(blockId: string, blockItemsClass: string);
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* Updates the aria attributes of the menu trigger button. Trigger button element must possess the following aria attributes; aria-expanded and aria-label.
|
|
@@ -29,9 +29,9 @@ declare module 'aria-ease' {
|
|
|
29
29
|
/**
|
|
30
30
|
* Cleans up the event listeners that were added to childen items of the menu, to prevent memory leak.
|
|
31
31
|
* @param {string} menuId The id of the menu
|
|
32
|
-
* @param {string}
|
|
32
|
+
* @param {string} menuItemsClass The class of the items that are children of the menu
|
|
33
33
|
*/
|
|
34
|
-
function cleanUpMenuEventListeners(menuId: string,
|
|
34
|
+
function cleanUpMenuEventListeners(menuId: string, menuItemsClass: string): void;
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
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 and aria-label.
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
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}
|
|
4
|
+
* @param {string} blockItemsClass The shared class of the items that are children of thes block
|
|
5
5
|
*/
|
|
6
6
|
import { handleKeyPress } from '../handleKeyPress';
|
|
7
7
|
var eventListenersAdded = new Set();
|
|
8
|
-
export function makeBlockAccessible(blockId,
|
|
8
|
+
export function makeBlockAccessible(blockId, blockItemsClass) {
|
|
9
9
|
var blockDiv = document.querySelector("#".concat(blockId));
|
|
10
|
-
var blockItems = blockDiv.querySelectorAll(".".concat(
|
|
10
|
+
var blockItems = blockDiv.querySelectorAll(".".concat(blockItemsClass));
|
|
11
11
|
blockItems.forEach(function (blockItem, blockItemIndex) {
|
|
12
12
|
if (!eventListenersAdded.has(blockItem)) {
|
|
13
13
|
eventListenersAdded.add(blockItem);
|
|
@@ -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}
|
|
4
|
+
* @param {string} blockItemsClass The shared class of the items that are children of thes block
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { HTMLElement, NodeListOfHTMLElement } from "../../Types"
|
|
@@ -9,9 +9,9 @@ import { handleKeyPress } from '../handleKeyPress';
|
|
|
9
9
|
|
|
10
10
|
let eventListenersAdded: Set<HTMLElement> = new Set();
|
|
11
11
|
|
|
12
|
-
export function makeBlockAccessible(blockId: string,
|
|
12
|
+
export function makeBlockAccessible(blockId: string, blockItemsClass: string) {
|
|
13
13
|
const blockDiv: HTMLElement = document.querySelector(`#${blockId}`) as HTMLElement
|
|
14
|
-
const blockItems: NodeListOfHTMLElement = blockDiv.querySelectorAll(`.${
|
|
14
|
+
const blockItems: NodeListOfHTMLElement = blockDiv.querySelectorAll(`.${blockItemsClass}`)
|
|
15
15
|
|
|
16
16
|
blockItems.forEach((blockItem: HTMLElement, blockItemIndex: number): void => {
|
|
17
17
|
if (!eventListenersAdded.has(blockItem)) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { handleKeyPress } from "../handleKeyPress";
|
|
2
|
-
export function cleanUpMenuEventListeners(menuId,
|
|
2
|
+
export function cleanUpMenuEventListeners(menuId, menuItemsClass) {
|
|
3
3
|
var menuDiv = document.querySelector("#".concat(menuId));
|
|
4
|
-
var menuItems = menuDiv.querySelectorAll(".".concat(
|
|
4
|
+
var menuItems = menuDiv.querySelectorAll(".".concat(menuItemsClass));
|
|
5
5
|
var triggerId = menuDiv.getAttribute('aria-labelledby');
|
|
6
6
|
var triggerButton = document.querySelector("#".concat(triggerId));
|
|
7
7
|
menuItems.forEach(function (menuItem, menuItemIndex) {
|
|
@@ -2,9 +2,9 @@ import { NodeListOfHTMLElement } from "../../Types"
|
|
|
2
2
|
import { handleKeyPress } from "../handleKeyPress"
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
export function cleanUpMenuEventListeners(menuId: string,
|
|
5
|
+
export function cleanUpMenuEventListeners(menuId: string, menuItemsClass: string): void {
|
|
6
6
|
const menuDiv: HTMLElement = document.querySelector(`#${menuId}`) as HTMLElement
|
|
7
|
-
const menuItems: NodeListOfHTMLElement = menuDiv.querySelectorAll(`.${
|
|
7
|
+
const menuItems: NodeListOfHTMLElement = menuDiv.querySelectorAll(`.${menuItemsClass}`)
|
|
8
8
|
|
|
9
9
|
const triggerId: string = menuDiv.getAttribute('aria-labelledby') as string
|
|
10
10
|
const triggerButton: HTMLElement = document.querySelector(`#${triggerId}`) as HTMLElement
|
|
@@ -1,13 +1,13 @@
|
|
|
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}
|
|
4
|
+
* @param {string} menuItemsClass 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();
|
|
8
|
-
export function makeMenuAccessible(menuId,
|
|
8
|
+
export function makeMenuAccessible(menuId, menuItemsClass) {
|
|
9
9
|
var menuDiv = document.querySelector("#".concat(menuId));
|
|
10
|
-
var menuItems = menuDiv.querySelectorAll(".".concat(
|
|
10
|
+
var menuItems = menuDiv.querySelectorAll(".".concat(menuItemsClass));
|
|
11
11
|
var triggerId = menuDiv.getAttribute('aria-labelledby');
|
|
12
12
|
var triggerButton = document.querySelector("#".concat(triggerId));
|
|
13
13
|
var menuClosedStateAriaLabel = triggerButton.getAttribute('aria-label');
|
|
@@ -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}
|
|
4
|
+
* @param {string} menuItemsClass The shared class of the items that are children of the menu
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { HTMLElement, NodeListOfHTMLElement } from '../../Types'
|
|
@@ -9,9 +9,9 @@ import { handleKeyPress } from '../handleKeyPress';
|
|
|
9
9
|
|
|
10
10
|
let eventListenersAdded: Set<HTMLElement> = new Set();
|
|
11
11
|
|
|
12
|
-
export function makeMenuAccessible(menuId: string,
|
|
12
|
+
export function makeMenuAccessible(menuId: string, menuItemsClass: string): void {
|
|
13
13
|
const menuDiv: HTMLElement = document.querySelector(`#${menuId}`) as HTMLElement;
|
|
14
|
-
const menuItems: NodeListOfHTMLElement = menuDiv.querySelectorAll(`.${
|
|
14
|
+
const menuItems: NodeListOfHTMLElement = menuDiv.querySelectorAll(`.${menuItemsClass}`);
|
|
15
15
|
|
|
16
16
|
const triggerId: string = menuDiv.getAttribute('aria-labelledby') as string;
|
|
17
17
|
const triggerButton: HTMLElement = document.querySelector(`#${triggerId}`) as HTMLElement;
|