aria-ease 1.4.3 → 1.4.5
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 +77 -31
- package/package.json +9 -3
- package/src/block/makeBlockAccessible.js +6 -0
- package/src/block/makeBlockAccessible.ts +8 -1
- package/src/handleKeyPress.js +3 -0
- package/src/handleKeyPress.ts +4 -0
- package/src/menu/cleanUpMenuEventListeners.js +12 -0
- package/src/menu/cleanUpMenuEventListeners.ts +14 -0
- package/src/menu/makeMenuAccessible.js +24 -7
- package/src/menu/makeMenuAccessible.ts +26 -8
- package/src/menu/updateMenuTriggerAriaAttributes.js +6 -0
- package/src/menu/updateMenuTriggerAriaAttributes.ts +6 -0
package/README.md
CHANGED
|
@@ -10,9 +10,11 @@ Out of the box accessibility utility package to develop production ready applica
|
|
|
10
10
|
|
|
11
11
|
## Features
|
|
12
12
|
|
|
13
|
+
Don't spend hours wrestling with accessibility code. Aria-Ease provides pre-built, customizable functions that help you integrate accessibility seamlessly into your development workflow. It simplifies the process of adding essential accessibility features to common UI components like menus, accordions, and checkboxes, e.t.c. This allows you to focus on building great user experiences for everyone.
|
|
14
|
+
|
|
13
15
|
The package currently has support for 5 components: accordions, blocks, checkboxes, menus, radio buttons
|
|
14
16
|
|
|
15
|
-
Add accessibility to menu: menu can be a dropdown,
|
|
17
|
+
Add accessibility to menu: menu can be a dropdown, slide navigation menu, 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
18
|
|
|
17
19
|
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
20
|
|
|
@@ -20,22 +22,29 @@ The updateMenuTriggerAriaAttributes function take two string arguments; the id o
|
|
|
20
22
|
|
|
21
23
|
#### Usage
|
|
22
24
|
|
|
23
|
-
```
|
|
24
|
-
import {
|
|
25
|
+
```javascript
|
|
26
|
+
import {
|
|
27
|
+
makeMenuAccessible,
|
|
28
|
+
updateMenuTriggerAriaAttributes,
|
|
29
|
+
cleanUpMenuEventListeners,
|
|
30
|
+
} from "aria-ease";
|
|
25
31
|
|
|
26
32
|
const MenuExample = () => {
|
|
27
33
|
const toggleMenuDisplay = (event) => {
|
|
28
|
-
if (
|
|
34
|
+
if (
|
|
35
|
+
event.type === "mousedown" ||
|
|
36
|
+
(event.type === "keydown" && (event.key === "Enter" || event.key === " "))
|
|
37
|
+
) {
|
|
29
38
|
event.preventDefault();
|
|
30
|
-
const menu = document.querySelector(
|
|
31
|
-
if (getComputedStyle(menu).display ===
|
|
32
|
-
menu.style.display =
|
|
33
|
-
makeMenuAccessible(
|
|
34
|
-
updateMenuTriggerAriaAttributes(
|
|
39
|
+
const menu = document.querySelector("#menu-div");
|
|
40
|
+
if (getComputedStyle(menu).display === "none") {
|
|
41
|
+
menu.style.display = "block";
|
|
42
|
+
makeMenuAccessible("menu-div", "menu-interactive-items");
|
|
43
|
+
updateMenuTriggerAriaAttributes("display-button", "Close profile menu");
|
|
35
44
|
} else {
|
|
36
|
-
cleanUpMenuEventListeners(
|
|
37
|
-
menu.style.display =
|
|
38
|
-
updateMenuTriggerAriaAttributes(
|
|
45
|
+
cleanUpMenuEventListeners("menu-div", "menu-interactive-items");
|
|
46
|
+
menu.style.display = "none";
|
|
47
|
+
updateMenuTriggerAriaAttributes("display-button", "Open profile menu");
|
|
39
48
|
}
|
|
40
49
|
}
|
|
41
50
|
};
|
|
@@ -50,38 +59,64 @@ const MenuExample = () => {
|
|
|
50
59
|
aria-expanded={false}
|
|
51
60
|
aria-controls="menu-div"
|
|
52
61
|
aria-label="Display profile menu"
|
|
53
|
-
className=
|
|
62
|
+
className="menu-example-trigger-button"
|
|
54
63
|
onKeyDown={toggleMenuDisplay}
|
|
55
64
|
>
|
|
56
65
|
Display Example Menu
|
|
57
66
|
</button>
|
|
58
|
-
<div
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
67
|
+
<div
|
|
68
|
+
id="menu-div"
|
|
69
|
+
role="menu"
|
|
70
|
+
aria-labelledby="display-button"
|
|
71
|
+
style={{ display: "none", marginTop: "5px" }}
|
|
72
|
+
>
|
|
73
|
+
<button
|
|
74
|
+
role="menuitem"
|
|
75
|
+
className="menu-interactive-items"
|
|
76
|
+
onClick={() => alert("Button clicked")}
|
|
77
|
+
>
|
|
78
|
+
One
|
|
79
|
+
</button>
|
|
80
|
+
<button
|
|
81
|
+
role="menuitem"
|
|
82
|
+
className="menu-interactive-items"
|
|
83
|
+
onClick={() => alert("Button clicked")}
|
|
84
|
+
>
|
|
85
|
+
Two
|
|
86
|
+
</button>
|
|
87
|
+
<button
|
|
88
|
+
role="menuitem"
|
|
89
|
+
className="menu-interactive-items"
|
|
90
|
+
onClick={() => alert("Button clicked")}
|
|
91
|
+
>
|
|
92
|
+
Three
|
|
93
|
+
</button>
|
|
62
94
|
</div>
|
|
63
95
|
</div>
|
|
64
|
-
)
|
|
65
|
-
}
|
|
96
|
+
);
|
|
97
|
+
};
|
|
66
98
|
|
|
67
|
-
export default MenuExample
|
|
99
|
+
export default MenuExample;
|
|
68
100
|
```
|
|
69
101
|
|
|
70
|
-
Add accessibility to block: block can be entire web page body,
|
|
102
|
+
Add accessibility to block: block can be tabs, entire web page body, interactive sliders and carousels e.t.c. Basically any 'block' 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. Using the entire page as a block, the page serves as a focus trap, and the page can be navigated from one interactive item to another from the top of the page to the bottom and cycle back.
|
|
71
103
|
|
|
72
104
|
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
105
|
|
|
74
106
|
#### Usage
|
|
75
107
|
|
|
76
|
-
```
|
|
77
|
-
import { useEffect } from
|
|
78
|
-
import { makeBlockAccessible } from "aria-ease"
|
|
108
|
+
```javascript
|
|
109
|
+
import { useEffect } from "react";
|
|
110
|
+
import { makeBlockAccessible } from "aria-ease";
|
|
79
111
|
|
|
80
112
|
const BlockExample = () => {
|
|
81
113
|
useEffect(() => {
|
|
82
|
-
const accessibleBlock = makeBlockAccessible(
|
|
114
|
+
const accessibleBlock = makeBlockAccessible(
|
|
115
|
+
"block-div",
|
|
116
|
+
"block-div-interactive-items"
|
|
117
|
+
);
|
|
83
118
|
return accessibleBlock;
|
|
84
|
-
},[])
|
|
119
|
+
}, []);
|
|
85
120
|
|
|
86
121
|
return (
|
|
87
122
|
<div>
|
|
@@ -91,10 +126,10 @@ const BlockExample = () => {
|
|
|
91
126
|
<button className="block-div-interactive-items">Three</button>
|
|
92
127
|
</div>
|
|
93
128
|
</div>
|
|
94
|
-
)
|
|
95
|
-
}
|
|
129
|
+
);
|
|
130
|
+
};
|
|
96
131
|
|
|
97
|
-
export default BlockExample
|
|
132
|
+
export default BlockExample;
|
|
98
133
|
```
|
|
99
134
|
|
|
100
135
|
[Check out more features/functionality in the docs](https://aria-ease.vercel.app/docs)
|
|
@@ -105,6 +140,17 @@ Find a bug? Head on over to [issue page](https://github.com/aria-ease/aria-ease/
|
|
|
105
140
|
|
|
106
141
|
Aria-ease is open-source software by [Isaac Victor](https://isaacvictordev.web.app/)
|
|
107
142
|
|
|
108
|
-
### P.S.
|
|
143
|
+
### P.S. Don't Forget About Focus Styling!
|
|
109
144
|
|
|
110
|
-
|
|
145
|
+
While Aria-Ease significantly aids in making your web applications more accessible, it's essential to remember that visual cues play a crucial role in accessibility. This is especially true for keyboard navigation, where focus styling indicates which element is currently selectable or active.
|
|
146
|
+
|
|
147
|
+
Without clear focus styling, users who rely on keyboard navigation may find it challenging to determine which part of the page they are interacting with. Therefore, we strongly encourage you to implement distinct focus styles for interactive elements on your web pages.
|
|
148
|
+
|
|
149
|
+
Here's a simple CSS example to enhance focus visibility:
|
|
150
|
+
|
|
151
|
+
```css
|
|
152
|
+
:focus {
|
|
153
|
+
outline: 2px solid rgba(0, 91, 211, 1); /* Blue outline for high contrast */
|
|
154
|
+
outline-offset: 1px;
|
|
155
|
+
}
|
|
156
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aria-ease",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.5",
|
|
4
4
|
"description": "Out-of-the-box accessibility utility package to develop production ready applications.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -11,14 +11,20 @@
|
|
|
11
11
|
"url": "git+https://github.com/aria-ease/aria-ease.git"
|
|
12
12
|
},
|
|
13
13
|
"keywords": [
|
|
14
|
+
"a11y",
|
|
14
15
|
"ARIA",
|
|
15
|
-
"Accessibility"
|
|
16
|
+
"Accessibility",
|
|
17
|
+
"Assistive Technology",
|
|
18
|
+
"Keyboard Navigation",
|
|
19
|
+
"Focus Management",
|
|
20
|
+
"WCAG Guidelines",
|
|
21
|
+
"Inclusive Design"
|
|
16
22
|
],
|
|
17
23
|
"author": "Isaac Akinduyile",
|
|
18
24
|
"license": "ISC",
|
|
19
25
|
"bugs": {
|
|
20
26
|
"url": "https://github.com/aria-ease/aria-ease/issues"
|
|
21
27
|
},
|
|
22
|
-
"homepage": "https://aria-ease.vercel.app/",
|
|
28
|
+
"homepage": "https://aria-ease.vercel.app/docs",
|
|
23
29
|
"types": "./aria-ease.d.ts"
|
|
24
30
|
}
|
|
@@ -7,7 +7,13 @@ import { handleKeyPress } from '../handleKeyPress';
|
|
|
7
7
|
var eventListenersAdded = new Set();
|
|
8
8
|
export function makeBlockAccessible(blockId, blockItemsClass) {
|
|
9
9
|
var blockDiv = document.querySelector("#".concat(blockId));
|
|
10
|
+
if (!blockDiv) {
|
|
11
|
+
throw new Error('Invalid block main div id provided.');
|
|
12
|
+
}
|
|
10
13
|
var blockItems = blockDiv.querySelectorAll(".".concat(blockItemsClass));
|
|
14
|
+
if (!blockItems) {
|
|
15
|
+
throw new Error('Invalid block items class provided.');
|
|
16
|
+
}
|
|
11
17
|
blockItems.forEach(function (blockItem, blockItemIndex) {
|
|
12
18
|
if (!eventListenersAdded.has(blockItem)) {
|
|
13
19
|
eventListenersAdded.add(blockItem);
|
|
@@ -11,7 +11,14 @@ let eventListenersAdded: Set<HTMLElement> = new Set();
|
|
|
11
11
|
|
|
12
12
|
export function makeBlockAccessible(blockId: string, blockItemsClass: string) {
|
|
13
13
|
const blockDiv: HTMLElement = document.querySelector(`#${blockId}`) as HTMLElement
|
|
14
|
-
|
|
14
|
+
if(!blockDiv) {
|
|
15
|
+
throw new Error('Invalid block main div id provided.');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const blockItems: NodeListOfHTMLElement = blockDiv.querySelectorAll(`.${blockItemsClass}`);
|
|
19
|
+
if(!blockItems) {
|
|
20
|
+
throw new Error('Invalid block items class provided.');
|
|
21
|
+
}
|
|
15
22
|
|
|
16
23
|
blockItems.forEach((blockItem: HTMLElement, blockItemIndex: number): void => {
|
|
17
24
|
if (!eventListenersAdded.has(blockItem)) {
|
package/src/handleKeyPress.js
CHANGED
|
@@ -2,6 +2,9 @@ import { updateMenuTriggerAriaAttributes } from "./menu/updateMenuTriggerAriaAtt
|
|
|
2
2
|
function handleMenuEscapeKeyPress(menuElement, menuTriggerButton, menuClosedStateAriaLabel) {
|
|
3
3
|
menuElement.style.display = 'none';
|
|
4
4
|
var menuTriggerButtonId = menuTriggerButton.getAttribute('id');
|
|
5
|
+
if (!menuTriggerButtonId) {
|
|
6
|
+
throw new Error("Menu trigger button does not have id attribute");
|
|
7
|
+
}
|
|
5
8
|
updateMenuTriggerAriaAttributes("".concat(menuTriggerButtonId), "".concat(menuClosedStateAriaLabel));
|
|
6
9
|
}
|
|
7
10
|
export function handleKeyPress(event, elementItems, elementItemIndex, menuElementDiv, triggerButton, menuClosedStateAriaLabel) {
|
package/src/handleKeyPress.ts
CHANGED
|
@@ -4,6 +4,10 @@ import { updateMenuTriggerAriaAttributes } from "./menu/updateMenuTriggerAriaAtt
|
|
|
4
4
|
function handleMenuEscapeKeyPress(menuElement: HTMLElement, menuTriggerButton: HTMLElement, menuClosedStateAriaLabel: string) {
|
|
5
5
|
menuElement.style.display = 'none';
|
|
6
6
|
const menuTriggerButtonId = menuTriggerButton.getAttribute('id');
|
|
7
|
+
if(!menuTriggerButtonId) {
|
|
8
|
+
throw new Error("Menu trigger button does not have id attribute")
|
|
9
|
+
}
|
|
10
|
+
|
|
7
11
|
updateMenuTriggerAriaAttributes(`${menuTriggerButtonId}`, `${menuClosedStateAriaLabel}`)
|
|
8
12
|
}
|
|
9
13
|
|
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
import { handleKeyPress } from "../handleKeyPress";
|
|
2
2
|
export function cleanUpMenuEventListeners(menuId, menuItemsClass) {
|
|
3
3
|
var menuDiv = document.querySelector("#".concat(menuId));
|
|
4
|
+
if (!menuDiv) {
|
|
5
|
+
throw new Error("Invalid menu div id provided");
|
|
6
|
+
}
|
|
4
7
|
var menuItems = menuDiv.querySelectorAll(".".concat(menuItemsClass));
|
|
8
|
+
if (!menuItems) {
|
|
9
|
+
throw new Error("Invalid menu items class provided");
|
|
10
|
+
}
|
|
5
11
|
var triggerId = menuDiv.getAttribute('aria-labelledby');
|
|
12
|
+
if (!triggerId) {
|
|
13
|
+
throw new Error("Menu div doesn't contain aria-labelledby attribute");
|
|
14
|
+
}
|
|
6
15
|
var triggerButton = document.querySelector("#".concat(triggerId));
|
|
16
|
+
if (!triggerButton) {
|
|
17
|
+
throw new Error("Menu trigger button id does not match menu div aria-labelledby attribute");
|
|
18
|
+
}
|
|
7
19
|
menuItems.forEach(function (menuItem, menuItemIndex) {
|
|
8
20
|
menuItem.removeEventListener('keydown', function (event) { return handleKeyPress(event, menuItems, menuItemIndex, menuDiv, triggerButton); });
|
|
9
21
|
});
|
|
@@ -4,10 +4,24 @@ import { handleKeyPress } from "../handleKeyPress"
|
|
|
4
4
|
|
|
5
5
|
export function cleanUpMenuEventListeners(menuId: string, menuItemsClass: string): void {
|
|
6
6
|
const menuDiv: HTMLElement = document.querySelector(`#${menuId}`) as HTMLElement
|
|
7
|
+
if(!menuDiv) {
|
|
8
|
+
throw new Error("Invalid menu div id provided")
|
|
9
|
+
}
|
|
10
|
+
|
|
7
11
|
const menuItems: NodeListOfHTMLElement = menuDiv.querySelectorAll(`.${menuItemsClass}`)
|
|
12
|
+
if(!menuItems) {
|
|
13
|
+
throw new Error("Invalid menu items class provided")
|
|
14
|
+
}
|
|
8
15
|
|
|
9
16
|
const triggerId: string = menuDiv.getAttribute('aria-labelledby') as string
|
|
17
|
+
if(!triggerId) {
|
|
18
|
+
throw new Error("Menu div doesn't contain aria-labelledby attribute")
|
|
19
|
+
}
|
|
20
|
+
|
|
10
21
|
const triggerButton: HTMLElement = document.querySelector(`#${triggerId}`) as HTMLElement
|
|
22
|
+
if(!triggerButton) {
|
|
23
|
+
throw new Error("Menu trigger button id does not match menu div aria-labelledby attribute")
|
|
24
|
+
}
|
|
11
25
|
|
|
12
26
|
menuItems.forEach((menuItem: HTMLElement, menuItemIndex: number): void => {
|
|
13
27
|
menuItem.removeEventListener('keydown', (event: KeyboardEvent): void => handleKeyPress(event, menuItems, menuItemIndex, menuDiv, triggerButton));
|
|
@@ -7,15 +7,32 @@ import { handleKeyPress } from '../handleKeyPress';
|
|
|
7
7
|
var eventListenersAdded = new Set();
|
|
8
8
|
export function makeMenuAccessible(menuId, menuItemsClass) {
|
|
9
9
|
var menuDiv = document.querySelector("#".concat(menuId));
|
|
10
|
+
if (!menuDiv) {
|
|
11
|
+
throw new Error("Invalid menu div id provided");
|
|
12
|
+
}
|
|
10
13
|
var menuItems = menuDiv.querySelectorAll(".".concat(menuItemsClass));
|
|
11
14
|
var triggerId = menuDiv.getAttribute('aria-labelledby');
|
|
15
|
+
if (!triggerId) {
|
|
16
|
+
throw new Error("Menu div doesn't contain aria-labelledby attribute");
|
|
17
|
+
}
|
|
12
18
|
var triggerButton = document.querySelector("#".concat(triggerId));
|
|
19
|
+
if (!triggerButton) {
|
|
20
|
+
throw new Error("Menu trigger button id does not match menu div aria-labelledby attribute");
|
|
21
|
+
}
|
|
13
22
|
var menuClosedStateAriaLabel = triggerButton.getAttribute('aria-label');
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
23
|
+
if (!menuClosedStateAriaLabel) {
|
|
24
|
+
throw new Error("Menu trigger button does not have initial aria-label");
|
|
25
|
+
}
|
|
26
|
+
if (menuItems && menuItems.length > 0) {
|
|
27
|
+
menuItems.item(0).focus();
|
|
28
|
+
menuItems.forEach(function (menuItem, menuItemIndex) {
|
|
29
|
+
if (!eventListenersAdded.has(menuItem)) {
|
|
30
|
+
eventListenersAdded.add(menuItem);
|
|
31
|
+
menuItem.addEventListener('keydown', function (event) { return handleKeyPress(event, menuItems, menuItemIndex, menuDiv, triggerButton, menuClosedStateAriaLabel); });
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
throw new Error("Invalid menu items class provided");
|
|
37
|
+
}
|
|
21
38
|
}
|
|
@@ -11,18 +11,36 @@ let eventListenersAdded: Set<HTMLElement> = new Set();
|
|
|
11
11
|
|
|
12
12
|
export function makeMenuAccessible(menuId: string, menuItemsClass: string): void {
|
|
13
13
|
const menuDiv: HTMLElement = document.querySelector(`#${menuId}`) as HTMLElement;
|
|
14
|
-
|
|
14
|
+
if(!menuDiv) {
|
|
15
|
+
throw new Error("Invalid menu div id provided")
|
|
16
|
+
}
|
|
15
17
|
|
|
18
|
+
const menuItems: NodeListOfHTMLElement = menuDiv.querySelectorAll(`.${menuItemsClass}`);
|
|
19
|
+
|
|
16
20
|
const triggerId: string = menuDiv.getAttribute('aria-labelledby') as string;
|
|
21
|
+
if(!triggerId) {
|
|
22
|
+
throw new Error("Menu div doesn't contain aria-labelledby attribute")
|
|
23
|
+
}
|
|
24
|
+
|
|
17
25
|
const triggerButton: HTMLElement = document.querySelector(`#${triggerId}`) as HTMLElement;
|
|
26
|
+
if(!triggerButton) {
|
|
27
|
+
throw new Error("Menu trigger button id does not match menu div aria-labelledby attribute")
|
|
28
|
+
}
|
|
18
29
|
|
|
19
30
|
const menuClosedStateAriaLabel: string = triggerButton.getAttribute('aria-label') as string;
|
|
31
|
+
if(!menuClosedStateAriaLabel) {
|
|
32
|
+
throw new Error("Menu trigger button does not have initial aria-label")
|
|
33
|
+
}
|
|
20
34
|
|
|
21
|
-
menuItems.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
eventListenersAdded.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
35
|
+
if(menuItems && menuItems.length > 0) {
|
|
36
|
+
menuItems.item(0).focus();
|
|
37
|
+
menuItems.forEach((menuItem: HTMLElement, menuItemIndex: number): void => {
|
|
38
|
+
if (!eventListenersAdded.has(menuItem)) {
|
|
39
|
+
eventListenersAdded.add(menuItem);
|
|
40
|
+
menuItem.addEventListener('keydown', (event: KeyboardEvent): void => handleKeyPress(event, menuItems, menuItemIndex, menuDiv, triggerButton, menuClosedStateAriaLabel));
|
|
41
|
+
}
|
|
42
|
+
})
|
|
43
|
+
} else {
|
|
44
|
+
throw new Error("Invalid menu items class provided")
|
|
45
|
+
}
|
|
28
46
|
}
|
|
@@ -5,7 +5,13 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export function updateMenuTriggerAriaAttributes(triggerId, ariaLabel) {
|
|
7
7
|
var triggerButton = document.querySelector("#".concat(triggerId));
|
|
8
|
+
if (!triggerButton) {
|
|
9
|
+
throw new Error("Invalid menu trigger button id provided");
|
|
10
|
+
}
|
|
8
11
|
var currentAriaExpandedState = triggerButton.getAttribute('aria-expanded');
|
|
12
|
+
if (!currentAriaExpandedState) {
|
|
13
|
+
throw new Error("Menu trigger button does not have aria-expanded attribute");
|
|
14
|
+
}
|
|
9
15
|
function triggerOpen(ariaLabel) {
|
|
10
16
|
triggerButton.setAttribute('aria-expanded', 'true');
|
|
11
17
|
triggerButton.setAttribute('aria-label', ariaLabel);
|
|
@@ -8,8 +8,14 @@ import { HTMLElement } from "../../Types";
|
|
|
8
8
|
|
|
9
9
|
export function updateMenuTriggerAriaAttributes(triggerId: string, ariaLabel: string): void {
|
|
10
10
|
const triggerButton: HTMLElement = document.querySelector(`#${triggerId}`) as HTMLElement
|
|
11
|
+
if(!triggerButton) {
|
|
12
|
+
throw new Error("Invalid menu trigger button id provided")
|
|
13
|
+
}
|
|
11
14
|
|
|
12
15
|
const currentAriaExpandedState: string = triggerButton.getAttribute('aria-expanded') as string
|
|
16
|
+
if(!currentAriaExpandedState) {
|
|
17
|
+
throw new Error("Menu trigger button does not have aria-expanded attribute")
|
|
18
|
+
}
|
|
13
19
|
|
|
14
20
|
function triggerOpen(ariaLabel: string): void {
|
|
15
21
|
triggerButton.setAttribute('aria-expanded', 'true')
|