aria-ease 1.0.4 → 1.0.6

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 CHANGED
@@ -9,10 +9,10 @@ Out of the box accessibility utility package to develop production ready applica
9
9
  ## Usage
10
10
 
11
11
  ```
12
- import { makeMenuAccessible } from "aria-ease"
12
+ import { makeMenuAccessible, makeTabAccessible } from "aria-ease"
13
13
 
14
14
  const App = () => {
15
- const toggleMenuDisplay = () => {
15
+ const toggleMenuDisplay = (): void => {
16
16
  const menu: HTMLElement = document.querySelector('#custom-menu') as HTMLElement
17
17
  if(getComputedStyle(menu).display === 'none') {
18
18
  menu.style.display = 'block'
@@ -22,13 +22,25 @@ const App = () => {
22
22
  }
23
23
  }
24
24
 
25
+ const handleTabButtonClick = (): void => {
26
+ makeTabAccessible('custom-tab', 'custom-tab-item')
27
+ }
28
+
25
29
  return (
26
30
  <div>
27
- <button onClick={toggleMenuDisplay}>Display</button>
28
- <div id="custom-menu" role="menu">
29
- <button role="menuitem" className="profile-menu-item">One</button>
30
- <button role="menuitem" className="profile-menu-item">Two</button>
31
- <button role="menuitem" className="profile-menu-item">Three</button>
31
+ <>
32
+ <button id="display-button" onClick={toggleMenuDisplay}>Display</button>
33
+ <div id="custom-menu" role="menu" aria-labelledby="display-button">
34
+ <button role="menuitem" className="profile-menu-item">One</button>
35
+ <button role="menuitem" className="profile-menu-item">Two</button>
36
+ <button role="menuitem" className="profile-menu-item">Three</button>
37
+ </div>
38
+ </>
39
+
40
+ <div id="custom-tab">
41
+ <button className="custom-tab-item" onClick={handleTabButtonClick}>One</button>
42
+ <button className="custom-tab-item" onClick={handleTabButtonClick}>Two</button>
43
+ <button className="custom-tab-item" onClick={handleTabButtonClick}>Three</button>
32
44
  </div>
33
45
  </div>
34
46
  )
package/aria-ease.d.ts CHANGED
@@ -1,5 +1,21 @@
1
- declare module 'aria-ease';
2
-
3
- declare function makeMenuAccessible(menuId: string, menuItemClass: string): void;
4
-
5
- export { makeMenuAccessible }
1
+ /**
2
+ * Declares the module 'aria-ease' and includes type information and JSDoc comments.
3
+ */
4
+ declare module 'aria-ease' {
5
+ /**
6
+ * Adds keyboard navigation 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.
7
+ * @param {string} menuId - The id of the menu.
8
+ * @param {string} menuItemClass - The class of the items that are children of the menu.
9
+ */
10
+ declare function makeMenuAccessible(menuId: string, menuItemClass: string): void;
11
+
12
+ /**
13
+ * Adds keyboard navigation to tab. The tab traps focus and can be interacted with using the keyboard.
14
+ * @param {string} tabId - The id of the tab container.
15
+ * @param {string} tabItemClass - The class of the individual tab items.
16
+ */
17
+ declare function makeTabAccessible(tabId: string, tabItemClass: string): void;
18
+
19
+ export { makeMenuAccessible, makeTabAccessible };
20
+ }
21
+
package/index.js CHANGED
@@ -1,5 +1,7 @@
1
1
  import { makeMenuAccessible } from './src/menu/makeMenuAccessible.js'
2
+ import { makeTabAccessible } from './src/tab/makeTabAccessible.js'
2
3
 
3
4
  export {
4
- makeMenuAccessible
5
+ makeMenuAccessible,
6
+ makeTabAccessible
5
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aria-ease",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "Out of the box utility accessibility package to develop production ready applications.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Adds keyboard navigation 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} menuItemClass The class of the items that are children of the menu
5
+ */
6
+ export declare function makeMenuAccessible(menuId: string, menuItemClass: string): void;
@@ -1,11 +1,11 @@
1
1
  /**
2
- * Adds keyboard navigation to menu.
3
- * @param {string} menu The id of the menu
4
- * @param {string} menuItem The class of the items that are children of the menu
5
- **/
6
- export function makeMenuAccessible(menu, menuItem) {
7
- var menuDiv = document.querySelector("#".concat(menu));
8
- var menuItems = menuDiv.querySelectorAll(".".concat(menuItem));
2
+ * Adds keyboard navigation 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} menuItemClass The class of the items that are children of the menu
5
+ */
6
+ export function makeMenuAccessible(menuId, menuItemClass) {
7
+ var menuDiv = document.querySelector("#".concat(menuId));
8
+ var menuItems = menuDiv.querySelectorAll(".".concat(menuItemClass));
9
9
  var triggerId = menuDiv.getAttribute('aria-labelledby');
10
10
  var triggerButton = document.querySelector("#".concat(triggerId));
11
11
  menuItems.item(0).focus();
@@ -1,21 +1,21 @@
1
1
  /**
2
- * Adds keyboard navigation to menu.
3
- * @param {string} menu The id of the menu
4
- * @param {string} menuItem The class of the items that are children of the menu
5
- **/
2
+ * Adds keyboard navigation 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} menuItemClass The class of the items that are children of the menu
5
+ */
6
6
 
7
7
  import { HTMLElement, NodeListOfHTMLElement } from '../../Types'
8
8
 
9
- export function makeMenuAccessible(menu: string, menuItem: string): void {
10
- const menuDiv: HTMLElement = document.querySelector(`#${menu}`) as HTMLElement
11
- const menuItems: NodeListOfHTMLElement = menuDiv.querySelectorAll(`.${menuItem}`)
9
+ export function makeMenuAccessible(menuId: string, menuItemClass: string): void {
10
+ const menuDiv: HTMLElement = document.querySelector(`#${menuId}`) as HTMLElement
11
+ const menuItems: NodeListOfHTMLElement = menuDiv.querySelectorAll(`.${menuItemClass}`)
12
12
 
13
13
  const triggerId: string = menuDiv.getAttribute('aria-labelledby') as string
14
14
  const triggerButton: HTMLElement = document.querySelector(`#${triggerId}`) as HTMLElement
15
15
 
16
16
  menuItems.item(0).focus();
17
- menuItems.forEach((menuItem: HTMLElement, menuItemIndex: number) => {
18
- menuItem.addEventListener('keydown', (event: KeyboardEvent) => handleKeyPress(event, menuItems, menuItemIndex))
17
+ menuItems.forEach((menuItem: HTMLElement, menuItemIndex: number): void => {
18
+ menuItem.addEventListener('keydown', (event: KeyboardEvent): void => handleKeyPress(event, menuItems, menuItemIndex))
19
19
  })
20
20
 
21
21
  function handleKeyPress(event: KeyboardEvent, menuItems: NodeListOfHTMLElement, menuItemIndex: number): void {
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Adds keyboard navigation to tab. The tab traps focus and can be interacted with using the keyboard.
3
+ * @param {string} tabId The id of the tab
4
+ * @param {string} tabItemClass The class of the items that are children of the tab
5
+ */
6
+ export declare function makeTabAccessible(tabId: string, tabItemClass: string): void;
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Adds keyboard navigation to tab. The tab traps focus and can be interacted with using the keyboard.
3
+ * @param {string} tabId The id of the tab
4
+ * @param {string} tabItemClass The class of the items that are children of the tab
5
+ */
6
+ export function makeTabAccessible(tabId, tabItemClass) {
7
+ var tabDiv = document.querySelector("#".concat(tabId));
8
+ var tabItems = tabDiv.querySelectorAll(".".concat(tabItemClass));
9
+ tabItems.forEach(function (tabItem, tabItemIndex) {
10
+ tabItem.addEventListener('keydown', function (event) { return handleKeyPress(event, tabItems, tabItemIndex); });
11
+ });
12
+ function handleKeyPress(event, tabItems, tabItemIndex) {
13
+ event.preventDefault();
14
+ switch (event.key) {
15
+ case 'ArrowUp':
16
+ case 'ArrowLeft':
17
+ if (tabItemIndex === 0) {
18
+ tabItems.item(tabItems.length - 1).focus();
19
+ }
20
+ else {
21
+ tabItems.item(tabItemIndex - 1).focus();
22
+ }
23
+ break;
24
+ case 'ArrowDown':
25
+ case 'ArrowRight':
26
+ if (tabItemIndex === tabItems.length - 1) {
27
+ tabItems.item(0).focus();
28
+ }
29
+ else {
30
+ tabItems.item(tabItemIndex + 1).focus();
31
+ }
32
+ break;
33
+ default:
34
+ break;
35
+ }
36
+ }
37
+ }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Adds keyboard navigation to tab. The tab traps focus and can be interacted with using the keyboard.
3
+ * @param {string} tabId The id of the tab
4
+ * @param {string} tabItemClass The class of the items that are children of the tab
5
+ */
6
+
7
+ import { HTMLElement, NodeListOfHTMLElement } from "../../Types"
8
+
9
+ export function makeTabAccessible(tabId: string, tabItemClass: string): void {
10
+ const tabDiv: HTMLElement = document.querySelector(`#${tabId}`) as HTMLElement
11
+ const tabItems: NodeListOfHTMLElement = tabDiv.querySelectorAll(`.${tabItemClass}`)
12
+
13
+ tabItems.forEach((tabItem: HTMLElement, tabItemIndex: number): void => {
14
+ tabItem.addEventListener('keydown', (event: KeyboardEvent) => handleKeyPress(event, tabItems, tabItemIndex))
15
+ })
16
+
17
+ function handleKeyPress(event: KeyboardEvent, tabItems: NodeListOfHTMLElement, tabItemIndex: number): void {
18
+ event.preventDefault()
19
+ switch(event.key) {
20
+ case 'ArrowUp':
21
+ case 'ArrowLeft':
22
+ if (tabItemIndex === 0) {
23
+ tabItems.item(tabItems.length - 1).focus();
24
+ } else {
25
+ tabItems.item(tabItemIndex - 1).focus();
26
+ }
27
+ break;
28
+ case 'ArrowDown':
29
+ case 'ArrowRight':
30
+ if (tabItemIndex === tabItems.length - 1) {
31
+ tabItems.item(0).focus();
32
+ } else {
33
+ tabItems.item(tabItemIndex + 1).focus();
34
+ }
35
+ break;
36
+ default:
37
+ break;
38
+ }
39
+ }
40
+ }
package/tsconfig.json CHANGED
@@ -9,7 +9,8 @@
9
9
  "strict": true,
10
10
  "forceConsistentCasingInFileNames": true,
11
11
  "module": "es2015",
12
- "moduleResolution": "node"
12
+ "moduleResolution": "node",
13
+ "declaration": true
13
14
  },
14
15
  "include": ["src"]
15
16
  }