abledom 0.6.0 → 0.6.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 +91 -1
- package/dist/esm/index.js +504 -14
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.cts +48 -1
- package/dist/index.d.ts +48 -1
- package/dist/index.js +507 -14
- package/dist/index.js.map +1 -1
- package/dist/ts3.9/index.d.ts +42 -1
- package/package.json +13 -13
package/README.md
CHANGED
|
@@ -1,9 +1,99 @@
|
|
|
1
1
|
# AbleDOM
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A continuous accessibility (a11y) monitor for modern web applications.
|
|
4
|
+
|
|
5
|
+
AbleDOM is a lightweight JavaScript/TypeScript library that observes your DOM in real-time and detects common accessibility issues as they appear.
|
|
4
6
|
|
|
5
7
|
_Here be dragons_.
|
|
6
8
|
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install abledom
|
|
13
|
+
# or
|
|
14
|
+
yarn add abledom
|
|
15
|
+
# or
|
|
16
|
+
pnpm add abledom
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Quick start
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { AbleDOM } from "abledom";
|
|
23
|
+
|
|
24
|
+
const _ableDOM = new AbleDOM(window, { log: window.console?.error });
|
|
25
|
+
|
|
26
|
+
// ...Create and add rules and exceptions
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Using rules
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import { AbleDOM, ContrastRule } from "abledom";
|
|
33
|
+
|
|
34
|
+
const contrastRule = new ContrastRule();
|
|
35
|
+
this._ableDOM.addRule(contrastRule);
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Adding valid exceptions
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
import { AbleDOM, ContrastRule } from "abledom";
|
|
42
|
+
|
|
43
|
+
const contrastExceptions: ((element: HTMLElement) => boolean)[] = [
|
|
44
|
+
(element: HTMLElement) => {
|
|
45
|
+
return element.style?.display === "none";
|
|
46
|
+
},
|
|
47
|
+
(element: HTMLElement) => {
|
|
48
|
+
return element.datalist?.ignore === "true";
|
|
49
|
+
},
|
|
50
|
+
];
|
|
51
|
+
|
|
52
|
+
const contrastRule = new ContrastRule();
|
|
53
|
+
|
|
54
|
+
contrastExceptions.forEach((exception) => contrastRule.addException(exception));
|
|
55
|
+
|
|
56
|
+
this._ableDOM.addRule(contrastRule);
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Rules
|
|
60
|
+
|
|
61
|
+
### AtomicRule
|
|
62
|
+
|
|
63
|
+
Detects focusable elements nested inside other atomic focusable elements (like buttons, links, or inputs). Prevents confusing interactive hierarchies that can break keyboard navigation and assistive technology functionality.
|
|
64
|
+
|
|
65
|
+
### BadFocusRule
|
|
66
|
+
|
|
67
|
+
Monitors focus changes to detect when focus is stolen by invisible elements. Helps identify scenarios where focus moves to elements that users cannot see, creating a poor accessibility experience.
|
|
68
|
+
|
|
69
|
+
### ContrastRule
|
|
70
|
+
|
|
71
|
+
Validates color contrast ratios between text and background colors according to WCAG standards. Ensures text meets minimum contrast requirements (4.5:1 for normal text, 3:1 for large text) for readability.
|
|
72
|
+
|
|
73
|
+
### ExistingIdRule
|
|
74
|
+
|
|
75
|
+
Verifies that elements referenced by `aria-labelledby`, `aria-describedby`, or `<label for>` attributes actually exist in the DOM. Prevents broken accessibility relationships.
|
|
76
|
+
|
|
77
|
+
### FocusableElementLabelRule
|
|
78
|
+
|
|
79
|
+
Ensures all focusable interactive elements have accessible labels. Checks for labels through various methods including `<label>` elements, ARIA attributes, alt text, and visible text content.
|
|
80
|
+
|
|
81
|
+
### FocusLostRule
|
|
82
|
+
|
|
83
|
+
Detects when keyboard focus is lost without being moved to another valid element. Monitors focus/blur events to catch scenarios where users might lose their place while navigating with keyboard.
|
|
84
|
+
|
|
85
|
+
### NestedInteractiveElementRule
|
|
86
|
+
|
|
87
|
+
Identifies interactive elements nested within other interactive elements (e.g., a button inside a link). This pattern can confuse users and assistive technologies about which element to interact with.
|
|
88
|
+
|
|
89
|
+
### RequiredParentRule
|
|
90
|
+
|
|
91
|
+
Validates that elements requiring specific parent elements are properly nested. Enforces correct HTML structure for elements like `<li>` (must be in `<ul>` or `<ol>`), table elements, and ARIA roles that have parent requirements.
|
|
92
|
+
|
|
93
|
+
### TabIndexRule
|
|
94
|
+
|
|
95
|
+
Warns about problematic uses of the `tabindex` attribute, including positive values that break natural tab order and `tabindex` on non-interactive elements. Promotes accessible keyboard navigation patterns.
|
|
96
|
+
|
|
7
97
|
## Contributing
|
|
8
98
|
|
|
9
99
|
This project welcomes contributions and suggestions. Most contributions require you to agree to a
|