aria-ease 2.0.0 → 2.0.1
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 +21 -111
- package/dist/index.cjs +329 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +123 -0
- package/dist/index.d.mts +140 -0
- package/dist/index.d.ts +123 -0
- package/dist/index.js +323 -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/src/handleKeyPress.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { updateMenuTriggerAriaAttributes } from "./menu/updateMenuTriggerAriaAttributes";
|
|
2
|
-
function handleMenuEscapeKeyPress(menuElement, menuTriggerButton, menuClosedStateAriaLabel) {
|
|
3
|
-
menuElement.style.display = 'none';
|
|
4
|
-
var menuTriggerButtonId = menuTriggerButton.getAttribute('id');
|
|
5
|
-
if (!menuTriggerButtonId) {
|
|
6
|
-
throw new Error("Menu trigger button does not have id attribute");
|
|
7
|
-
}
|
|
8
|
-
updateMenuTriggerAriaAttributes("".concat(menuTriggerButtonId), "".concat(menuClosedStateAriaLabel));
|
|
9
|
-
}
|
|
10
|
-
export function handleKeyPress(event, elementItems, elementItemIndex, menuElementDiv, triggerButton, menuClosedStateAriaLabel) {
|
|
11
|
-
switch (event.key) {
|
|
12
|
-
case 'ArrowUp':
|
|
13
|
-
case 'ArrowLeft':
|
|
14
|
-
if (((elementItems.item(elementItemIndex).tagName !== 'INPUT') && (elementItems.item(elementItemIndex).tagName !== 'TEXTAREA')) || (elementItems.item(elementItemIndex).tagName === 'INPUT' && (elementItems.item(elementItemIndex).type !== 'text' && elementItems.item(elementItemIndex).type !== 'email' && elementItems.item(elementItemIndex).type !== 'password' && elementItems.item(elementItemIndex).type !== 'tel' && elementItems.item(elementItemIndex).type !== 'number'))) {
|
|
15
|
-
event.preventDefault();
|
|
16
|
-
if (elementItemIndex === 0) {
|
|
17
|
-
elementItems.item(elementItems.length - 1).focus();
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
elementItems.item(elementItemIndex - 1).focus();
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
if ((elementItems.item(elementItemIndex).tagName === 'INPUT' && (elementItems.item(elementItemIndex).type === 'text' || elementItems.item(elementItemIndex).type === 'tel' || elementItems.item(elementItemIndex).type === 'password' || elementItems.item(elementItemIndex).type === 'email' || elementItems.item(elementItemIndex).type === 'number')) || elementItems.item(elementItemIndex).tagName === 'TEXTAREA') {
|
|
24
|
-
if (elementItems.item(elementItemIndex).selectionStart === 0) {
|
|
25
|
-
event.preventDefault();
|
|
26
|
-
if (elementItemIndex === 0) {
|
|
27
|
-
elementItems.item(elementItems.length - 1).focus();
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
elementItems.item(elementItemIndex - 1).focus();
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
break;
|
|
35
|
-
case 'ArrowDown':
|
|
36
|
-
case 'ArrowRight':
|
|
37
|
-
if (((elementItems.item(elementItemIndex).tagName !== 'INPUT') && (elementItems.item(elementItemIndex).tagName !== 'TEXTAREA')) || (elementItems.item(elementItemIndex).tagName === 'INPUT' && (elementItems.item(elementItemIndex).type !== 'text' && elementItems.item(elementItemIndex).type !== 'email' && elementItems.item(elementItemIndex).type !== 'password' && elementItems.item(elementItemIndex).type !== 'tel' && elementItems.item(elementItemIndex).type !== 'number'))) {
|
|
38
|
-
event.preventDefault();
|
|
39
|
-
if (elementItemIndex === elementItems.length - 1) {
|
|
40
|
-
elementItems.item(0).focus();
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
elementItems.item(elementItemIndex + 1).focus();
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
if ((elementItems.item(elementItemIndex).tagName === 'INPUT' && (elementItems.item(elementItemIndex).type === 'text' || elementItems.item(elementItemIndex).type === 'tel' || elementItems.item(elementItemIndex).type === 'password' || elementItems.item(elementItemIndex).type === 'email' || elementItems.item(elementItemIndex).type === 'number')) || elementItems.item(elementItemIndex).tagName === 'TEXTAREA') {
|
|
47
|
-
if (elementItems.item(elementItemIndex).selectionStart === elementItems.item(elementItemIndex).value.length) {
|
|
48
|
-
event.preventDefault();
|
|
49
|
-
if (elementItemIndex === elementItems.length - 1) {
|
|
50
|
-
elementItems.item(0).focus();
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
elementItems.item(elementItemIndex + 1).focus();
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
break;
|
|
58
|
-
case 'Escape':
|
|
59
|
-
event.preventDefault();
|
|
60
|
-
if (menuElementDiv && triggerButton && menuClosedStateAriaLabel) {
|
|
61
|
-
(getComputedStyle(menuElementDiv).display === 'block') ?
|
|
62
|
-
handleMenuEscapeKeyPress(menuElementDiv, triggerButton, menuClosedStateAriaLabel) :
|
|
63
|
-
null;
|
|
64
|
-
triggerButton.focus();
|
|
65
|
-
}
|
|
66
|
-
break;
|
|
67
|
-
case 'Enter':
|
|
68
|
-
case ' ':
|
|
69
|
-
if (elementItems.item(elementItemIndex).tagName === 'BUTTON') {
|
|
70
|
-
event.preventDefault();
|
|
71
|
-
elementItems.item(elementItemIndex).click();
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
74
|
-
else if (elementItems.item(elementItemIndex).tagName === 'A') {
|
|
75
|
-
event.preventDefault();
|
|
76
|
-
elementItems.item(elementItemIndex).click();
|
|
77
|
-
break;
|
|
78
|
-
}
|
|
79
|
-
break;
|
|
80
|
-
default:
|
|
81
|
-
break;
|
|
82
|
-
}
|
|
83
|
-
}
|
package/src/handleKeyPress.ts
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { NodeListOfHTMLElement, HTMLElement } from "../Types";
|
|
2
|
-
import { updateMenuTriggerAriaAttributes } from "./menu/updateMenuTriggerAriaAttributes";
|
|
3
|
-
|
|
4
|
-
function handleMenuEscapeKeyPress(menuElement: HTMLElement, menuTriggerButton: HTMLElement, menuClosedStateAriaLabel: string) {
|
|
5
|
-
menuElement.style.display = 'none';
|
|
6
|
-
const menuTriggerButtonId = menuTriggerButton.getAttribute('id');
|
|
7
|
-
if(!menuTriggerButtonId) {
|
|
8
|
-
throw new Error("Menu trigger button does not have id attribute");
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
updateMenuTriggerAriaAttributes(`${menuTriggerButtonId}`, `${menuClosedStateAriaLabel}`)
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function handleKeyPress(event: KeyboardEvent, elementItems: NodeListOfHTMLElement, elementItemIndex: number, menuElementDiv?: HTMLElement | undefined, triggerButton?: HTMLElement | undefined, menuClosedStateAriaLabel?: string | undefined): void {
|
|
15
|
-
switch(event.key) {
|
|
16
|
-
case 'ArrowUp':
|
|
17
|
-
case 'ArrowLeft':
|
|
18
|
-
if(((elementItems.item(elementItemIndex).tagName !== 'INPUT') && (elementItems.item(elementItemIndex).tagName !== 'TEXTAREA')) || (elementItems.item(elementItemIndex).tagName === 'INPUT' && (elementItems.item(elementItemIndex).type !== 'text' && elementItems.item(elementItemIndex).type !== 'email' && elementItems.item(elementItemIndex).type !== 'password' && elementItems.item(elementItemIndex).type !== 'tel' && elementItems.item(elementItemIndex).type !== 'number'))) {
|
|
19
|
-
event.preventDefault();
|
|
20
|
-
if (elementItemIndex === 0) {
|
|
21
|
-
elementItems.item(elementItems.length - 1).focus();
|
|
22
|
-
} else {
|
|
23
|
-
elementItems.item(elementItemIndex - 1).focus();
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
if((elementItems.item(elementItemIndex).tagName === 'INPUT' && (elementItems.item(elementItemIndex).type === 'text' || elementItems.item(elementItemIndex).type === 'tel' || elementItems.item(elementItemIndex).type === 'password' || elementItems.item(elementItemIndex).type === 'email' || elementItems.item(elementItemIndex).type === 'number')) || elementItems.item(elementItemIndex).tagName === 'TEXTAREA') {
|
|
27
|
-
if (elementItems.item(elementItemIndex).selectionStart === 0) {
|
|
28
|
-
event.preventDefault()
|
|
29
|
-
if (elementItemIndex === 0) {
|
|
30
|
-
elementItems.item(elementItems.length - 1).focus();
|
|
31
|
-
} else {
|
|
32
|
-
elementItems.item(elementItemIndex - 1).focus();
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
break;
|
|
37
|
-
case 'ArrowDown':
|
|
38
|
-
case 'ArrowRight':
|
|
39
|
-
if(((elementItems.item(elementItemIndex).tagName !== 'INPUT') && (elementItems.item(elementItemIndex).tagName !== 'TEXTAREA')) || (elementItems.item(elementItemIndex).tagName === 'INPUT' && (elementItems.item(elementItemIndex).type !== 'text' && elementItems.item(elementItemIndex).type !== 'email' && elementItems.item(elementItemIndex).type !== 'password' && elementItems.item(elementItemIndex).type !== 'tel' && elementItems.item(elementItemIndex).type !== 'number'))) {
|
|
40
|
-
event.preventDefault()
|
|
41
|
-
if (elementItemIndex === elementItems.length - 1) {
|
|
42
|
-
elementItems.item(0).focus();
|
|
43
|
-
} else {
|
|
44
|
-
elementItems.item(elementItemIndex + 1).focus();
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
if((elementItems.item(elementItemIndex).tagName === 'INPUT' && (elementItems.item(elementItemIndex).type === 'text' || elementItems.item(elementItemIndex).type === 'tel' || elementItems.item(elementItemIndex).type === 'password' || elementItems.item(elementItemIndex).type === 'email' || elementItems.item(elementItemIndex).type === 'number')) || elementItems.item(elementItemIndex).tagName === 'TEXTAREA') {
|
|
48
|
-
if (elementItems.item(elementItemIndex).selectionStart === elementItems.item(elementItemIndex).value.length) {
|
|
49
|
-
event.preventDefault()
|
|
50
|
-
if (elementItemIndex === elementItems.length - 1) {
|
|
51
|
-
elementItems.item(0).focus();
|
|
52
|
-
} else {
|
|
53
|
-
elementItems.item(elementItemIndex + 1).focus();
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
break;
|
|
58
|
-
case 'Escape':
|
|
59
|
-
event.preventDefault();
|
|
60
|
-
if(menuElementDiv && triggerButton && menuClosedStateAriaLabel) {
|
|
61
|
-
(getComputedStyle(menuElementDiv).display === 'block') ?
|
|
62
|
-
handleMenuEscapeKeyPress(menuElementDiv, triggerButton, menuClosedStateAriaLabel) :
|
|
63
|
-
null
|
|
64
|
-
triggerButton.focus();
|
|
65
|
-
}
|
|
66
|
-
break;
|
|
67
|
-
case 'Enter':
|
|
68
|
-
case ' ':
|
|
69
|
-
if(elementItems.item(elementItemIndex).tagName === 'BUTTON') {
|
|
70
|
-
event.preventDefault();
|
|
71
|
-
elementItems.item(elementItemIndex).click();
|
|
72
|
-
break;
|
|
73
|
-
} else if (elementItems.item(elementItemIndex).tagName === 'A') {
|
|
74
|
-
event.preventDefault();
|
|
75
|
-
elementItems.item(elementItemIndex).click();
|
|
76
|
-
break;
|
|
77
|
-
}
|
|
78
|
-
break;
|
|
79
|
-
default:
|
|
80
|
-
break;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { handleKeyPress } from "../handleKeyPress";
|
|
2
|
-
export function cleanUpMenuEventListeners(menuId, menuItemsClass) {
|
|
3
|
-
var menuDiv = document.querySelector("#".concat(menuId));
|
|
4
|
-
if (!menuDiv) {
|
|
5
|
-
throw new Error("Invalid menu div id provided");
|
|
6
|
-
}
|
|
7
|
-
var menuItems = menuDiv.querySelectorAll(".".concat(menuItemsClass));
|
|
8
|
-
if (!menuItems) {
|
|
9
|
-
throw new Error("Invalid menu items shared class provided");
|
|
10
|
-
}
|
|
11
|
-
var triggerId = menuDiv.getAttribute('aria-labelledby');
|
|
12
|
-
if (!triggerId) {
|
|
13
|
-
throw new Error("Menu div doesn't contain aria-labelledby attribute");
|
|
14
|
-
}
|
|
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
|
-
}
|
|
19
|
-
menuItems.forEach(function (menuItem, menuItemIndex) {
|
|
20
|
-
menuItem.removeEventListener('keydown', function (event) { return handleKeyPress(event, menuItems, menuItemIndex, menuDiv, triggerButton); });
|
|
21
|
-
});
|
|
22
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { NodeListOfHTMLElement } from "../../Types"
|
|
2
|
-
import { handleKeyPress } from "../handleKeyPress"
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export function cleanUpMenuEventListeners(menuId: string, menuItemsClass: string): void {
|
|
6
|
-
const menuDiv: HTMLElement = document.querySelector(`#${menuId}`) as HTMLElement
|
|
7
|
-
if(!menuDiv) {
|
|
8
|
-
throw new Error("Invalid menu div id provided")
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const menuItems: NodeListOfHTMLElement = menuDiv.querySelectorAll(`.${menuItemsClass}`)
|
|
12
|
-
if(!menuItems) {
|
|
13
|
-
throw new Error("Invalid menu items shared class provided")
|
|
14
|
-
}
|
|
15
|
-
|
|
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
|
-
|
|
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
|
-
}
|
|
25
|
-
|
|
26
|
-
menuItems.forEach((menuItem: HTMLElement, menuItemIndex: number): void => {
|
|
27
|
-
menuItem.removeEventListener('keydown', (event: KeyboardEvent): void => handleKeyPress(event, menuItems, menuItemIndex, menuDiv, triggerButton));
|
|
28
|
-
})
|
|
29
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
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
|
-
* @param {string} menuId The id of the menu
|
|
4
|
-
* @param {string} menuItemsClass The shared class of the items that are children of the menu
|
|
5
|
-
*/
|
|
6
|
-
import { handleKeyPress } from '../handleKeyPress';
|
|
7
|
-
var eventListenersAdded = new Set();
|
|
8
|
-
export function makeMenuAccessible(menuId, menuItemsClass) {
|
|
9
|
-
var menuDiv = document.querySelector("#".concat(menuId));
|
|
10
|
-
if (!menuDiv) {
|
|
11
|
-
throw new Error("Invalid menu div id provided");
|
|
12
|
-
}
|
|
13
|
-
var menuItems = menuDiv.querySelectorAll(".".concat(menuItemsClass));
|
|
14
|
-
var triggerId = menuDiv.getAttribute('aria-labelledby');
|
|
15
|
-
if (!triggerId) {
|
|
16
|
-
throw new Error("Menu div doesn't contain aria-labelledby attribute");
|
|
17
|
-
}
|
|
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
|
-
}
|
|
22
|
-
var menuClosedStateAriaLabel = triggerButton.getAttribute('aria-label');
|
|
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 shared class provided");
|
|
37
|
-
}
|
|
38
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/**
|
|
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
|
-
* @param {string} menuId The id of the menu
|
|
4
|
-
* @param {string} menuItemsClass The shared class of the items that are children of the menu
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { HTMLElement, NodeListOfHTMLElement } from '../../Types'
|
|
8
|
-
import { handleKeyPress } from '../handleKeyPress';
|
|
9
|
-
|
|
10
|
-
let eventListenersAdded: Set<HTMLElement> = new Set();
|
|
11
|
-
|
|
12
|
-
export function makeMenuAccessible(menuId: string, menuItemsClass: string): void {
|
|
13
|
-
const menuDiv: HTMLElement = document.querySelector(`#${menuId}`) as HTMLElement;
|
|
14
|
-
if(!menuDiv) {
|
|
15
|
-
throw new Error("Invalid menu div id provided")
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const menuItems: NodeListOfHTMLElement = menuDiv.querySelectorAll(`.${menuItemsClass}`);
|
|
19
|
-
|
|
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
|
-
|
|
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
|
-
}
|
|
29
|
-
|
|
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
|
-
}
|
|
34
|
-
|
|
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 shared class provided")
|
|
45
|
-
}
|
|
46
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
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 and aria-label.
|
|
3
|
-
* @param {string} triggerId The id of the trigger button that toggles the menu
|
|
4
|
-
* @param {string} ariaLabel The aria label to be updated to trigger element
|
|
5
|
-
*/
|
|
6
|
-
export function updateMenuTriggerAriaAttributes(triggerId, ariaLabel) {
|
|
7
|
-
var triggerButton = document.querySelector("#".concat(triggerId));
|
|
8
|
-
if (!triggerButton) {
|
|
9
|
-
throw new Error("Invalid menu trigger button id provided");
|
|
10
|
-
}
|
|
11
|
-
var currentAriaExpandedState = triggerButton.getAttribute('aria-expanded');
|
|
12
|
-
if (!currentAriaExpandedState) {
|
|
13
|
-
throw new Error("Menu trigger button does not have aria-expanded attribute");
|
|
14
|
-
}
|
|
15
|
-
function triggerOpen(ariaLabel) {
|
|
16
|
-
triggerButton.setAttribute('aria-expanded', 'true');
|
|
17
|
-
triggerButton.setAttribute('aria-label', ariaLabel);
|
|
18
|
-
}
|
|
19
|
-
function triggerClose(ariaLabel) {
|
|
20
|
-
triggerButton.setAttribute('aria-expanded', 'false');
|
|
21
|
-
triggerButton.setAttribute('aria-label', ariaLabel);
|
|
22
|
-
}
|
|
23
|
-
(currentAriaExpandedState === 'false') ?
|
|
24
|
-
triggerOpen(ariaLabel) :
|
|
25
|
-
triggerClose(ariaLabel);
|
|
26
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
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 and aria-label.
|
|
3
|
-
* @param {string} triggerId The id of the trigger button that toggles the menu
|
|
4
|
-
* @param {string} ariaLabel The aria label to be updated to trigger element
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { HTMLElement } from "../../Types";
|
|
8
|
-
|
|
9
|
-
export function updateMenuTriggerAriaAttributes(triggerId: string, ariaLabel: string): void {
|
|
10
|
-
const triggerButton: HTMLElement = document.querySelector(`#${triggerId}`) as HTMLElement
|
|
11
|
-
if(!triggerButton) {
|
|
12
|
-
throw new Error("Invalid menu trigger button id provided")
|
|
13
|
-
}
|
|
14
|
-
|
|
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
|
-
}
|
|
19
|
-
|
|
20
|
-
function triggerOpen(ariaLabel: string): void {
|
|
21
|
-
triggerButton.setAttribute('aria-expanded', 'true')
|
|
22
|
-
triggerButton.setAttribute('aria-label', ariaLabel)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function triggerClose(ariaLabel: string): void {
|
|
26
|
-
triggerButton.setAttribute('aria-expanded', 'false')
|
|
27
|
-
triggerButton.setAttribute('aria-label', ariaLabel)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
(currentAriaExpandedState === 'false') ?
|
|
31
|
-
triggerOpen(ariaLabel) :
|
|
32
|
-
triggerClose(ariaLabel)
|
|
33
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 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.
|
|
3
|
-
* @param {RadioStates[]} radioStates Array of objects containing radio buttons state information
|
|
4
|
-
* @param {string} radiosClass The shared class of all the radio buttons
|
|
5
|
-
* @param {number} currentPressedRadioIndex Index of the currently checked or unchecked radio button
|
|
6
|
-
*/
|
|
7
|
-
export function updateGroupRadiosAriaAttributes(radioStates, radiosClass, currentPressedRadioIndex) {
|
|
8
|
-
var allRadios = Array.from(document.querySelectorAll(".".concat(radiosClass)));
|
|
9
|
-
if (!allRadios) {
|
|
10
|
-
throw new Error('Invalid radios shared class provided.');
|
|
11
|
-
}
|
|
12
|
-
allRadios.forEach(function (radio, index) {
|
|
13
|
-
if (index === currentPressedRadioIndex) {
|
|
14
|
-
radio.setAttribute("aria-checked", radioStates[index].checked ? 'true' : 'false');
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
17
|
-
if (radio.getAttribute("aria-checked") === "true") {
|
|
18
|
-
radio.setAttribute("aria-checked", 'false');
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 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.
|
|
3
|
-
* @param {RadioStates[]} radioStates Array of objects containing radio buttons state information
|
|
4
|
-
* @param {string} radiosClass The shared class of all the radio buttons
|
|
5
|
-
* @param {number} currentPressedRadioIndex Index of the currently checked or unchecked radio button
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { HTMLElement, RadioStates } from "../../../Types";
|
|
9
|
-
|
|
10
|
-
export function updateGroupRadiosAriaAttributes(radioStates: RadioStates[], radiosClass: string, currentPressedRadioIndex: number): void {
|
|
11
|
-
const allRadios: HTMLElement[] = Array.from(document.querySelectorAll(`.${radiosClass}`));
|
|
12
|
-
|
|
13
|
-
if( !allRadios) {
|
|
14
|
-
throw new Error('Invalid radios shared class provided.');
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
allRadios.forEach((radio, index) => {
|
|
18
|
-
if (index === currentPressedRadioIndex) {
|
|
19
|
-
radio.setAttribute("aria-checked", radioStates[index].checked ? 'true' : 'false');
|
|
20
|
-
} else {
|
|
21
|
-
if(radio.getAttribute("aria-checked") === "true") {
|
|
22
|
-
radio.setAttribute("aria-checked", 'false');
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Adds screen reader accessibility to single radio button. Updates the aria attribute of the radio button. Radio element must possess the following aria attributes; aria-checked and aria-label.
|
|
3
|
-
* @param {string} radioClass The class of the radio button
|
|
4
|
-
* @param {string} updatedAriaLabel The aria label to be updated to button element
|
|
5
|
-
*/
|
|
6
|
-
export function updateSingleRadioAriaAttribute(radioClass, updatedAriaLabel) {
|
|
7
|
-
var radio = document.querySelector(".".concat(radioClass));
|
|
8
|
-
if (!radio) {
|
|
9
|
-
throw new Error('Invalid radio button class provided.');
|
|
10
|
-
}
|
|
11
|
-
var currentAriaCheckedState = radio.getAttribute('aria-checked');
|
|
12
|
-
if (!currentAriaCheckedState) {
|
|
13
|
-
throw new Error("Radio element does not have aria-checked attribute");
|
|
14
|
-
}
|
|
15
|
-
function radioChecked() {
|
|
16
|
-
radio.setAttribute('aria-checked', 'true');
|
|
17
|
-
}
|
|
18
|
-
function radioUnchecked() {
|
|
19
|
-
radio.setAttribute('aria-checked', 'false');
|
|
20
|
-
}
|
|
21
|
-
(currentAriaCheckedState === 'false') ?
|
|
22
|
-
radioChecked() :
|
|
23
|
-
radioUnchecked();
|
|
24
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Adds screen reader accessibility to single radio button. Updates the aria attribute of the radio button. Radio element must possess the following aria attributes; aria-checked and aria-label.
|
|
3
|
-
* @param {string} radioClass The class of the radio button
|
|
4
|
-
* @param {string} updatedAriaLabel The aria label to be updated to button element
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { HTMLElement } from "../../../Types";
|
|
8
|
-
|
|
9
|
-
export function updateSingleRadioAriaAttribute(radioClass: string, updatedAriaLabel: string): void {
|
|
10
|
-
const radio: HTMLElement = document.querySelector(`.${radioClass}`) as HTMLElement;
|
|
11
|
-
|
|
12
|
-
if( !radio) {
|
|
13
|
-
throw new Error('Invalid radio button class provided.');
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const currentAriaCheckedState: string = radio.getAttribute('aria-checked') as string
|
|
17
|
-
if(!currentAriaCheckedState) {
|
|
18
|
-
throw new Error("Radio element does not have aria-checked attribute")
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function radioChecked(): void {
|
|
22
|
-
radio.setAttribute('aria-checked', 'true');
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function radioUnchecked(): void {
|
|
27
|
-
radio.setAttribute('aria-checked', 'false');
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
(currentAriaCheckedState === 'false') ?
|
|
32
|
-
radioChecked() :
|
|
33
|
-
radioUnchecked()
|
|
34
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Adds screen reader accessibility to toggle buttons. Updates the aria attributes of the toggle buttons. Button must be button element with a role of button, and possess the aria-pressed attribute.
|
|
3
|
-
* @param {ToggleStates[]} toggleStates Array of objects containing toggle buttons state information
|
|
4
|
-
* @param {string} togglesClass The shared class of all the toggle buttons
|
|
5
|
-
* @param {number} currentPressedToggleIndex Index of the currently pressed or unpressed toggle button
|
|
6
|
-
*/
|
|
7
|
-
export function updateGroupTogglesAriaAttributes(toggleStates, togglesClass, currentPressedToggleIndex) {
|
|
8
|
-
var allToggles = Array.from(document.querySelectorAll(".".concat(togglesClass)));
|
|
9
|
-
if (!allToggles) {
|
|
10
|
-
throw new Error('Invalid toggles shared class provided.');
|
|
11
|
-
}
|
|
12
|
-
allToggles.forEach(function (toggle, index) {
|
|
13
|
-
if (index === currentPressedToggleIndex) {
|
|
14
|
-
toggle.setAttribute("aria-pressed", toggleStates[index].pressed ? 'true' : 'false');
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Adds screen reader accessibility to toggle buttons. Updates the aria attributes of the toggle buttons. Button must be button element with a role of button, and possess the aria-pressed attribute.
|
|
3
|
-
* @param {ToggleStates[]} toggleStates Array of objects containing toggle buttons state information
|
|
4
|
-
* @param {string} togglesClass The shared class of all the toggle buttons
|
|
5
|
-
* @param {number} currentPressedToggleIndex Index of the currently pressed or unpressed toggle button
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { HTMLElement, ToggleStates } from "../../../Types";
|
|
9
|
-
|
|
10
|
-
export function updateGroupTogglesAriaAttributes(toggleStates: ToggleStates[], togglesClass: string, currentPressedToggleIndex: number): void {
|
|
11
|
-
const allToggles: HTMLElement[] = Array.from(document.querySelectorAll(`.${togglesClass}`));
|
|
12
|
-
|
|
13
|
-
if ( !allToggles) {
|
|
14
|
-
throw new Error('Invalid toggles shared class provided.');
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
allToggles.forEach((toggle, index) => {
|
|
18
|
-
if (index === currentPressedToggleIndex) {
|
|
19
|
-
toggle.setAttribute("aria-pressed", toggleStates[index].pressed ? 'true' : 'false');
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Adds screen reader accessibility to a single toggle element. Updates the aria attribute of the toggle element. Toggle element must possess the aria-pressed attribute.
|
|
3
|
-
* @param {string} toggleClass The class of all the toggle element
|
|
4
|
-
*/
|
|
5
|
-
export function updateSingleToggleAriaAttribute(toggleClass) {
|
|
6
|
-
var toggle = document.querySelector(".".concat(toggleClass));
|
|
7
|
-
if (!toggle) {
|
|
8
|
-
throw new Error('Invalid toggle class provided.');
|
|
9
|
-
}
|
|
10
|
-
var currentAriaPressedState = toggle.getAttribute('aria-pressed');
|
|
11
|
-
if (!currentAriaPressedState) {
|
|
12
|
-
throw new Error("Toggle element does not have aria-pressed attribute");
|
|
13
|
-
}
|
|
14
|
-
function togglePressed() {
|
|
15
|
-
toggle.setAttribute('aria-pressed', 'true');
|
|
16
|
-
}
|
|
17
|
-
function toggleUnpressed() {
|
|
18
|
-
toggle.setAttribute('aria-pressed', 'false');
|
|
19
|
-
}
|
|
20
|
-
(currentAriaPressedState === 'false') ?
|
|
21
|
-
togglePressed() :
|
|
22
|
-
toggleUnpressed();
|
|
23
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Adds screen reader accessibility to a single toggle element. Updates the aria attribute of the toggle element. Toggle element must possess the aria-pressed attribute.
|
|
3
|
-
* @param {string} toggleClass The class of all the toggle element
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { HTMLElement } from "../../../Types";
|
|
7
|
-
|
|
8
|
-
export function updateSingleToggleAriaAttribute(toggleClass: string): void {
|
|
9
|
-
const toggle: HTMLElement = document.querySelector(`.${toggleClass}`) as HTMLElement;
|
|
10
|
-
|
|
11
|
-
if( !toggle) {
|
|
12
|
-
throw new Error('Invalid toggle class provided.');
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const currentAriaPressedState: string = toggle.getAttribute('aria-pressed') as string
|
|
16
|
-
if(!currentAriaPressedState) {
|
|
17
|
-
throw new Error("Toggle element does not have aria-pressed attribute")
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function togglePressed(): void {
|
|
21
|
-
toggle.setAttribute('aria-pressed', 'true');
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function toggleUnpressed(): void {
|
|
25
|
-
toggle.setAttribute('aria-pressed', 'false');
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
(currentAriaPressedState === 'false') ?
|
|
29
|
-
togglePressed() :
|
|
30
|
-
toggleUnpressed()
|
|
31
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "es5",
|
|
4
|
-
"lib": ["dom", "dom.iterable", "esnext"],
|
|
5
|
-
"allowJs": true,
|
|
6
|
-
"skipLibCheck": true,
|
|
7
|
-
"esModuleInterop": false,
|
|
8
|
-
"allowSyntheticDefaultImports": true,
|
|
9
|
-
"strict": true,
|
|
10
|
-
"forceConsistentCasingInFileNames": true,
|
|
11
|
-
"module": "es2015",
|
|
12
|
-
"moduleResolution": "node",
|
|
13
|
-
"declaration": false
|
|
14
|
-
},
|
|
15
|
-
"include": ["src"]
|
|
16
|
-
}
|
|
17
|
-
|