aria-ease 2.0.0 → 2.0.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 +19 -111
- package/dist/index.cjs +320 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +115 -0
- package/dist/index.d.mts +140 -0
- package/dist/index.d.ts +115 -0
- package/dist/index.js +314 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +110 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +36 -5
- package/CONTRIBUTION-GUIDELINES.md +0 -21
- package/Types.d.ts +0 -33
- package/aria-ease.d.ts +0 -100
- package/index.js +0 -25
- package/src/accordion/updateAccordionTriggerAriaAttributes.js +0 -21
- package/src/accordion/updateAccordionTriggerAriaAttributes.ts +0 -25
- package/src/block/makeBlockAccessible.js +0 -31
- package/src/block/makeBlockAccessible.ts +0 -38
- package/src/checkbox/group/updateGroupCheckboxesAriaAttributes.js +0 -19
- package/src/checkbox/group/updateGroupCheckboxesAriaAttributes.ts +0 -23
- package/src/checkbox/single/updateSingleCheckboxAriaAttribute.js +0 -27
- package/src/checkbox/single/updateSingleCheckboxAriaAttribute.ts +0 -34
- package/src/handleKeyPress.js +0 -83
- package/src/handleKeyPress.ts +0 -82
- package/src/menu/cleanUpMenuEventListeners.js +0 -22
- package/src/menu/cleanUpMenuEventListeners.ts +0 -29
- package/src/menu/makeMenuAccessible.js +0 -38
- package/src/menu/makeMenuAccessible.ts +0 -46
- package/src/menu/updateMenuTriggerAriaAttributes.js +0 -26
- package/src/menu/updateMenuTriggerAriaAttributes.ts +0 -33
- package/src/radio/group/updateGroupRadiosAriaAttributes.js +0 -22
- package/src/radio/group/updateGroupRadiosAriaAttributes.ts +0 -26
- package/src/radio/single/updateSingleRadioAriaAttribute.js +0 -24
- package/src/radio/single/updateSingleRadioAriaAttribute.ts +0 -34
- package/src/toggle/group/updateGroupTogglesAriaAttributes.js +0 -17
- package/src/toggle/group/updateGroupTogglesAriaAttributes.ts +0 -22
- package/src/toggle/single/updateSingleToggleAriaAttribute.js +0 -23
- package/src/toggle/single/updateSingleToggleAriaAttribute.ts +0 -31
- package/tsconfig.json +0 -17
package/README.md
CHANGED
|
@@ -16,123 +16,31 @@ The package currently has support for 6 components: accordions, blocks, checkbox
|
|
|
16
16
|
|
|
17
17
|
Add accessibility to menu: menu can be a dropdown, combo box, 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.
|
|
18
18
|
|
|
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.
|
|
20
|
-
|
|
21
|
-
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.
|
|
22
|
-
|
|
23
|
-
#### Usage
|
|
24
|
-
|
|
25
|
-
```javascript
|
|
26
|
-
import {
|
|
27
|
-
makeMenuAccessible,
|
|
28
|
-
updateMenuTriggerAriaAttributes,
|
|
29
|
-
cleanUpMenuEventListeners,
|
|
30
|
-
} from "aria-ease";
|
|
31
|
-
|
|
32
|
-
const MenuExample = () => {
|
|
33
|
-
const toggleMenuDisplay = (event) => {
|
|
34
|
-
if (
|
|
35
|
-
event.type === "mousedown" ||
|
|
36
|
-
(event.type === "keydown" && (event.key === "Enter" || event.key === " "))
|
|
37
|
-
) {
|
|
38
|
-
event.preventDefault();
|
|
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");
|
|
44
|
-
} else {
|
|
45
|
-
cleanUpMenuEventListeners("menu-div", "menu-interactive-items");
|
|
46
|
-
menu.style.display = "none";
|
|
47
|
-
updateMenuTriggerAriaAttributes("display-button", "Open profile menu");
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
return (
|
|
53
|
-
<div>
|
|
54
|
-
<button
|
|
55
|
-
id="display-button"
|
|
56
|
-
onMouseDown={toggleMenuDisplay}
|
|
57
|
-
aria-haspopup={true}
|
|
58
|
-
role="button"
|
|
59
|
-
aria-expanded={false}
|
|
60
|
-
aria-controls="menu-div"
|
|
61
|
-
aria-label="Display profile menu"
|
|
62
|
-
className="menu-example-trigger-button"
|
|
63
|
-
onKeyDown={toggleMenuDisplay}
|
|
64
|
-
>
|
|
65
|
-
Display Example Menu
|
|
66
|
-
</button>
|
|
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>
|
|
94
|
-
</div>
|
|
95
|
-
</div>
|
|
96
|
-
);
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
export default MenuExample;
|
|
100
|
-
```
|
|
101
|
-
|
|
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 interactive 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 cycles back to the top.
|
|
103
|
-
|
|
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.
|
|
105
|
-
|
|
106
19
|
#### Usage
|
|
107
20
|
|
|
108
21
|
```javascript
|
|
109
|
-
import {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
</div>
|
|
128
|
-
</div>
|
|
129
|
-
);
|
|
22
|
+
import { Menu } from "aria-ease";
|
|
23
|
+
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
menuRef.current = Menu.makeMenuAccessible({
|
|
26
|
+
menuId: "menu-div",
|
|
27
|
+
menuElementsClass: "profile-menu-items",
|
|
28
|
+
triggerId: "display-button",
|
|
29
|
+
});
|
|
30
|
+
}, []);
|
|
31
|
+
|
|
32
|
+
const toggleMenuDisplay = (event) => {
|
|
33
|
+
event.preventDefault();
|
|
34
|
+
const menuDiv = document.querySelector("#menu-div");
|
|
35
|
+
if (getComputedStyle(menuDiv).display === "none") {
|
|
36
|
+
menuRef.current.openMenu();
|
|
37
|
+
} else {
|
|
38
|
+
menuRef.current.closeMenu();
|
|
39
|
+
}
|
|
130
40
|
};
|
|
131
|
-
|
|
132
|
-
export default BlockExample;
|
|
133
41
|
```
|
|
134
42
|
|
|
135
|
-
[Check out more features/functionality in the docs](https://ariaease.
|
|
43
|
+
[Check out more features/functionality in the docs](https://ariaease.web.app/docs)
|
|
136
44
|
|
|
137
45
|
[Start contributing on GitHub](https://github.com/aria-ease/aria-ease)
|
|
138
46
|
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __export = function(target, all) {
|
|
4
|
+
for(var name in all)__defProp(target, name, {
|
|
5
|
+
get: all[name],
|
|
6
|
+
enumerable: true
|
|
7
|
+
});
|
|
8
|
+
};
|
|
9
|
+
// src/accordion/index.ts
|
|
10
|
+
var accordion_exports = {};
|
|
11
|
+
__export(accordion_exports, {
|
|
12
|
+
updateAccordionTriggerAriaAttributes: function() {
|
|
13
|
+
return updateAccordionTriggerAriaAttributes;
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
// src/accordion/src/updateAccordionTriggerAriaAttributes/updateAccordionTriggerAriaAttributes.ts
|
|
17
|
+
function updateAccordionTriggerAriaAttributes(accordionId, accordionTriggersClass, accordionStates, clickedTriggerIndex) {
|
|
18
|
+
var accordionDiv = document.querySelector("#".concat(accordionId));
|
|
19
|
+
if (!accordionDiv) {
|
|
20
|
+
throw new Error("Invalid accordion main div id provided.");
|
|
21
|
+
}
|
|
22
|
+
var accordionItems = Array.from(accordionDiv.querySelectorAll(".".concat(accordionTriggersClass)));
|
|
23
|
+
if (accordionItems.length === 0) {
|
|
24
|
+
throw new Error("Invalid accordion items shared class provided.");
|
|
25
|
+
}
|
|
26
|
+
if (accordionItems.length !== accordionStates.length) {
|
|
27
|
+
throw new Error("Accordion state/DOM length mismatch: found ".concat(accordionItems.length, " triggers, but got ").concat(accordionStates.length, " state objects."));
|
|
28
|
+
}
|
|
29
|
+
accordionItems.forEach(function(accordionItem, index) {
|
|
30
|
+
var state = accordionStates[index];
|
|
31
|
+
var expanded = accordionItem.getAttribute("aria-expanded");
|
|
32
|
+
var shouldBeExpanded = index === clickedTriggerIndex ? state.display ? "true" : "false" : "false";
|
|
33
|
+
if (expanded && expanded !== shouldBeExpanded) {
|
|
34
|
+
accordionItem.setAttribute("aria-expanded", shouldBeExpanded);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
// src/block/index.ts
|
|
39
|
+
var block_exports = {};
|
|
40
|
+
__export(block_exports, {
|
|
41
|
+
makeBlockAccessible: function() {
|
|
42
|
+
return makeBlockAccessible;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
// src/utils/handleKeyPress/handleKeyPress.ts
|
|
46
|
+
function isTextInput(el) {
|
|
47
|
+
if (el.tagName !== "INPUT") return false;
|
|
48
|
+
var type = el.type;
|
|
49
|
+
return [
|
|
50
|
+
"text",
|
|
51
|
+
"email",
|
|
52
|
+
"password",
|
|
53
|
+
"tel",
|
|
54
|
+
"number"
|
|
55
|
+
].includes(type);
|
|
56
|
+
}
|
|
57
|
+
function isTextArea(el) {
|
|
58
|
+
return el.tagName === "TEXTAREA";
|
|
59
|
+
}
|
|
60
|
+
function isNativeButton(el) {
|
|
61
|
+
return el.tagName === "BUTTON" || el.tagName === "INPUT" && [
|
|
62
|
+
"button",
|
|
63
|
+
"submit",
|
|
64
|
+
"reset"
|
|
65
|
+
].includes(el.type);
|
|
66
|
+
}
|
|
67
|
+
function isLink(el) {
|
|
68
|
+
return el.tagName === "A";
|
|
69
|
+
}
|
|
70
|
+
function moveFocus(elementItems, currentIndex, direction) {
|
|
71
|
+
var len = elementItems.length;
|
|
72
|
+
var nextIndex = (currentIndex + direction + len) % len;
|
|
73
|
+
elementItems.item(nextIndex).focus();
|
|
74
|
+
}
|
|
75
|
+
function isClickableButNotSemantic(el) {
|
|
76
|
+
return el.getAttribute("data-custom-click") !== null || el.getAttribute("data-custom-click") !== void 0;
|
|
77
|
+
}
|
|
78
|
+
function handleMenuEscapeKeyPress(menuElement, menuTriggerButton) {
|
|
79
|
+
menuElement.style.display = "none";
|
|
80
|
+
var menuTriggerButtonId = menuTriggerButton.getAttribute("id");
|
|
81
|
+
if (!menuTriggerButtonId) {
|
|
82
|
+
throw new Error("Menu trigger button does not have id attribute");
|
|
83
|
+
}
|
|
84
|
+
menuTriggerButton.setAttribute("aria-expanded", "false");
|
|
85
|
+
}
|
|
86
|
+
function handleKeyPress(event, elementItems, elementItemIndex, menuElementDiv, triggerButton) {
|
|
87
|
+
var currentEl = elementItems.item(elementItemIndex);
|
|
88
|
+
switch(event.key){
|
|
89
|
+
case "ArrowUp":
|
|
90
|
+
case "ArrowLeft":
|
|
91
|
+
{
|
|
92
|
+
if (!isTextInput(currentEl) && !isTextArea(currentEl)) {
|
|
93
|
+
event.preventDefault();
|
|
94
|
+
moveFocus(elementItems, elementItemIndex, -1);
|
|
95
|
+
} else if (isTextInput(currentEl) || isTextArea(currentEl)) {
|
|
96
|
+
var cursorStart = currentEl.selectionStart;
|
|
97
|
+
if (cursorStart === 0) {
|
|
98
|
+
event.preventDefault();
|
|
99
|
+
moveFocus(elementItems, elementItemIndex, -1);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
case "ArrowDown":
|
|
105
|
+
case "ArrowRight":
|
|
106
|
+
{
|
|
107
|
+
if (!isTextInput(currentEl) && !isTextArea(currentEl)) {
|
|
108
|
+
event.preventDefault();
|
|
109
|
+
moveFocus(elementItems, elementItemIndex, 1);
|
|
110
|
+
} else if (isTextInput(currentEl) || isTextArea(currentEl)) {
|
|
111
|
+
var value = currentEl.value;
|
|
112
|
+
var cursorEnd = currentEl.selectionStart;
|
|
113
|
+
if (cursorEnd === value.length) {
|
|
114
|
+
event.preventDefault();
|
|
115
|
+
moveFocus(elementItems, elementItemIndex, 1);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
case "Escape":
|
|
121
|
+
{
|
|
122
|
+
event.preventDefault();
|
|
123
|
+
if (menuElementDiv && triggerButton) {
|
|
124
|
+
if (getComputedStyle(menuElementDiv).display === "block") {
|
|
125
|
+
handleMenuEscapeKeyPress(menuElementDiv, triggerButton);
|
|
126
|
+
}
|
|
127
|
+
triggerButton.focus();
|
|
128
|
+
}
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
case "Enter":
|
|
132
|
+
case " ":
|
|
133
|
+
{
|
|
134
|
+
if (!isNativeButton(currentEl) && !isLink(currentEl) && isClickableButNotSemantic(currentEl)) {
|
|
135
|
+
event.preventDefault();
|
|
136
|
+
currentEl.click();
|
|
137
|
+
}
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
// src/block/src/makeBlockAccessible/makeBlockAccessible.ts
|
|
143
|
+
var eventListenersMap = /* @__PURE__ */ new Map();
|
|
144
|
+
function makeBlockAccessible(blockId, blockElementsClass) {
|
|
145
|
+
var blockDiv = document.querySelector("#".concat(blockId));
|
|
146
|
+
if (!blockDiv) {
|
|
147
|
+
throw new Error("Invalid block main div id provided.");
|
|
148
|
+
}
|
|
149
|
+
var blockItems = blockDiv.querySelectorAll(".".concat(blockElementsClass));
|
|
150
|
+
if (!blockItems) {
|
|
151
|
+
throw new Error("Invalid block items shared class provided.");
|
|
152
|
+
}
|
|
153
|
+
blockItems.forEach(function(blockItem) {
|
|
154
|
+
if (!eventListenersMap.has(blockItem)) {
|
|
155
|
+
blockItem.addEventListener("keydown", function(event) {
|
|
156
|
+
var items = blockDiv.querySelectorAll(".".concat(blockElementsClass));
|
|
157
|
+
var index = Array.prototype.indexOf.call(items, blockItem);
|
|
158
|
+
handleKeyPress(event, items, index);
|
|
159
|
+
var handler = function(event2) {
|
|
160
|
+
return handleKeyPress(event2, items, index);
|
|
161
|
+
};
|
|
162
|
+
eventListenersMap.set(blockItem, handler);
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
return function cleanUpBlockEventListeners() {
|
|
167
|
+
blockItems.forEach(function(blockItem, blockItemIndex) {
|
|
168
|
+
if (eventListenersMap.has(blockItem)) {
|
|
169
|
+
blockItem.removeEventListener("keydown", function(event) {
|
|
170
|
+
return handleKeyPress(event, blockItems, blockItemIndex);
|
|
171
|
+
});
|
|
172
|
+
eventListenersMap.delete(blockItem);
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
// src/checkbox/index.ts
|
|
178
|
+
var checkbox_exports = {};
|
|
179
|
+
__export(checkbox_exports, {
|
|
180
|
+
updateCheckboxAriaAttributes: function() {
|
|
181
|
+
return updateCheckboxAriaAttributes;
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
// src/checkbox/src/updateCheckboxAriaAttributes/updateCheckboxAriaAttributes.ts
|
|
185
|
+
function updateCheckboxAriaAttributes(checkboxId, checkboxesClass, checkboxStates, currentPressedCheckboxIndex) {
|
|
186
|
+
var checkboxDiv = document.querySelector("#".concat(checkboxId));
|
|
187
|
+
if (!checkboxDiv) {
|
|
188
|
+
throw new Error("Invalid checkbox main div id provided.");
|
|
189
|
+
}
|
|
190
|
+
var checkboxItems = Array.from(document.querySelectorAll(".".concat(checkboxesClass)));
|
|
191
|
+
if (checkboxItems.length === 0) {
|
|
192
|
+
throw new Error("Invalid checkboxes shared class provided.");
|
|
193
|
+
}
|
|
194
|
+
checkboxItems.forEach(function(checkbox, index) {
|
|
195
|
+
if (index === currentPressedCheckboxIndex) {
|
|
196
|
+
checkbox.setAttribute("aria-checked", checkboxStates[index].checked ? "true" : "false");
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
// src/menu/index.ts
|
|
201
|
+
var menu_exports = {};
|
|
202
|
+
__export(menu_exports, {
|
|
203
|
+
makeMenuAccessible: function() {
|
|
204
|
+
return makeMenuAccessible;
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
// src/menu/src/makeMenuAccessible/makeMenuAccessible.ts
|
|
208
|
+
function makeMenuAccessible(param) {
|
|
209
|
+
var menuId = param.menuId, menuElementsClass = param.menuElementsClass, triggerId = param.triggerId;
|
|
210
|
+
var menuDiv = document.querySelector("#".concat(menuId));
|
|
211
|
+
if (!menuDiv) throw new Error("Invalid menu div id provided");
|
|
212
|
+
var triggerButton = document.querySelector("#".concat(triggerId));
|
|
213
|
+
if (!triggerButton) throw new Error("Invalid trigger button id provided");
|
|
214
|
+
var handlerMap = /* @__PURE__ */ new Map();
|
|
215
|
+
function setAria(isOpen) {
|
|
216
|
+
triggerButton.setAttribute("aria-expanded", isOpen ? "true" : "false");
|
|
217
|
+
}
|
|
218
|
+
function addListeners() {
|
|
219
|
+
var menuItems = menuDiv.querySelectorAll(".".concat(menuElementsClass));
|
|
220
|
+
menuItems.forEach(function(menuItem, index) {
|
|
221
|
+
if (!handlerMap.has(menuItem)) {
|
|
222
|
+
var handler = function(event) {
|
|
223
|
+
return handleKeyPress(event, menuItems, index, menuDiv, triggerButton);
|
|
224
|
+
};
|
|
225
|
+
menuItem.addEventListener("keydown", handler);
|
|
226
|
+
handlerMap.set(menuItem, handler);
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
function removeListeners() {
|
|
231
|
+
var menuItems = menuDiv.querySelectorAll(".".concat(menuElementsClass));
|
|
232
|
+
menuItems.forEach(function(menuItem) {
|
|
233
|
+
var handler = handlerMap.get(menuItem);
|
|
234
|
+
if (handler) {
|
|
235
|
+
menuItem.removeEventListener("keydown", handler);
|
|
236
|
+
handlerMap.delete(menuItem);
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
function openMenu() {
|
|
241
|
+
menuDiv.style.display = "block";
|
|
242
|
+
setAria(true);
|
|
243
|
+
addListeners();
|
|
244
|
+
var menuItems = menuDiv.querySelectorAll(".".concat(menuElementsClass));
|
|
245
|
+
if (menuItems.length > 0) menuItems[0].focus();
|
|
246
|
+
}
|
|
247
|
+
function closeMenu() {
|
|
248
|
+
removeListeners();
|
|
249
|
+
menuDiv.style.display = "none";
|
|
250
|
+
setAria(false);
|
|
251
|
+
triggerButton.focus();
|
|
252
|
+
}
|
|
253
|
+
function cleanup() {
|
|
254
|
+
removeListeners();
|
|
255
|
+
}
|
|
256
|
+
return {
|
|
257
|
+
openMenu: openMenu,
|
|
258
|
+
closeMenu: closeMenu,
|
|
259
|
+
cleanup: cleanup
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
// src/radio/index.ts
|
|
263
|
+
var radio_exports = {};
|
|
264
|
+
__export(radio_exports, {
|
|
265
|
+
updateRadioAriaAttributes: function() {
|
|
266
|
+
return updateRadioAriaAttributes;
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
// src/radio/src/updateRadioAriaAttributes/updateRadioAriaAttributes.ts
|
|
270
|
+
function updateRadioAriaAttributes(radioId, radiosClass, radioStates, currentPressedRadioIndex) {
|
|
271
|
+
var radioDiv = document.querySelector("#".concat(radioId));
|
|
272
|
+
if (!radioDiv) {
|
|
273
|
+
throw new Error("Invalid radio main div id provided.");
|
|
274
|
+
}
|
|
275
|
+
var radioItems = Array.from(radioDiv.querySelectorAll(".".concat(radiosClass)));
|
|
276
|
+
if (radioItems.length === 0) {
|
|
277
|
+
throw new Error("Invalid radios shared class provided.");
|
|
278
|
+
}
|
|
279
|
+
radioItems.forEach(function(radioItem, index) {
|
|
280
|
+
var state = radioStates[index];
|
|
281
|
+
var checked = radioItem.getAttribute("aria-checked");
|
|
282
|
+
var shouldBeChecked = index === currentPressedRadioIndex ? state.checked ? "true" : "false" : "false";
|
|
283
|
+
if (checked && checked !== shouldBeChecked) {
|
|
284
|
+
radioItem.setAttribute("aria-checked", shouldBeChecked);
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
// src/toggle/index.ts
|
|
289
|
+
var toggle_exports = {};
|
|
290
|
+
__export(toggle_exports, {
|
|
291
|
+
updateToggleAriaAttribute: function() {
|
|
292
|
+
return updateToggleAriaAttribute;
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
// src/toggle/src/updateToggleAriaAttribute/updateToggleAriaAttribute.ts
|
|
296
|
+
function updateToggleAriaAttribute(toggleId, togglesClass, toggleStates, currentPressedToggleIndex) {
|
|
297
|
+
var toggleDiv = document.querySelector("#".concat(toggleId));
|
|
298
|
+
if (!toggleDiv) {
|
|
299
|
+
throw new Error("Invalid toggle main div id provided.");
|
|
300
|
+
}
|
|
301
|
+
var toggleItems = Array.from(toggleDiv.querySelectorAll(".".concat(togglesClass)));
|
|
302
|
+
if (toggleItems.length === 0) {
|
|
303
|
+
throw new Error("Invalid toggles shared class provided.");
|
|
304
|
+
}
|
|
305
|
+
if (toggleItems.length !== toggleStates.length) {
|
|
306
|
+
throw new Error("Toggle state/DOM length mismatch: found ".concat(toggleItems.length, " triggers, but got ").concat(toggleStates.length, " state objects."));
|
|
307
|
+
}
|
|
308
|
+
toggleItems.forEach(function(toggle, index) {
|
|
309
|
+
if (index === currentPressedToggleIndex) {
|
|
310
|
+
toggle.setAttribute("aria-pressed", toggleStates[index].pressed ? "true" : "false");
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
exports.Accordion = accordion_exports;
|
|
315
|
+
exports.Block = block_exports;
|
|
316
|
+
exports.Checkbox = checkbox_exports;
|
|
317
|
+
exports.Menu = menu_exports;
|
|
318
|
+
exports.Radio = radio_exports;
|
|
319
|
+
exports.Toggle = toggle_exports; //# sourceMappingURL=index.cjs.map
|
|
320
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/macx/aria-ease/package/dist/index.cjs","../src/accordion/index.ts"],"names":["accordion_exports","__export"],"mappings":"AAAA;SAK0D,GAAA,EAAA,CAAA,CAAA,OAAA,CAAA,CAAA,CAAA,EAAA,GAAA,CAAA,IAAA,CAAA,KAAA,MAAA,EAAA,MAAA;SAAA,GAAA,EAAA,CAAA,SAAA,CAAA,CAAA,EAAA,GAAA,CAAA,IAAA,MAAA,MAAA,EAAA,MAAA;SAAA,GAAA,EAAA,GAAA,CAAA,EAAA,GAAA,KAAA,MAAA,MAAA,EAAA,MAAA;QAAA,KAAA,GAAA,CAAA,KAAA;QAAA,YAAA;IAAA;IAAA;AAG1D,yBAAyB;ACRzB,IAAAA,oBAAA,CAAA;AAAAC,SAAAD,mBAAA","sourcesContent":["'use strict';\n\nvar __defProp = Object.defineProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\n\n// src/accordion/index.ts\nvar accordion_exports = {};\n__export(accordion_exports, {\n updateAccordionTriggerAriaAttributes: () => updateAccordionTriggerAriaAttributes\n});\n\n// src/accordion/src/updateAccordionTriggerAriaAttributes/updateAccordionTriggerAriaAttributes.ts\nfunction updateAccordionTriggerAriaAttributes(accordionStates, accordionsClass, currentClickedTriggerIndex) {\n console.log(\"Accordion updateAccordionTriggerAriaAttributes initiated\");\n}\n\n// src/block/index.ts\nvar block_exports = {};\n__export(block_exports, {\n makeBlockAccessible: () => makeBlockAccessible\n});\n\n// src/block/src/makeBlockAccessible/makeBlockAccessible.ts\nfunction makeBlockAccessible(blockId, blockItemsClass) {\n console.log(\"Block makeBlockAccessible initiated\");\n}\n\n// src/checkbox/index.ts\nvar checkbox_exports = {};\n__export(checkbox_exports, {\n updateGroupCheckboxesAriaAttributes: () => updateGroupCheckboxesAriaAttributes,\n updateSingleCheckboxAriaAttributes: () => updateSingleCheckboxAriaAttributes\n});\n\n// src/checkbox/src/single-checkbox/updateSingleCheckboxAriaAttributes/updateSingleCheckboxAriaAttributes.ts\nfunction updateSingleCheckboxAriaAttributes(checkboxClass, updatedAriaLabel) {\n console.log(\"Checkbox updateSingleCheckboxAriaAttributes initiated\");\n}\n\n// src/checkbox/src/group-checkbox/updateGroupCheckboxesAriaAttributes/updateGroupCheckboxesAriaAttributes.ts\nfunction updateGroupCheckboxesAriaAttributes(checkboxStates, checkboxesClass, currentPressedCheckboxIndex) {\n console.log(\"Checkbox updateGroupCheckboxesAriaAttributes initiated\");\n}\n\n// src/menu/index.ts\nvar menu_exports = {};\n__export(menu_exports, {\n cleanUpMenuEventListeners: () => cleanUpMenuEventListeners,\n makeMenuAccessible: () => makeMenuAccessible,\n updateMenuTriggerAriaAttributes: () => updateMenuTriggerAriaAttributes\n});\n\n// src/menu/src/cleanUpMenuEventListeners/cleanUpMenuEventListeners.ts\nfunction cleanUpMenuEventListeners(menuId, menuItemsClass) {\n console.log(\"Menu cleanUpMenuEventListeners initiated\");\n}\n\n// src/menu/src/makeMenuAccessible/makeMenuAccessible.ts\nfunction makeMenuAccessible(menuId, menuItemsClass) {\n console.log(\"Menu makeMenuAccessible initiated\");\n}\n\n// src/menu/src/updateMenuTriggerAriaAttributes/updateMenuTriggerAriaAttributes.ts\nfunction updateMenuTriggerAriaAttributes(triggerId, ariaLabel) {\n console.log(\"Menu updateMenuTriggerAriaAttributes initiated\");\n}\n\n// src/radio/index.ts\nvar radio_exports = {};\n__export(radio_exports, {\n updateGroupRadiosAriaAttributes: () => updateGroupRadiosAriaAttributes,\n updateSingleRadioAriaAttributes: () => updateSingleRadioAriaAttributes\n});\n\n// src/radio/src/single-radio/updateSingleRadioAriaAttributes.ts\nfunction updateSingleRadioAriaAttributes(radioClass) {\n console.log(\"Radio updateSingleRadioAriaAttributes initiated\");\n}\n\n// src/radio/src/group-radio/updateGroupRadiosAriaAttributes.ts\nfunction updateGroupRadiosAriaAttributes(radioStates, radiosClass, currentPressedRadioIndex) {\n console.log(\"Radio updateGroupRadiosAriaAttributes initiated\");\n}\n\n// src/toggle/index.ts\nvar toggle_exports = {};\n__export(toggle_exports, {\n updateGroupTogglesAriaAttributes: () => updateGroupTogglesAriaAttributes,\n updateSingleToggleAriaAttributes: () => updateSingleToggleAriaAttributes\n});\n\n// src/toggle/src/single-toggle/updateSingleToggleAriaAttributes.ts\nfunction updateSingleToggleAriaAttributes(toggleClass) {\n console.log(\"Toggle updateSingleToggleAriaAttributes initiated\");\n}\n\n// src/toggle/src/group-toggle/updateGroupTogglesAriaAttributes.ts\nfunction updateGroupTogglesAriaAttributes(toggleStates, togglesClass, currentPressedToggleIndex) {\n console.log(\"Toggle updateGroupTogglesAriaAttributes initiated\");\n}\n\nexports.Accordion = accordion_exports;\nexports.Block = block_exports;\nexports.Checkbox = checkbox_exports;\nexports.Menu = menu_exports;\nexports.Radio = radio_exports;\nexports.Toggle = toggle_exports;\n//# sourceMappingURL=index.cjs.map\n","import { updateAccordionTriggerAriaAttributes } from \"./src/updateAccordionTriggerAriaAttributes/updateAccordionTriggerAriaAttributes\";\n\nexport { updateAccordionTriggerAriaAttributes }"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
type HTMLElement = Element;
|
|
3
|
+
type NodeListOf<HTMLElement> = Iterable<HTMLElement>;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
interface AccordionStates {
|
|
7
|
+
display: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface CheckboxStates {
|
|
11
|
+
checked: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface RadioStates {
|
|
15
|
+
checked: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface ToggleStates {
|
|
19
|
+
pressed: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 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-controls, aria-label (for only non-text triggers).
|
|
24
|
+
* @param {string} accordionId The id of the accordion triggers parent container.
|
|
25
|
+
* @param {string} accordionTriggersClass The shared class of all the accordion triggers.
|
|
26
|
+
* @param {AccordionStates[]} accordionStates Array of objects containing accordions state information.
|
|
27
|
+
* @param {number} clickedTriggerIndex Index of the currently clicked accordion trigger within the accordion div container.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
declare function updateAccordionTriggerAriaAttributes(accordionId: string, accordionTriggersClass: string, accordionStates: AccordionStates[], clickedTriggerIndex: number): void;
|
|
31
|
+
|
|
32
|
+
declare const index$5_updateAccordionTriggerAriaAttributes: typeof updateAccordionTriggerAriaAttributes;
|
|
33
|
+
declare namespace index$5 {
|
|
34
|
+
export { index$5_updateAccordionTriggerAriaAttributes as updateAccordionTriggerAriaAttributes };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Adds keyboard interaction to block. The block traps focus and can be interacted with using the keyboard.
|
|
39
|
+
* @param {string} blockId The id of the block container.
|
|
40
|
+
* @param {string} blockElementsClass The shared class of the elements that are children of the block.
|
|
41
|
+
*/
|
|
42
|
+
declare function makeBlockAccessible(blockId: string, blockElementsClass: string): () => void;
|
|
43
|
+
|
|
44
|
+
declare const index$4_makeBlockAccessible: typeof makeBlockAccessible;
|
|
45
|
+
declare namespace index$4 {
|
|
46
|
+
export { index$4_makeBlockAccessible as makeBlockAccessible };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Adds screen reader accessibility to multiple checkboxes. Updates the aria attributes of the checkboxes. Checkbox elements must possess the following aria attributes; aria-checked and aria-label.
|
|
51
|
+
* @param {string} checkboxId The id of the checkbox parent container.
|
|
52
|
+
* @param {string} checkboxesClass The shared class of all the checkboxes.
|
|
53
|
+
* @param {CheckboxStates[]} checkboxStates Array of objects containing checkboxes state information.
|
|
54
|
+
* @param {number} currentPressedCheckboxIndex Index of the currently checked or unchecked checkbox.
|
|
55
|
+
*/
|
|
56
|
+
|
|
57
|
+
declare function updateCheckboxAriaAttributes(checkboxId: string, checkboxesClass: string, checkboxStates: CheckboxStates[], currentPressedCheckboxIndex: number): void;
|
|
58
|
+
|
|
59
|
+
declare const index$3_updateCheckboxAriaAttributes: typeof updateCheckboxAriaAttributes;
|
|
60
|
+
declare namespace index$3 {
|
|
61
|
+
export { index$3_updateCheckboxAriaAttributes as updateCheckboxAriaAttributes };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Adds keyboard interaction to toggle menu. The menu traps focus and can be interacted with using the keyboard. The first interactive item of the menu has focus when menu open.
|
|
66
|
+
* @param {string} menuId - The id of the menu.
|
|
67
|
+
* @param {string} menuElementsClass - The class of the items that are children of the menu.
|
|
68
|
+
* @param {string} triggerId - The id of the button that triggers the menu.
|
|
69
|
+
*/
|
|
70
|
+
declare function makeMenuAccessible({ menuId, menuElementsClass, triggerId }: {
|
|
71
|
+
menuId: string;
|
|
72
|
+
menuElementsClass: string;
|
|
73
|
+
triggerId: string;
|
|
74
|
+
}): {
|
|
75
|
+
openMenu: () => void;
|
|
76
|
+
closeMenu: () => void;
|
|
77
|
+
cleanup: () => void;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
declare const index$2_makeMenuAccessible: typeof makeMenuAccessible;
|
|
81
|
+
declare namespace index$2 {
|
|
82
|
+
export { index$2_makeMenuAccessible as makeMenuAccessible };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Adds screen reader accessibility to multiple radio buttons. Updates the aria attributes of the radio buttons. Radio elements must possess the following aria attributes; aria-checked and aria-label.
|
|
87
|
+
* @param {string} radioId The id of the radio parent container.
|
|
88
|
+
* @param {string} radiosClass The shared class of all the radios.
|
|
89
|
+
* @param {RadioStates[]} radioStates Array of objects containing radio buttons state information.
|
|
90
|
+
* @param {number} currentPressedRadioIndex Index of the currently checked or unchecked radio button.
|
|
91
|
+
*/
|
|
92
|
+
|
|
93
|
+
declare function updateRadioAriaAttributes(radioId: string, radiosClass: string, radioStates: RadioStates[], currentPressedRadioIndex: number): void;
|
|
94
|
+
|
|
95
|
+
declare const index$1_updateRadioAriaAttributes: typeof updateRadioAriaAttributes;
|
|
96
|
+
declare namespace index$1 {
|
|
97
|
+
export { index$1_updateRadioAriaAttributes as updateRadioAriaAttributes };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Adds screen reader accessibility to toggle buttons. Updates the aria attributes of the toggle buttons. Button must be a semantic button element or a non-semantic element with a role of button, and possess the aria-pressed attribute.
|
|
102
|
+
* @param {string} toggleId The id of the toggle buttons parent container.
|
|
103
|
+
* @param {string} togglesClass The shared class of all the toggle buttons.
|
|
104
|
+
* @param {ToggleStates[]} toggleStates Array of objects containing toggle buttons state information.
|
|
105
|
+
* @param {number} currentPressedToggleIndex Index of the currently pressed or unpressed toggle button.
|
|
106
|
+
*/
|
|
107
|
+
|
|
108
|
+
declare function updateToggleAriaAttribute(toggleId: string, togglesClass: string, toggleStates: ToggleStates[], currentPressedToggleIndex: number): void;
|
|
109
|
+
|
|
110
|
+
declare const index_updateToggleAriaAttribute: typeof updateToggleAriaAttribute;
|
|
111
|
+
declare namespace index {
|
|
112
|
+
export { index_updateToggleAriaAttribute as updateToggleAriaAttribute };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export { index$5 as Accordion, index$4 as Block, index$3 as Checkbox, index$2 as Menu, index$1 as Radio, index as Toggle };
|