aria-ease 1.4.7 → 1.4.9
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 +3 -3
- package/Types.d.ts +8 -1
- package/aria-ease.d.ts +41 -8
- package/index.js +12 -4
- package/package.json +1 -1
- package/src/accordion/updateAccordionTriggerAriaAttributes.js +4 -4
- package/src/accordion/updateAccordionTriggerAriaAttributes.ts +4 -4
- package/src/block/makeBlockAccessible.js +1 -1
- package/src/block/makeBlockAccessible.ts +1 -1
- package/src/checkbox/{updateCheckboxAriaAttributes.js → group/updateGroupCheckboxesAriaAttributes.js} +3 -3
- package/src/checkbox/{updateCheckboxAriaAttributes.ts → group/updateGroupCheckboxesAriaAttributes.ts} +4 -4
- package/src/checkbox/single/updateSingleCheckboxAriaAttribute.js +27 -0
- package/src/checkbox/single/updateSingleCheckboxAriaAttribute.ts +34 -0
- package/src/handleKeyPress.js +24 -2
- package/src/handleKeyPress.ts +22 -2
- package/src/menu/cleanUpMenuEventListeners.js +1 -1
- package/src/menu/cleanUpMenuEventListeners.ts +1 -1
- package/src/menu/makeMenuAccessible.js +1 -1
- package/src/menu/makeMenuAccessible.ts +1 -1
- package/src/menu/updateMenuTriggerAriaAttributes.js +2 -2
- package/src/menu/updateMenuTriggerAriaAttributes.ts +2 -2
- package/src/radio/{updateRadioAriaAttributes.js → group/updateGroupRadiosAriaAttributes.js} +3 -3
- package/src/radio/{updateRadioAriaAttributes.ts → group/updateGroupRadiosAriaAttributes.ts} +5 -5
- package/src/radio/single/updateSingleRadioAriaAttribute.js +26 -0
- package/src/radio/single/updateSingleRadioAriaAttribute.ts +34 -0
- package/src/toggle/group/updateGroupTogglesAriaAttributes.js +18 -0
- package/src/toggle/group/updateGroupTogglesAriaAttributes.ts +23 -0
- package/src/toggle/single/updateSingleToggleAriaAttribute.js +26 -0
- package/src/toggle/single/updateSingleToggleAriaAttribute.ts +34 -0
package/README.md
CHANGED
|
@@ -10,11 +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
|
|
13
|
+
Don't spend hours wrestling with accessibility code. Aria-Ease provides pre-built functions that help you integrate accessibility seamlessly into your development workflow. It simplifies the process of adding essential accessibility features (e.g. assistive capability, keyboard navigation, focus management) 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
14
|
|
|
15
|
-
The package currently has support for 5 components: accordions, blocks, checkboxes, menus,
|
|
15
|
+
The package currently has support for 5 components: accordions, blocks, checkboxes, menus, radios, toggle butttons
|
|
16
16
|
|
|
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.
|
|
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
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
20
|
|
package/Types.d.ts
CHANGED
|
@@ -21,10 +21,17 @@ interface RadioStates {
|
|
|
21
21
|
uncheckedAriaLabel: string;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
interface ToggleStates {
|
|
25
|
+
pressed: boolean;
|
|
26
|
+
pressedAriaLabel: string;
|
|
27
|
+
unpressedAriaLabel: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
24
30
|
export {
|
|
25
31
|
HTMLElement,
|
|
26
32
|
NodeListOfHTMLElement,
|
|
27
33
|
AccordionStates,
|
|
28
34
|
CheckboxStates,
|
|
29
|
-
RadioStates
|
|
35
|
+
RadioStates,
|
|
36
|
+
ToggleStates
|
|
30
37
|
};
|
package/aria-ease.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Declares the module 'aria-ease' and includes type information and JSDoc comments.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import { AccordionStates, CheckboxStates, RadioStates } from "./Types";
|
|
5
|
+
import { AccordionStates, CheckboxStates, RadioStates, ToggleStates } from "./Types";
|
|
6
6
|
|
|
7
7
|
declare module 'aria-ease' {
|
|
8
8
|
/**
|
|
@@ -42,28 +42,61 @@ declare module 'aria-ease' {
|
|
|
42
42
|
function updateAccordionTriggerAriaAttributes(accordionStates: AccordionStates[], accordionsClass: string, currentClickedTriggerIndex: number): void;
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
|
-
* Adds screen reader accessibility to
|
|
45
|
+
* Adds screen reader accessibility to a single checkbox. Updates the aria attributes of the checkbox. Checkbox element must possess the following aria attributes; aria-checked and aria-label.
|
|
46
|
+
* @param {string} checkboxClass The shared class of all the checkboxes
|
|
47
|
+
* @param {string} updatedAriaLabel The aria label to be updated to checkbox element
|
|
48
|
+
*/
|
|
49
|
+
function updateSingleCheckboxAriaAttribute(checkboxClass: string, updatedAriaLabel: string): void
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* 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.
|
|
46
53
|
* @param {CheckboxStates[]} checkboxStates Array of objects containing checkboxes state information
|
|
47
54
|
* @param {string} checkboxesClass The shared class of all the checkboxes
|
|
48
55
|
* @param {number} currentPressedCheckboxIndex Index of the currently checked or unchecked checkbox
|
|
49
56
|
*/
|
|
50
|
-
function
|
|
57
|
+
function updateGroupCheckboxesAriaAttributes(checkboxStates: CheckboxStates[], checkboxesClass: string, currentPressedCheckboxIndex: number): void;
|
|
51
58
|
|
|
52
59
|
/**
|
|
53
|
-
* Adds screen reader accessibility to radio buttons. Updates the aria attributes of the radio
|
|
60
|
+
* 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.
|
|
54
61
|
* @param {RadioStates[]} radioStates Array of objects containing radio buttons state information
|
|
55
62
|
* @param {string} radiosClass The shared class of all the radio buttons
|
|
56
63
|
* @param {number} currentPressedRadioIndex Index of the currently checked or unchecked radio button
|
|
57
64
|
*/
|
|
58
|
-
function
|
|
59
|
-
|
|
65
|
+
function updateGroupRadiosAriaAttributes(radioStates: RadioStates[], radiosClass: string, currentPressedRadioIndex: number): void;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Adds screen reader accessibility to a single toggle element. Updates the aria attributes of the toggle element. Toggle element must possess the following aria attributes; aria-pressed and aria-label.
|
|
69
|
+
* @param {string} togglesClass The shared class of all the toggle elements
|
|
70
|
+
* @param {string} updatedAriaLabel The aria label to be updated to toggle element
|
|
71
|
+
*/
|
|
72
|
+
function updateSingleToggleAriaAttribute(toggleClass: string, updatedAriaLabel: string): void
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Adds screen reader accessibility to toggle elements. Updates the aria attributes of the toggle elements. Toggle element must possess the following aria attributes; aria-pressed and aria-label.
|
|
76
|
+
* @param {ToggleStates[]} toggleStates Array of objects containing toggle elements state information
|
|
77
|
+
* @param {string} togglesClass The shared class of all the toggle elements
|
|
78
|
+
* @param {number} currentPressedToggleIndex Index of the currently pressed or unpressed toggle element
|
|
79
|
+
*/
|
|
80
|
+
function updateGroupTogglesAriaAttributes(toggleStates: ToggleStates[], togglesClass: string, currentPressedToggleIndex: number): void
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* 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.
|
|
84
|
+
* @param {string} radioClass The class of the radio button
|
|
85
|
+
* @param {string} updatedAriaLabel The aria label to be updated to button element
|
|
86
|
+
*/
|
|
87
|
+
function updateSingleRadioAriaAttribute(radioClass: string, updatedAriaLabel: string): void
|
|
88
|
+
|
|
60
89
|
export {
|
|
61
90
|
makeMenuAccessible,
|
|
62
91
|
makeBlockAccessible,
|
|
63
92
|
updateMenuTriggerAriaAttributes,
|
|
64
93
|
cleanUpMenuEventListeners,
|
|
65
94
|
updateAccordionTriggerAriaAttributes,
|
|
66
|
-
|
|
67
|
-
|
|
95
|
+
updateSingleCheckboxAriaAttribute,
|
|
96
|
+
updateGroupCheckboxesAriaAttributes,
|
|
97
|
+
updateSingleRadioAriaAttribute,
|
|
98
|
+
updateGroupRadiosAriaAttributes,
|
|
99
|
+
updateSingleToggleAriaAttribute,
|
|
100
|
+
updateGroupTogglesAriaAttributes
|
|
68
101
|
};
|
|
69
102
|
}
|
package/index.js
CHANGED
|
@@ -3,8 +3,12 @@ import { makeBlockAccessible } from './src/block/makeBlockAccessible.js'
|
|
|
3
3
|
import { updateMenuTriggerAriaAttributes } from './src/menu/updateMenuTriggerAriaAttributes.js'
|
|
4
4
|
import { cleanUpMenuEventListeners } from './src/menu/cleanUpMenuEventListeners.js'
|
|
5
5
|
import { updateAccordionTriggerAriaAttributes } from './src/accordion/updateAccordionTriggerAriaAttributes.js'
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
6
|
+
import { updateSingleCheckboxAriaAttribute } from './src/checkbox/single/updateSingleCheckboxAriaAttribute.js'
|
|
7
|
+
import { updateGroupCheckboxesAriaAttributes } from './src/checkbox/group/updateGroupCheckboxesAriaAttributes.js'
|
|
8
|
+
import { updateSingleRadioAriaAttribute } from './src/radio/single/updateSingleRadioAriaAttribute.js'
|
|
9
|
+
import { updateGroupRadiosAriaAttributes } from './src/radio/group/updateGroupRadiosAriaAttributes.js'
|
|
10
|
+
import { updateSingleToggleAriaAttribute } from './src/toggle/single/updateSingleToggleAriaAttribute.js'
|
|
11
|
+
import { updateGroupTogglesAriaAttributes } from './src/toggle/group/updateGroupTogglesAriaAttributes.js'
|
|
8
12
|
|
|
9
13
|
export {
|
|
10
14
|
makeMenuAccessible,
|
|
@@ -12,6 +16,10 @@ export {
|
|
|
12
16
|
updateMenuTriggerAriaAttributes,
|
|
13
17
|
cleanUpMenuEventListeners,
|
|
14
18
|
updateAccordionTriggerAriaAttributes,
|
|
15
|
-
|
|
16
|
-
|
|
19
|
+
updateSingleCheckboxAriaAttribute,
|
|
20
|
+
updateGroupCheckboxesAriaAttributes,
|
|
21
|
+
updateSingleRadioAriaAttribute,
|
|
22
|
+
updateGroupRadiosAriaAttributes,
|
|
23
|
+
updateSingleToggleAriaAttribute,
|
|
24
|
+
updateGroupTogglesAriaAttributes
|
|
17
25
|
}
|
package/package.json
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
* @param {number} currentClickedTriggerIndex Index of the currently clicked accordion trigger
|
|
6
6
|
*/
|
|
7
7
|
export function updateAccordionTriggerAriaAttributes(accordionStates, accordionsClass, currentClickedTriggerIndex) {
|
|
8
|
-
var
|
|
9
|
-
if (!
|
|
10
|
-
throw new Error('Invalid
|
|
8
|
+
var allAccordionTriggers = Array.from(document.querySelectorAll(".".concat(accordionsClass)));
|
|
9
|
+
if (!allAccordionTriggers) {
|
|
10
|
+
throw new Error('Invalid triggers shared class provided.');
|
|
11
11
|
}
|
|
12
|
-
|
|
12
|
+
allAccordionTriggers.forEach(function (trigger, index) {
|
|
13
13
|
if (index === currentClickedTriggerIndex) {
|
|
14
14
|
trigger.setAttribute("aria-expanded", accordionStates[index].display ? 'true' : 'false');
|
|
15
15
|
}
|
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
import { HTMLElement, AccordionStates } from "../../Types";
|
|
9
9
|
|
|
10
10
|
export function updateAccordionTriggerAriaAttributes(accordionStates: AccordionStates[], accordionsClass: string, currentClickedTriggerIndex: number): void {
|
|
11
|
-
const
|
|
11
|
+
const allAccordionTriggers: HTMLElement[] = Array.from(document.querySelectorAll(`.${accordionsClass}`));
|
|
12
12
|
|
|
13
|
-
if ( !
|
|
14
|
-
throw new Error('Invalid
|
|
13
|
+
if ( !allAccordionTriggers) {
|
|
14
|
+
throw new Error('Invalid triggers shared class provided.');
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
allAccordionTriggers.forEach((trigger, index) => {
|
|
18
18
|
if (index === currentClickedTriggerIndex) {
|
|
19
19
|
trigger.setAttribute("aria-expanded", accordionStates[index].display ? 'true' : 'false');
|
|
20
20
|
} else {
|
|
@@ -12,7 +12,7 @@ export function makeBlockAccessible(blockId, blockItemsClass) {
|
|
|
12
12
|
}
|
|
13
13
|
var blockItems = blockDiv.querySelectorAll(".".concat(blockItemsClass));
|
|
14
14
|
if (!blockItems) {
|
|
15
|
-
throw new Error('Invalid block items class provided.');
|
|
15
|
+
throw new Error('Invalid block items shared class provided.');
|
|
16
16
|
}
|
|
17
17
|
blockItems.forEach(function (blockItem, blockItemIndex) {
|
|
18
18
|
if (!eventListenersAdded.has(blockItem)) {
|
|
@@ -17,7 +17,7 @@ export function makeBlockAccessible(blockId: string, blockItemsClass: string) {
|
|
|
17
17
|
|
|
18
18
|
const blockItems: NodeListOfHTMLElement = blockDiv.querySelectorAll(`.${blockItemsClass}`);
|
|
19
19
|
if(!blockItems) {
|
|
20
|
-
throw new Error('Invalid block items class provided.');
|
|
20
|
+
throw new Error('Invalid block items shared class provided.');
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
blockItems.forEach((blockItem: HTMLElement, blockItemIndex: number): void => {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Adds screen reader accessibility to checkboxes. Updates the aria attributes of the
|
|
2
|
+
* 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.
|
|
3
3
|
* @param {CheckboxStates[]} checkboxStates Array of objects containing checkboxes state information
|
|
4
4
|
* @param {string} checkboxesClass The shared class of all the checkboxes
|
|
5
5
|
* @param {number} currentPressedCheckboxIndex Index of the currently checked or unchecked checkbox
|
|
6
6
|
*/
|
|
7
|
-
export function
|
|
7
|
+
export function updateGroupCheckboxesAriaAttributes(checkboxStates, checkboxesClass, currentPressedCheckboxIndex) {
|
|
8
8
|
var allCheckboxes = Array.from(document.querySelectorAll(".".concat(checkboxesClass)));
|
|
9
9
|
if (!allCheckboxes) {
|
|
10
|
-
throw new Error('Invalid checkboxes class provided.');
|
|
10
|
+
throw new Error('Invalid checkboxes shared class provided.');
|
|
11
11
|
}
|
|
12
12
|
;
|
|
13
13
|
allCheckboxes.forEach(function (checkbox, index) {
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Adds screen reader accessibility to checkboxes. Updates the aria attributes of the
|
|
2
|
+
* 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.
|
|
3
3
|
* @param {CheckboxStates[]} checkboxStates Array of objects containing checkboxes state information
|
|
4
4
|
* @param {string} checkboxesClass The shared class of all the checkboxes
|
|
5
5
|
* @param {number} currentPressedCheckboxIndex Index of the currently checked or unchecked checkbox
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import { HTMLElement, CheckboxStates } from "
|
|
8
|
+
import { HTMLElement, CheckboxStates } from "../../../Types";
|
|
9
9
|
|
|
10
|
-
export function
|
|
10
|
+
export function updateGroupCheckboxesAriaAttributes(checkboxStates: CheckboxStates[], checkboxesClass: string, currentPressedCheckboxIndex: number): void {
|
|
11
11
|
const allCheckboxes: HTMLElement[] = Array.from(document.querySelectorAll(`.${checkboxesClass}`));
|
|
12
12
|
|
|
13
13
|
if ( !allCheckboxes) {
|
|
14
|
-
throw new Error('Invalid checkboxes class provided.');
|
|
14
|
+
throw new Error('Invalid checkboxes shared class provided.');
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
allCheckboxes.forEach((checkbox, index) => {
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adds screen reader accessibility to a single checkbox. Updates the aria attributes of the checkbox. Checkbox element must possess the following aria attributes; aria-checked and aria-label.
|
|
3
|
+
* @param {string} checkboxClass The shared class of all the checkboxes
|
|
4
|
+
* @param {string} updatedAriaLabel The aria label to be updated to checkbox element
|
|
5
|
+
*/
|
|
6
|
+
export function updateSingleCheckboxAriaAttribute(checkboxClass, updatedAriaLabel) {
|
|
7
|
+
var checkbox = document.querySelector(".".concat(checkboxClass));
|
|
8
|
+
if (!checkbox) {
|
|
9
|
+
throw new Error('Invalid checkbox class provided.');
|
|
10
|
+
}
|
|
11
|
+
;
|
|
12
|
+
var currentAriaCheckedState = checkbox.getAttribute('aria-checked');
|
|
13
|
+
if (!currentAriaCheckedState) {
|
|
14
|
+
throw new Error("Checkbox element does not have aria-checked attribute");
|
|
15
|
+
}
|
|
16
|
+
function checkboxChecked(ariaLabel) {
|
|
17
|
+
checkbox.setAttribute('aria-checked', 'true');
|
|
18
|
+
checkbox.setAttribute('aria-label', ariaLabel);
|
|
19
|
+
}
|
|
20
|
+
function checkboxUnchecked(ariaLabel) {
|
|
21
|
+
checkbox.setAttribute('aria-checked', 'false');
|
|
22
|
+
checkbox.setAttribute('aria-label', ariaLabel);
|
|
23
|
+
}
|
|
24
|
+
(currentAriaCheckedState === 'false') ?
|
|
25
|
+
checkboxChecked(updatedAriaLabel) :
|
|
26
|
+
checkboxUnchecked(updatedAriaLabel);
|
|
27
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adds screen reader accessibility to a single checkbox. Updates the aria attributes of the checkbox. Checkbox element must possess the following aria attributes; aria-checked and aria-label.
|
|
3
|
+
* @param {string} checkboxClass The shared class of all the checkboxes
|
|
4
|
+
* @param {string} updatedAriaLabel The aria label to be updated to checkbox element
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { HTMLElement } from "../../../Types";
|
|
8
|
+
|
|
9
|
+
export function updateSingleCheckboxAriaAttribute(checkboxClass: string, updatedAriaLabel: string): void {
|
|
10
|
+
const checkbox: HTMLElement = document.querySelector(`.${checkboxClass}`) as HTMLElement;
|
|
11
|
+
|
|
12
|
+
if ( !checkbox) {
|
|
13
|
+
throw new Error('Invalid checkbox class provided.');
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const currentAriaCheckedState: string = checkbox.getAttribute('aria-checked') as string
|
|
17
|
+
if(!currentAriaCheckedState) {
|
|
18
|
+
throw new Error("Checkbox element does not have aria-checked attribute")
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function checkboxChecked(ariaLabel: string): void {
|
|
22
|
+
checkbox.setAttribute('aria-checked', 'true');
|
|
23
|
+
checkbox.setAttribute('aria-label', ariaLabel);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function checkboxUnchecked(ariaLabel: string): void {
|
|
27
|
+
checkbox.setAttribute('aria-checked', 'false');
|
|
28
|
+
checkbox.setAttribute('aria-label', ariaLabel);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
(currentAriaCheckedState === 'false') ?
|
|
32
|
+
checkboxChecked(updatedAriaLabel) :
|
|
33
|
+
checkboxUnchecked(updatedAriaLabel)
|
|
34
|
+
}
|
package/src/handleKeyPress.js
CHANGED
|
@@ -11,7 +11,7 @@ export function handleKeyPress(event, elementItems, elementItemIndex, menuElemen
|
|
|
11
11
|
switch (event.key) {
|
|
12
12
|
case 'ArrowUp':
|
|
13
13
|
case 'ArrowLeft':
|
|
14
|
-
if ((elementItems.item(elementItemIndex).tagName !== 'INPUT') || (elementItems.item(elementItemIndex).tagName === 'INPUT' && elementItems.item(elementItemIndex).type
|
|
14
|
+
if ((elementItems.item(elementItemIndex).tagName !== 'INPUT') || (elementItems.item(elementItemIndex).tagName === 'INPUT' && elementItems.item(elementItemIndex).type !== 'text')) {
|
|
15
15
|
event.preventDefault();
|
|
16
16
|
if (elementItemIndex === 0) {
|
|
17
17
|
elementItems.item(elementItems.length - 1).focus();
|
|
@@ -20,10 +20,21 @@ export function handleKeyPress(event, elementItems, elementItemIndex, menuElemen
|
|
|
20
20
|
elementItems.item(elementItemIndex - 1).focus();
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
+
if ((elementItems.item(elementItemIndex).tagName === 'INPUT' && elementItems.item(elementItemIndex).type === 'text') || (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
|
+
}
|
|
23
34
|
break;
|
|
24
35
|
case 'ArrowDown':
|
|
25
36
|
case 'ArrowRight':
|
|
26
|
-
if ((elementItems.item(elementItemIndex).tagName !== 'INPUT') || (elementItems.item(elementItemIndex).tagName === 'INPUT' && elementItems.item(elementItemIndex).type
|
|
37
|
+
if ((elementItems.item(elementItemIndex).tagName !== 'INPUT') || (elementItems.item(elementItemIndex).tagName === 'INPUT' && elementItems.item(elementItemIndex).type !== 'text')) {
|
|
27
38
|
event.preventDefault();
|
|
28
39
|
if (elementItemIndex === elementItems.length - 1) {
|
|
29
40
|
elementItems.item(0).focus();
|
|
@@ -32,6 +43,17 @@ export function handleKeyPress(event, elementItems, elementItemIndex, menuElemen
|
|
|
32
43
|
elementItems.item(elementItemIndex + 1).focus();
|
|
33
44
|
}
|
|
34
45
|
}
|
|
46
|
+
if ((elementItems.item(elementItemIndex).tagName === 'INPUT' && elementItems.item(elementItemIndex).type === 'text') || (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
|
+
}
|
|
35
57
|
break;
|
|
36
58
|
case 'Escape':
|
|
37
59
|
event.preventDefault();
|
package/src/handleKeyPress.ts
CHANGED
|
@@ -15,7 +15,7 @@ export function handleKeyPress(event: KeyboardEvent, elementItems: NodeListOfHTM
|
|
|
15
15
|
switch(event.key) {
|
|
16
16
|
case 'ArrowUp':
|
|
17
17
|
case 'ArrowLeft':
|
|
18
|
-
if((elementItems.item(elementItemIndex).tagName !== 'INPUT') || (elementItems.item(elementItemIndex).tagName === 'INPUT' && elementItems.item(elementItemIndex).type
|
|
18
|
+
if((elementItems.item(elementItemIndex).tagName !== 'INPUT') || (elementItems.item(elementItemIndex).tagName === 'INPUT' && elementItems.item(elementItemIndex).type !== 'text')) {
|
|
19
19
|
event.preventDefault()
|
|
20
20
|
if (elementItemIndex === 0) {
|
|
21
21
|
elementItems.item(elementItems.length - 1).focus();
|
|
@@ -23,10 +23,20 @@ export function handleKeyPress(event: KeyboardEvent, elementItems: NodeListOfHTM
|
|
|
23
23
|
elementItems.item(elementItemIndex - 1).focus();
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
+
if((elementItems.item(elementItemIndex).tagName === 'INPUT' && elementItems.item(elementItemIndex).type === 'text') || (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
|
+
}
|
|
26
36
|
break;
|
|
27
37
|
case 'ArrowDown':
|
|
28
38
|
case 'ArrowRight':
|
|
29
|
-
if((elementItems.item(elementItemIndex).tagName !== 'INPUT') || (elementItems.item(elementItemIndex).tagName === 'INPUT' && elementItems.item(elementItemIndex).type
|
|
39
|
+
if((elementItems.item(elementItemIndex).tagName !== 'INPUT') || (elementItems.item(elementItemIndex).tagName === 'INPUT' && elementItems.item(elementItemIndex).type !== 'text')) {
|
|
30
40
|
event.preventDefault()
|
|
31
41
|
if (elementItemIndex === elementItems.length - 1) {
|
|
32
42
|
elementItems.item(0).focus();
|
|
@@ -34,6 +44,16 @@ export function handleKeyPress(event: KeyboardEvent, elementItems: NodeListOfHTM
|
|
|
34
44
|
elementItems.item(elementItemIndex + 1).focus();
|
|
35
45
|
}
|
|
36
46
|
}
|
|
47
|
+
if((elementItems.item(elementItemIndex).tagName === 'INPUT' && elementItems.item(elementItemIndex).type === 'text') || (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
|
+
}
|
|
37
57
|
break;
|
|
38
58
|
case 'Escape':
|
|
39
59
|
event.preventDefault();
|
|
@@ -6,7 +6,7 @@ export function cleanUpMenuEventListeners(menuId, menuItemsClass) {
|
|
|
6
6
|
}
|
|
7
7
|
var menuItems = menuDiv.querySelectorAll(".".concat(menuItemsClass));
|
|
8
8
|
if (!menuItems) {
|
|
9
|
-
throw new Error("Invalid menu items class provided");
|
|
9
|
+
throw new Error("Invalid menu items shared class provided");
|
|
10
10
|
}
|
|
11
11
|
var triggerId = menuDiv.getAttribute('aria-labelledby');
|
|
12
12
|
if (!triggerId) {
|
|
@@ -10,7 +10,7 @@ export function cleanUpMenuEventListeners(menuId: string, menuItemsClass: string
|
|
|
10
10
|
|
|
11
11
|
const menuItems: NodeListOfHTMLElement = menuDiv.querySelectorAll(`.${menuItemsClass}`)
|
|
12
12
|
if(!menuItems) {
|
|
13
|
-
throw new Error("Invalid menu items class provided")
|
|
13
|
+
throw new Error("Invalid menu items shared class provided")
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
const triggerId: string = menuDiv.getAttribute('aria-labelledby') as string
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
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
|
|
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
5
|
*/
|
|
6
6
|
export function updateMenuTriggerAriaAttributes(triggerId, ariaLabel) {
|
|
7
7
|
var triggerButton = document.querySelector("#".concat(triggerId));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
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
|
|
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
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { HTMLElement } from "../../Types";
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Adds screen reader accessibility to radio buttons. Updates the aria attributes of the radio
|
|
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
3
|
* @param {RadioStates[]} radioStates Array of objects containing radio buttons state information
|
|
4
4
|
* @param {string} radiosClass The shared class of all the radio buttons
|
|
5
5
|
* @param {number} currentPressedRadioIndex Index of the currently checked or unchecked radio button
|
|
6
6
|
*/
|
|
7
|
-
export function
|
|
7
|
+
export function updateGroupRadiosAriaAttributes(radioStates, radiosClass, currentPressedRadioIndex) {
|
|
8
8
|
var allRadios = Array.from(document.querySelectorAll(".".concat(radiosClass)));
|
|
9
9
|
if (!allRadios) {
|
|
10
|
-
throw new Error('Invalid radios class provided.');
|
|
10
|
+
throw new Error('Invalid radios shared class provided.');
|
|
11
11
|
}
|
|
12
12
|
allRadios.forEach(function (radio, index) {
|
|
13
13
|
if (index === currentPressedRadioIndex) {
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Adds screen reader accessibility to radio buttons. Updates the aria attributes of the radio
|
|
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
3
|
* @param {RadioStates[]} radioStates Array of objects containing radio buttons state information
|
|
4
4
|
* @param {string} radiosClass The shared class of all the radio buttons
|
|
5
5
|
* @param {number} currentPressedRadioIndex Index of the currently checked or unchecked radio button
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import { HTMLElement, RadioStates } from "
|
|
8
|
+
import { HTMLElement, RadioStates } from "../../../Types";
|
|
9
9
|
|
|
10
|
-
export function
|
|
10
|
+
export function updateGroupRadiosAriaAttributes(radioStates: RadioStates[], radiosClass: string, currentPressedRadioIndex: number): void {
|
|
11
11
|
const allRadios: HTMLElement[] = Array.from(document.querySelectorAll(`.${radiosClass}`));
|
|
12
12
|
|
|
13
|
-
if
|
|
14
|
-
throw new Error('Invalid radios class provided.');
|
|
13
|
+
if( !allRadios) {
|
|
14
|
+
throw new Error('Invalid radios shared class provided.');
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
allRadios.forEach((radio, index) => {
|
|
@@ -0,0 +1,26 @@
|
|
|
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(ariaLabel) {
|
|
16
|
+
radio.setAttribute('aria-checked', 'true');
|
|
17
|
+
radio.setAttribute('aria-label', ariaLabel);
|
|
18
|
+
}
|
|
19
|
+
function radioUnchecked(ariaLabel) {
|
|
20
|
+
radio.setAttribute('aria-checked', 'false');
|
|
21
|
+
radio.setAttribute('aria-label', ariaLabel);
|
|
22
|
+
}
|
|
23
|
+
(currentAriaCheckedState === 'false') ?
|
|
24
|
+
radioChecked(updatedAriaLabel) :
|
|
25
|
+
radioUnchecked(updatedAriaLabel);
|
|
26
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
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(ariaLabel: string): void {
|
|
22
|
+
radio.setAttribute('aria-checked', 'true');
|
|
23
|
+
radio.setAttribute('aria-label', ariaLabel);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function radioUnchecked(ariaLabel: string): void {
|
|
27
|
+
radio.setAttribute('aria-checked', 'false');
|
|
28
|
+
radio.setAttribute('aria-label', ariaLabel);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
(currentAriaCheckedState === 'false') ?
|
|
32
|
+
radioChecked(updatedAriaLabel) :
|
|
33
|
+
radioUnchecked(updatedAriaLabel)
|
|
34
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
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 following aria attributes; aria-pressed and aria-label.
|
|
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
|
+
toggle.setAttribute("aria-label", toggleStates[index].pressed ? toggleStates[index].pressedAriaLabel : toggleStates[index].unpressedAriaLabel);
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
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 following aria attributes; aria-pressed and aria-label.
|
|
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
|
+
toggle.setAttribute("aria-label", toggleStates[index].pressed ? toggleStates[index].pressedAriaLabel : toggleStates[index].unpressedAriaLabel);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adds screen reader accessibility to a single toggle element. Updates the aria attributes of the toggle element. Toggle element must possess the following aria attributes; aria-pressed and aria-label.
|
|
3
|
+
* @param {string} toggleClass The class of all the toggle element
|
|
4
|
+
* @param {string} updatedAriaLabel The aria label to be updated to toggle element
|
|
5
|
+
*/
|
|
6
|
+
export function updateSingleToggleAriaAttribute(toggleClass, updatedAriaLabel) {
|
|
7
|
+
var toggle = document.querySelector(".".concat(toggleClass));
|
|
8
|
+
if (!toggle) {
|
|
9
|
+
throw new Error('Invalid toggle class provided.');
|
|
10
|
+
}
|
|
11
|
+
var currentAriaPressedState = toggle.getAttribute('aria-pressed');
|
|
12
|
+
if (!currentAriaPressedState) {
|
|
13
|
+
throw new Error("Toggle element does not have aria-pressed attribute");
|
|
14
|
+
}
|
|
15
|
+
function togglePressed(ariaLabel) {
|
|
16
|
+
toggle.setAttribute('aria-pressed', 'true');
|
|
17
|
+
toggle.setAttribute('aria-label', ariaLabel);
|
|
18
|
+
}
|
|
19
|
+
function toggleUnpressed(ariaLabel) {
|
|
20
|
+
toggle.setAttribute('aria-pressed', 'false');
|
|
21
|
+
toggle.setAttribute('aria-label', ariaLabel);
|
|
22
|
+
}
|
|
23
|
+
(currentAriaPressedState === 'false') ?
|
|
24
|
+
togglePressed(updatedAriaLabel) :
|
|
25
|
+
toggleUnpressed(updatedAriaLabel);
|
|
26
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adds screen reader accessibility to a single toggle element. Updates the aria attributes of the toggle element. Toggle element must possess the following aria attributes; aria-pressed and aria-label.
|
|
3
|
+
* @param {string} toggleClass The class of all the toggle element
|
|
4
|
+
* @param {string} updatedAriaLabel The aria label to be updated to toggle element
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { HTMLElement } from "../../../Types";
|
|
8
|
+
|
|
9
|
+
export function updateSingleToggleAriaAttribute(toggleClass: string, updatedAriaLabel: string): void {
|
|
10
|
+
const toggle: HTMLElement = document.querySelector(`.${toggleClass}`) as HTMLElement;
|
|
11
|
+
|
|
12
|
+
if( !toggle) {
|
|
13
|
+
throw new Error('Invalid toggle class provided.');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const currentAriaPressedState: string = toggle.getAttribute('aria-pressed') as string
|
|
17
|
+
if(!currentAriaPressedState) {
|
|
18
|
+
throw new Error("Toggle element does not have aria-pressed attribute")
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function togglePressed(ariaLabel: string): void {
|
|
22
|
+
toggle.setAttribute('aria-pressed', 'true');
|
|
23
|
+
toggle.setAttribute('aria-label', ariaLabel);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function toggleUnpressed(ariaLabel: string): void {
|
|
27
|
+
toggle.setAttribute('aria-pressed', 'false');
|
|
28
|
+
toggle.setAttribute('aria-label', ariaLabel);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
(currentAriaPressedState === 'false') ?
|
|
32
|
+
togglePressed(updatedAriaLabel) :
|
|
33
|
+
toggleUnpressed(updatedAriaLabel)
|
|
34
|
+
}
|