@compa11y/core 0.1.5 → 0.1.8
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 +15 -133
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -8,152 +8,34 @@ Framework-agnostic accessibility primitives for building accessible UI component
|
|
|
8
8
|
npm install @compa11y/core
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## What's included
|
|
12
12
|
|
|
13
|
-
- **Focus Management** — Focus traps, focus scope, roving tabindex
|
|
14
|
-
- **Keyboard Navigation** — Pre-built patterns for menus, tabs, grids
|
|
15
|
-
- **Screen Reader Support** — Live region announcements
|
|
16
|
-
- **ARIA Utilities** — Helpers for managing ARIA attributes
|
|
13
|
+
- **Focus Management** — Focus traps, focus scope, roving tabindex, focus neighbor/return
|
|
14
|
+
- **Keyboard Navigation** — Pre-built patterns for menus, tabs, grids, dialogs
|
|
15
|
+
- **Screen Reader Support** — Live region announcements (polite & assertive)
|
|
16
|
+
- **ARIA Utilities** — Helpers for managing ARIA attributes and relationships
|
|
17
|
+
- **Platform Detection** — Detect reduced motion, high contrast, dark mode preferences
|
|
17
18
|
- **Dev Warnings** — Catch accessibility issues during development
|
|
18
19
|
|
|
19
|
-
##
|
|
20
|
-
|
|
21
|
-
### Focus Trap
|
|
20
|
+
## Quick start
|
|
22
21
|
|
|
23
22
|
```ts
|
|
24
|
-
import { createFocusTrap } from '@compa11y/core';
|
|
25
|
-
|
|
26
|
-
const dialog = document.getElementById('dialog');
|
|
27
|
-
const trap = createFocusTrap(dialog, {
|
|
28
|
-
escapeDeactivates: true,
|
|
29
|
-
returnFocus: true,
|
|
30
|
-
});
|
|
23
|
+
import { createFocusTrap, announce, aria } from '@compa11y/core';
|
|
31
24
|
|
|
32
|
-
//
|
|
25
|
+
// Trap focus in a dialog
|
|
26
|
+
const trap = createFocusTrap(dialogElement, { escapeDeactivates: true });
|
|
33
27
|
trap.activate();
|
|
34
28
|
|
|
35
|
-
//
|
|
36
|
-
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
### Announcements
|
|
40
|
-
|
|
41
|
-
```ts
|
|
42
|
-
import { announce, announcePolite, announceAssertive } from '@compa11y/core';
|
|
43
|
-
|
|
44
|
-
// Polite announcement (doesn't interrupt)
|
|
45
|
-
announcePolite('Item added to cart');
|
|
46
|
-
|
|
47
|
-
// Assertive announcement (interrupts current speech)
|
|
48
|
-
announceAssertive('Error: Form submission failed');
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
### Keyboard Navigation
|
|
29
|
+
// Announce to screen readers
|
|
30
|
+
announce('Item added to cart');
|
|
52
31
|
|
|
53
|
-
|
|
54
|
-
import { createKeyboardManager, KeyboardPatterns } from '@compa11y/core';
|
|
55
|
-
|
|
56
|
-
const manager = createKeyboardManager(
|
|
57
|
-
KeyboardPatterns.menu({
|
|
58
|
-
onUp: () => focusPreviousItem(),
|
|
59
|
-
onDown: () => focusNextItem(),
|
|
60
|
-
onEnter: () => selectItem(),
|
|
61
|
-
onEscape: () => closeMenu(),
|
|
62
|
-
})
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
manager.attach(menuElement);
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
### ARIA Utilities
|
|
69
|
-
|
|
70
|
-
```ts
|
|
71
|
-
import { aria, buildAriaProps, hasAccessibleName } from '@compa11y/core';
|
|
72
|
-
|
|
73
|
-
// Set individual ARIA attributes
|
|
32
|
+
// Set ARIA attributes
|
|
74
33
|
aria.setExpanded(button, true);
|
|
75
|
-
aria.setControls(button, 'menu-id');
|
|
76
|
-
|
|
77
|
-
// Build props object for React/frameworks
|
|
78
|
-
const props = buildAriaProps({
|
|
79
|
-
expanded: true,
|
|
80
|
-
controls: 'menu-id',
|
|
81
|
-
hasPopup: 'menu',
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
// Check accessibility
|
|
85
|
-
if (!hasAccessibleName(element)) {
|
|
86
|
-
console.warn('Element needs an accessible name');
|
|
87
|
-
}
|
|
88
34
|
```
|
|
89
35
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
```ts
|
|
93
|
-
import { checks, createComponentWarnings } from '@compa11y/core';
|
|
94
|
-
|
|
95
|
-
// Use pre-built checks
|
|
96
|
-
checks.accessibleLabel(element, 'MyComponent');
|
|
97
|
-
|
|
98
|
-
// Create component-scoped warnings
|
|
99
|
-
const warnings = createComponentWarnings('MyComponent');
|
|
100
|
-
warnings.error('Missing required prop', 'Add the "label" prop');
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
## API Reference
|
|
104
|
-
|
|
105
|
-
### Focus
|
|
106
|
-
|
|
107
|
-
- `createFocusTrap(container, options)` — Create a focus trap
|
|
108
|
-
- `createFocusScope(container, options)` — Manage focus within a scope
|
|
109
|
-
- `createRovingTabindex(container, selector, options)` — Roving tabindex pattern
|
|
110
|
-
- `initFocusVisible()` — Initialize focus-visible detection
|
|
111
|
-
|
|
112
|
-
### Announcer
|
|
113
|
-
|
|
114
|
-
- `initAnnouncer()` — Initialize live regions
|
|
115
|
-
- `announce(message, options)` — General announcement
|
|
116
|
-
- `announcePolite(message)` — Non-interrupting announcement
|
|
117
|
-
- `announceAssertive(message)` — Interrupting announcement
|
|
118
|
-
- `createAnnouncer(defaults)` — Create scoped announcer
|
|
119
|
-
|
|
120
|
-
### Keyboard
|
|
121
|
-
|
|
122
|
-
- `createKeyboardManager(handlers, options)` — Keyboard event handling
|
|
123
|
-
- `KeyboardPatterns.menu(handlers)` — Menu navigation pattern
|
|
124
|
-
- `KeyboardPatterns.tabs(handlers)` — Tabs navigation pattern
|
|
125
|
-
- `KeyboardPatterns.grid(handlers)` — Grid navigation pattern
|
|
126
|
-
- `createTypeAhead(items, options)` — Type-ahead search
|
|
127
|
-
|
|
128
|
-
### ARIA
|
|
129
|
-
|
|
130
|
-
- `aria.*` — ARIA attribute setters
|
|
131
|
-
- `buildAriaProps(props)` — Build props object
|
|
132
|
-
- `hasAccessibleName(element)` — Check for accessible name
|
|
133
|
-
- `mergeAriaIds(...ids)` — Merge ARIA ID lists
|
|
134
|
-
|
|
135
|
-
### Dev
|
|
136
|
-
|
|
137
|
-
- `warn(warning)` — Issue a warning
|
|
138
|
-
- `checks.*` — Pre-built accessibility checks
|
|
139
|
-
- `createComponentWarnings(name)` — Create scoped warnings
|
|
140
|
-
|
|
141
|
-
### DOM Utilities
|
|
142
|
-
|
|
143
|
-
- `isFocusable(element)` — Check if focusable
|
|
144
|
-
- `isTabbable(element)` — Check if tabbable
|
|
145
|
-
- `getFocusableElements(container)` — Get all focusable elements
|
|
146
|
-
- `getTabbableElements(container)` — Get all tabbable elements
|
|
147
|
-
- `getFirstFocusable(container)` — Get first focusable
|
|
148
|
-
- `getLastFocusable(container)` — Get last focusable
|
|
149
|
-
|
|
150
|
-
### Platform
|
|
36
|
+
## Documentation
|
|
151
37
|
|
|
152
|
-
|
|
153
|
-
- `isMac()` — Check if macOS
|
|
154
|
-
- `prefersReducedMotion()` — Check motion preference
|
|
155
|
-
- `prefersHighContrast()` — Check contrast preference
|
|
156
|
-
- `prefersDarkMode()` — Check color scheme preference
|
|
38
|
+
Full documentation, API reference, and examples at **[compa11y.org](https://compa11y.org)**.
|
|
157
39
|
|
|
158
40
|
## License
|
|
159
41
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@compa11y/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "Framework-agnostic accessibility primitives",
|
|
5
5
|
"author": "Ivan Trajkovski",
|
|
6
6
|
"license": "MIT",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"main": "./dist/index.js",
|
|
12
12
|
"module": "./dist/index.mjs",
|
|
13
13
|
"types": "./dist/index.d.ts",
|
|
14
|
-
"homepage": "https://
|
|
14
|
+
"homepage": "https://compa11y.org",
|
|
15
15
|
"bugs": {
|
|
16
16
|
"url": "https://github.com/trajkovskiivan/compa11y/issues"
|
|
17
17
|
},
|