aria-ease 1.0.0

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.
File without changes
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Isaac
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # Aria-Ease
2
+
3
+ Out of the box utility accessibility package to develop production ready applications.
4
+
5
+ ## Install
6
+
7
+ `npm i aria-ease`
8
+
9
+ ## Usage
10
+
11
+ ```
12
+ import { makeMenuAccessible } from "aria-ease"
13
+
14
+ const App = () => {
15
+ const toggleMenuDisplay = () => {
16
+ const menu: HTMLElement = document.querySelector('#custom-menu') as HTMLElement
17
+ if(getComputedStyle(menu).display === 'none') {
18
+ menu.style.display = 'block'
19
+ makeMenuAccessible('custom-menu', 'profile-menu-item');
20
+ } else {
21
+ menu.style.display = 'none'
22
+ }
23
+ }
24
+
25
+ return (
26
+ <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>
32
+ </div>
33
+ </div>
34
+ )
35
+ }
36
+
37
+ export default App
38
+ ```
package/Types.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ declare global {
2
+ type HTMLElement = Element;
3
+ type NodeListOf<HTMLElement> = Iterable<HTMLElement>;
4
+ }
5
+
6
+ export {
7
+ HTMLElement,
8
+ NodeListOfHTMLElement,
9
+ };
package/aria-ease.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ declare module 'aria-ease';
2
+
3
+ declare function makeMenuAccessible(menuId: string, menuItemClass: string): void;
package/index.js ADDED
@@ -0,0 +1,5 @@
1
+ import { makeMenuAccessible } from './src/menu/makeMenuAccessible.js'
2
+
3
+ export {
4
+ makeMenuAccessible
5
+ }
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "aria-ease",
3
+ "version": "1.0.0",
4
+ "description": "Out of the box utility accessibility package to develop production ready applications.",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/Scriptkidd98/aria-ease.git"
12
+ },
13
+ "keywords": [
14
+ "ARIA",
15
+ "Accessibility"
16
+ ],
17
+ "author": "Isaac Akinduyile",
18
+ "license": "ISC",
19
+ "bugs": {
20
+ "url": "https://github.com/Scriptkidd98/aria-ease/issues"
21
+ },
22
+ "homepage": "https://github.com/Scriptkidd98/aria-ease#readme",
23
+ "types": "./aria-ease.d.ts"
24
+ }
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ /**
3
+ * Adds keyboard navigation to menu.
4
+ * @param {string} menu The id of the menu
5
+ * @param {string} menuItem The class of the items that are children of the menu
6
+ **/
7
+
8
+ function makeMenuAccessible(menu, menuItem) {
9
+ var menuDiv = document.querySelector("#".concat(menu));
10
+ var menuItems = menuDiv.querySelectorAll(".".concat(menuItem));
11
+ menuItems.item(0).focus();
12
+ menuItems.forEach(function (menuItem, menuItemIndex) {
13
+ menuItem.addEventListener('keydown', function (event) { return handleKeyPress(event, menuItems, menuItemIndex); });
14
+ });
15
+ function handleKeyPress(event, menuItems, menuItemIndex) {
16
+ event.preventDefault();
17
+ switch (event.key) {
18
+ case 'ArrowUp':
19
+ case 'ArrowLeft':
20
+ if (menuItemIndex === 0) {
21
+ menuItems.item(menuItems.length - 1).focus();
22
+ }
23
+ else {
24
+ menuItems.item(menuItemIndex - 1).focus();
25
+ }
26
+ break;
27
+ case 'ArrowDown':
28
+ case 'ArrowRight':
29
+ if (menuItemIndex === menuItems.length - 1) {
30
+ menuItems.item(0).focus();
31
+ }
32
+ else {
33
+ menuItems.item(menuItemIndex + 1).focus();
34
+ }
35
+ break;
36
+ default:
37
+ break;
38
+ }
39
+ }
40
+ }
41
+
42
+ export { makeMenuAccessible }
@@ -0,0 +1,41 @@
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
+
7
+ import { HTMLElement, NodeListOfHTMLElement } from '../../Types'
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}`)
12
+
13
+ menuItems.item(0).focus();
14
+ menuItems.forEach((menuItem: HTMLElement, menuItemIndex: number) => {
15
+ menuItem.addEventListener('keydown', (event: KeyboardEvent) => handleKeyPress(event, menuItems, menuItemIndex))
16
+ })
17
+
18
+ function handleKeyPress(event: KeyboardEvent, menuItems: NodeListOfHTMLElement, menuItemIndex: number): void {
19
+ event.preventDefault()
20
+ switch(event.key) {
21
+ case 'ArrowUp':
22
+ case 'ArrowLeft':
23
+ if (menuItemIndex === 0) {
24
+ menuItems.item(menuItems.length - 1).focus();
25
+ } else {
26
+ menuItems.item(menuItemIndex - 1).focus();
27
+ }
28
+ break;
29
+ case 'ArrowDown':
30
+ case 'ArrowRight':
31
+ if (menuItemIndex === menuItems.length - 1) {
32
+ menuItems.item(0).focus();
33
+ } else {
34
+ menuItems.item(menuItemIndex + 1).focus();
35
+ }
36
+ break;
37
+ default:
38
+ break;
39
+ }
40
+ }
41
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,14 @@
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
+ },
12
+ "include": ["src"]
13
+ }
14
+