@baukit/a11y-core 0.5.1 → 0.6.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.
- package/README.md +10 -3
- package/dist/announce-web.d.ts +11 -0
- package/dist/announce-web.d.ts.map +1 -0
- package/dist/announce-web.js +32 -0
- package/dist/announce-web.js.map +1 -0
- package/dist/announce.d.ts +3 -9
- package/dist/announce.d.ts.map +1 -1
- package/dist/announce.js +8 -30
- package/dist/announce.js.map +1 -1
- package/dist/web.d.ts +1 -0
- package/dist/web.d.ts.map +1 -1
- package/dist/web.js +1 -0
- package/dist/web.js.map +1 -1
- package/package.json +10 -10
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ product's Expo SDK decides the versions, and React Native is optional.
|
|
|
10
10
|
## Two entry points
|
|
11
11
|
|
|
12
12
|
A React Native product imports the package root and gets everything. A plain React web app imports
|
|
13
|
-
`@baukit/a11y-core/web` and gets `useFocusTrap`, `useInert`, `useAriaHiddenInert`,
|
|
13
|
+
`@baukit/a11y-core/web` and gets `announce`, `useFocusTrap`, `useInert`, `useAriaHiddenInert`,
|
|
14
14
|
`useReducedMotion`, `useReducedMotionPreference`, `useRovingMenu`, `nextEnabledMenuIndex`,
|
|
15
15
|
`useSingleFlight`, `createRouteFocusController`, and the `dom-boundary` helpers. Nothing reachable
|
|
16
16
|
from that entry imports `react-native`, at runtime or in its types, so the app needs no React
|
|
@@ -20,8 +20,9 @@ reason.
|
|
|
20
20
|
The DOM hooks ask whether a document exists rather than asking `Platform` which OS this is. The
|
|
21
21
|
two questions have the same answer here: every branch those hooks guard reads or writes the DOM,
|
|
22
22
|
React Native Web gives them a real document, and React Native has none. Hooks with a genuine
|
|
23
|
-
platform split, such as `
|
|
24
|
-
the root
|
|
23
|
+
platform split, such as `useOverlayA11y`, keep reading `Platform` and stay behind the root entry.
|
|
24
|
+
`announce` and `useReducedMotion` exist on both entries: the root version reads `Platform`, and the
|
|
25
|
+
`/web` version is its DOM half.
|
|
25
26
|
|
|
26
27
|
## Overlays
|
|
27
28
|
|
|
@@ -172,6 +173,12 @@ forcing a reflow first so the same message twice is spoken twice. Blank messages
|
|
|
172
173
|
The region's DOM id defaults to `baukit-announcer`. Pass `liveRegionId` to place it under a
|
|
173
174
|
product-owned id, and `assertive: true` to interrupt rather than wait for a pause.
|
|
174
175
|
|
|
176
|
+
`announce` from `@baukit/a11y-core/web` takes the same arguments and is the web half alone, so a
|
|
177
|
+
plain React app gets the live region without React Native. It creates the region on the first
|
|
178
|
+
call, or adopts an element the product already rendered under that id, and needs no component or
|
|
179
|
+
provider. Filtering which messages deserve speech stays in the product: call `announce` only for
|
|
180
|
+
the ones that do.
|
|
181
|
+
|
|
175
182
|
## Reduced motion, groups, and forms
|
|
176
183
|
|
|
177
184
|
`useReducedMotionPreference` returns `{ reducedMotion, resolved }` and follows preference changes
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Default DOM id of the shared web live region. Override it per product. */
|
|
2
|
+
export declare const DEFAULT_LIVE_REGION_ID = "baukit-announcer";
|
|
3
|
+
export interface AnnounceOptions {
|
|
4
|
+
/** Interrupts the screen reader instead of waiting for a pause. */
|
|
5
|
+
assertive?: boolean;
|
|
6
|
+
/** DOM id of the web live region. Defaults to `DEFAULT_LIVE_REGION_ID`. */
|
|
7
|
+
liveRegionId?: string;
|
|
8
|
+
}
|
|
9
|
+
/** Announces an outcome through a visually hidden ARIA live region. */
|
|
10
|
+
export declare function announce(message: string, { assertive, liveRegionId }?: AnnounceOptions): void;
|
|
11
|
+
//# sourceMappingURL=announce-web.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"announce-web.d.ts","sourceRoot":"","sources":["../src/announce-web.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,eAAO,MAAM,sBAAsB,qBAAqB,CAAC;AAKzD,MAAM,WAAW,eAAe;IAC9B,mEAAmE;IACnE,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,2EAA2E;IAC3E,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAiBD,uEAAuE;AACvE,wBAAgB,QAAQ,CACtB,OAAO,EAAE,MAAM,EACf,EAAE,SAAiB,EAAE,YAAqC,EAAE,GAAE,eAAoB,GACjF,IAAI,CASN"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** Default DOM id of the shared web live region. Override it per product. */
|
|
2
|
+
export const DEFAULT_LIVE_REGION_ID = 'baukit-announcer';
|
|
3
|
+
const VISUALLY_HIDDEN = 'position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0;';
|
|
4
|
+
function liveRegion(assertive, liveRegionId) {
|
|
5
|
+
if (typeof document === 'undefined')
|
|
6
|
+
return null;
|
|
7
|
+
let region = document.getElementById(liveRegionId);
|
|
8
|
+
if (!region) {
|
|
9
|
+
region = document.createElement('div');
|
|
10
|
+
region.id = liveRegionId;
|
|
11
|
+
region.style.cssText = VISUALLY_HIDDEN;
|
|
12
|
+
document.body.appendChild(region);
|
|
13
|
+
}
|
|
14
|
+
region.setAttribute('aria-atomic', 'true');
|
|
15
|
+
region.setAttribute('aria-live', assertive ? 'assertive' : 'polite');
|
|
16
|
+
region.setAttribute('role', assertive ? 'alert' : 'status');
|
|
17
|
+
return region;
|
|
18
|
+
}
|
|
19
|
+
/** Announces an outcome through a visually hidden ARIA live region. */
|
|
20
|
+
export function announce(message, { assertive = false, liveRegionId = DEFAULT_LIVE_REGION_ID } = {}) {
|
|
21
|
+
const trimmed = message.trim();
|
|
22
|
+
if (!trimmed)
|
|
23
|
+
return;
|
|
24
|
+
const region = liveRegion(assertive, liveRegionId);
|
|
25
|
+
if (!region)
|
|
26
|
+
return;
|
|
27
|
+
region.textContent = '';
|
|
28
|
+
// Force a distinct mutation so the same message twice is spoken twice.
|
|
29
|
+
region.getBoundingClientRect();
|
|
30
|
+
region.textContent = trimmed;
|
|
31
|
+
}
|
|
32
|
+
//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AC,SAAS,EAAE,YAAY,CAAC,CAAC;IACnD,IAAI,CAAC,MAAM;QAAE,OAAO;IACpB,MAAM,CAAC,WAAW,GAAG,EAAE,CAAC;IACxB,uEAAuE;IACvE,MAAM,CAAC,qBAAqB,EAAE,CAAC;IAC/B,MAAM,CAAC,WAAW,GAAG,OAAO,CAAC;AAC/B,CAAC"}
|
package/dist/announce.d.ts
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
export interface AnnounceOptions {
|
|
4
|
-
/** Interrupts the screen reader instead of waiting for a pause. */
|
|
5
|
-
assertive?: boolean;
|
|
6
|
-
/** DOM id of the web live region. Defaults to `DEFAULT_LIVE_REGION_ID`. */
|
|
7
|
-
liveRegionId?: string;
|
|
8
|
-
}
|
|
1
|
+
import { type AnnounceOptions } from './announce-web.js';
|
|
2
|
+
export { DEFAULT_LIVE_REGION_ID, type AnnounceOptions } from './announce-web.js';
|
|
9
3
|
/** Announces an outcome without requiring a visible live-region component. */
|
|
10
|
-
export declare function announce(message: string,
|
|
4
|
+
export declare function announce(message: string, options?: AnnounceOptions): void;
|
|
11
5
|
//# sourceMappingURL=announce.d.ts.map
|
package/dist/announce.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"announce.d.ts","sourceRoot":"","sources":["../src/announce.ts"],"names":[],"mappings":"AAEA,
|
|
1
|
+
{"version":3,"file":"announce.d.ts","sourceRoot":"","sources":["../src/announce.ts"],"names":[],"mappings":"AAEA,OAAO,EAA6B,KAAK,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpF,OAAO,EAAE,sBAAsB,EAAE,KAAK,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEjF,8EAA8E;AAC9E,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,eAAoB,GAAG,IAAI,CAQ7E"}
|
package/dist/announce.js
CHANGED
|
@@ -1,37 +1,15 @@
|
|
|
1
1
|
import { AccessibilityInfo, Platform } from 'react-native';
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
const VISUALLY_HIDDEN = 'position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0;';
|
|
5
|
-
function webLiveRegion(assertive, liveRegionId) {
|
|
6
|
-
if (typeof document === 'undefined')
|
|
7
|
-
return null;
|
|
8
|
-
let region = document.getElementById(liveRegionId);
|
|
9
|
-
if (!region) {
|
|
10
|
-
region = document.createElement('div');
|
|
11
|
-
region.id = liveRegionId;
|
|
12
|
-
region.style.cssText = VISUALLY_HIDDEN;
|
|
13
|
-
document.body.appendChild(region);
|
|
14
|
-
}
|
|
15
|
-
region.setAttribute('aria-atomic', 'true');
|
|
16
|
-
region.setAttribute('aria-live', assertive ? 'assertive' : 'polite');
|
|
17
|
-
region.setAttribute('role', assertive ? 'alert' : 'status');
|
|
18
|
-
return region;
|
|
19
|
-
}
|
|
2
|
+
import { announce as announceOnWeb } from './announce-web.js';
|
|
3
|
+
export { DEFAULT_LIVE_REGION_ID } from './announce-web.js';
|
|
20
4
|
/** Announces an outcome without requiring a visible live-region component. */
|
|
21
|
-
export function announce(message,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return;
|
|
25
|
-
if (Platform.OS !== 'web') {
|
|
26
|
-
AccessibilityInfo.announceForAccessibility(trimmed);
|
|
5
|
+
export function announce(message, options = {}) {
|
|
6
|
+
if (Platform.OS === 'web') {
|
|
7
|
+
announceOnWeb(message, options);
|
|
27
8
|
return;
|
|
28
9
|
}
|
|
29
|
-
const
|
|
30
|
-
if (!
|
|
10
|
+
const trimmed = message.trim();
|
|
11
|
+
if (!trimmed)
|
|
31
12
|
return;
|
|
32
|
-
|
|
33
|
-
// Force a distinct mutation so the same message twice is spoken twice.
|
|
34
|
-
void region.offsetWidth;
|
|
35
|
-
region.textContent = trimmed;
|
|
13
|
+
AccessibilityInfo.announceForAccessibility(trimmed);
|
|
36
14
|
}
|
|
37
15
|
//# sourceMappingURL=announce.js.map
|
package/dist/announce.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"announce.js","sourceRoot":"","sources":["../src/announce.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAE3D,
|
|
1
|
+
{"version":3,"file":"announce.js","sourceRoot":"","sources":["../src/announce.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAE3D,OAAO,EAAE,QAAQ,IAAI,aAAa,EAAwB,MAAM,mBAAmB,CAAC;AAEpF,OAAO,EAAE,sBAAsB,EAAwB,MAAM,mBAAmB,CAAC;AAEjF,8EAA8E;AAC9E,MAAM,UAAU,QAAQ,CAAC,OAAe,EAAE,UAA2B,EAAE;IACrE,IAAI,QAAQ,CAAC,EAAE,KAAK,KAAK,EAAE,CAAC;QAC1B,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAChC,OAAO;IACT,CAAC;IACD,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;IAC/B,IAAI,CAAC,OAAO;QAAE,OAAO;IACrB,iBAAiB,CAAC,wBAAwB,CAAC,OAAO,CAAC,CAAC;AACtD,CAAC"}
|
package/dist/web.d.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* dependency tree can bundle it. React Native products import the package root
|
|
5
5
|
* instead and get these exports plus the native ones.
|
|
6
6
|
*/
|
|
7
|
+
export * from './announce-web.js';
|
|
7
8
|
export * from './dom-boundary.js';
|
|
8
9
|
export * from './route-focus.js';
|
|
9
10
|
export * from './use-focus-trap.js';
|
package/dist/web.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web.d.ts","sourceRoot":"","sources":["../src/web.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EACL,gBAAgB,EAChB,0BAA0B,EAC1B,KAAK,uBAAuB,GAC7B,MAAM,6BAA6B,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC"}
|
|
1
|
+
{"version":3,"file":"web.d.ts","sourceRoot":"","sources":["../src/web.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EACL,gBAAgB,EAChB,0BAA0B,EAC1B,KAAK,uBAAuB,GAC7B,MAAM,6BAA6B,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC"}
|
package/dist/web.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* dependency tree can bundle it. React Native products import the package root
|
|
5
5
|
* instead and get these exports plus the native ones.
|
|
6
6
|
*/
|
|
7
|
+
export * from './announce-web.js';
|
|
7
8
|
export * from './dom-boundary.js';
|
|
8
9
|
export * from './route-focus.js';
|
|
9
10
|
export * from './use-focus-trap.js';
|
package/dist/web.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web.js","sourceRoot":"","sources":["../src/web.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EACL,gBAAgB,EAChB,0BAA0B,GAE3B,MAAM,6BAA6B,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC"}
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../src/web.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EACL,gBAAgB,EAChB,0BAA0B,GAE3B,MAAM,6BAA6B,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@baukit/a11y-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Accessibility behavior shared by web and React Native products: overlay focus, inert background content, announcements, reduced motion, and keyboard movement.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Patrick Koss",
|
|
@@ -46,19 +46,19 @@
|
|
|
46
46
|
"format:check": "prettier --check src package.json tsconfig.json tsconfig.test.json"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@testing-library/dom": "10.4.
|
|
50
|
-
"@testing-library/react": "16.3.
|
|
51
|
-
"@types/react": "19.
|
|
52
|
-
"jsdom": "30.
|
|
53
|
-
"react": "19.
|
|
54
|
-
"react-dom": "19.
|
|
55
|
-
"react-native": "0.86.
|
|
49
|
+
"@testing-library/dom": "10.4.2",
|
|
50
|
+
"@testing-library/react": "16.3.3",
|
|
51
|
+
"@types/react": "19.3.0",
|
|
52
|
+
"jsdom": "30.1.1",
|
|
53
|
+
"react": "19.3.0",
|
|
54
|
+
"react-dom": "19.3.0",
|
|
55
|
+
"react-native": "0.86.3",
|
|
56
56
|
"typescript": "6.0.3",
|
|
57
|
-
"vitest": "
|
|
57
|
+
"vitest": "5.0.3"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
60
|
"react": "^19.2.0",
|
|
61
|
-
"react-native": "^0.86.
|
|
61
|
+
"react-native": "^0.86.3"
|
|
62
62
|
},
|
|
63
63
|
"peerDependenciesMeta": {
|
|
64
64
|
"react-native": {
|