@baukit/a11y-core 0.3.0 → 0.5.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 CHANGED
@@ -11,7 +11,8 @@ product's Expo SDK decides the versions, and React Native is optional.
11
11
 
12
12
  A React Native product imports the package root and gets everything. A plain React web app imports
13
13
  `@baukit/a11y-core/web` and gets `useFocusTrap`, `useInert`, `useAriaHiddenInert`,
14
- `useSingleFlight`, `createRouteFocusController`, and the `dom-boundary` helpers. Nothing reachable
14
+ `useRovingMenu`, `nextEnabledMenuIndex`, `useSingleFlight`, `createRouteFocusController`, and the
15
+ `dom-boundary` helpers. Nothing reachable
15
16
  from that entry imports `react-native`, at runtime or in its types, so the app needs no React
16
17
  Native in its dependency tree. `react-native` is an optional peer dependency for exactly that
17
18
  reason.
@@ -66,6 +67,55 @@ overlay. `useAriaHiddenInert` covers a separate problem: routers mark inactive w
66
67
  `aria-hidden`, which leaves their descendants in the keyboard focus order. Mount it once at the
67
68
  app root. Put `ARIA_HIDDEN_INERT_OPT_OUT` on an element that must stay focusable anyway.
68
69
 
70
+ ## Menus
71
+
72
+ `useRovingMenu` holds the keyboard state of an action menu. It gives the menu one tab stop on an
73
+ enabled item, moves focus with the arrow keys while skipping disabled items, wraps at both ends,
74
+ and sends Home and End to the first and last enabled items. It renders nothing and never invokes an
75
+ action. Escape, Tab containment, the inert background, and focus restoration stay with
76
+ `useOverlayA11y`, so call `useRovingMenu` first and pass its `initialFocusRef` on:
77
+
78
+ ```tsx
79
+ const menu = useRovingMenu({ active: visible, options: items });
80
+ const overlay = useOverlayA11y({
81
+ active: visible,
82
+ containerRef: panelRef,
83
+ initialFocusRef: menu.initialFocusRef,
84
+ onEscape: onClose,
85
+ triggerRef,
86
+ });
87
+
88
+ items.map((item, index) => (
89
+ <Pressable key={item.id} {...menu.itemProps(index)} disabled={item.disabled} />
90
+ ));
91
+ ```
92
+
93
+ `options` only needs `disabled` and `selected`, so the product's item array fits as is. The tab
94
+ stop starts on the first selected enabled item, otherwise the first enabled item, and returns there
95
+ each time the menu opens. `itemProps(index)` returns the `tabIndex`, `ref`, and `onKeyDown` for one
96
+ item; `activeIndex` names the item holding the tab stop.
97
+
98
+ - With no enabled item, `activeIndex` is null, every item has `tabIndex: -1`, arrow keys do
99
+ nothing, and `initialFocusRef.current` is null. `useOverlayA11y` then focuses the first focusable
100
+ element in the container, so put the close control before the items.
101
+ - When the active item is disabled or removed while the menu is open, the tab stop moves to the
102
+ item now at that position if it is enabled, otherwise back to the initial item. If the removed
103
+ item held focus and focus fell to the document body, the hook focuses the new active item.
104
+ - A key that comes from a host nested inside an item, such as a text field, is left alone.
105
+ - `initialFocusRef` is one stable ref for the life of the component. The hook points it at the
106
+ active item in an effect, and the overlay reads it in a later effect when the menu opens, so both
107
+ hooks must run in the same component with `useRovingMenu` first. Do not swap it for another ref
108
+ while the menu is open: the web trap would re-enter and forget the trigger it restores to.
109
+
110
+ `nextEnabledMenuIndex(key, currentIndex, options)` is the pure step behind the hook, for a product
111
+ that handles keys on the menu container instead. It returns null for keys other than the arrows,
112
+ Home, and End, and for a menu without an enabled item. It moves relative to `currentIndex` even
113
+ when that item is disabled or gone: an index past the end moves Down to the first enabled item and
114
+ Up to the last, and so does `-1`.
115
+
116
+ Action order, closing before or after an action, async failure recovery, selection meaning, and
117
+ copy stay with the product.
118
+
69
119
  ## Route focus
70
120
 
71
121
  WebKit can blur the initiating control to `body` when a router makes the outgoing scene inert.
@@ -89,6 +139,21 @@ The controller waits for the destination target to mount and retries on animatio
89
139
  moves focus to another reachable element, and it never focuses a target below `inert`,
90
140
  `aria-hidden="true"`, or `hidden`.
91
141
 
142
+ React Native has no document, so the controller does not apply there. To move VoiceOver or
143
+ TalkBack to a destination heading, call `focusAccessibilityElement(headingRef)` from the root
144
+ entry once the heading has laid out, for example one animation frame after the route gains focus.
145
+ On native it resolves the view tag and calls `AccessibilityInfo.setAccessibilityFocus`. On web it
146
+ focuses the element with `preventScroll`. It returns false when the ref is empty, the view is
147
+ unmounted, or the web element cannot take focus.
148
+
149
+ ```ts
150
+ import { focusAccessibilityElement } from '@baukit/a11y-core';
151
+
152
+ const frame = requestAnimationFrame(() => {
153
+ focusAccessibilityElement(headingRef);
154
+ });
155
+ ```
156
+
92
157
  ## The React Native to DOM boundary
93
158
 
94
159
  React Native Web renders a `View` as a DOM element, but the `View` type never says so. Every
package/dist/index.d.ts CHANGED
@@ -1,11 +1,13 @@
1
1
  export * from './announce.js';
2
2
  export * from './dom-boundary.js';
3
+ export { focusAccessibilityElement } from './native-focus.js';
3
4
  export * from './route-focus.js';
4
5
  export * from './use-enter-to-next.js';
5
6
  export * from './use-focus-trap.js';
6
7
  export * from './use-inert.js';
7
8
  export * from './use-overlay-a11y.js';
8
9
  export * from './use-reduced-motion.js';
10
+ export * from './use-roving-menu.js';
9
11
  export * from './use-roving-radio-group.js';
10
12
  export * from './use-single-flight.js';
11
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,wBAAwB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AAC9D,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,wBAAwB,CAAC"}
package/dist/index.js CHANGED
@@ -1,11 +1,13 @@
1
1
  export * from './announce.js';
2
2
  export * from './dom-boundary.js';
3
+ export { focusAccessibilityElement } from './native-focus.js';
3
4
  export * from './route-focus.js';
4
5
  export * from './use-enter-to-next.js';
5
6
  export * from './use-focus-trap.js';
6
7
  export * from './use-inert.js';
7
8
  export * from './use-overlay-a11y.js';
8
9
  export * from './use-reduced-motion.js';
10
+ export * from './use-roving-menu.js';
9
11
  export * from './use-roving-radio-group.js';
10
12
  export * from './use-single-flight.js';
11
13
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,wBAAwB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,OAAO,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AAC9D,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,wBAAwB,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { type HostRef } from './dom-boundary.js';
2
+ /** Native view tag behind a ref, or null when the ref is empty or unmounted. */
3
+ export declare function nativeNodeHandle(ref: HostRef | undefined): number | null;
4
+ /**
5
+ * Moves screen-reader focus to the element behind `ref`. Web focuses the DOM
6
+ * element without scrolling; native asks VoiceOver or TalkBack to focus the
7
+ * view. Returns false when there was nothing to focus.
8
+ */
9
+ export declare function focusAccessibilityElement(ref: HostRef | undefined): boolean;
10
+ //# sourceMappingURL=native-focus.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native-focus.d.ts","sourceRoot":"","sources":["../src/native-focus.ts"],"names":[],"mappings":"AAEA,OAAO,EAA8B,KAAK,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE7E,gFAAgF;AAChF,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,OAAO,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAQxE;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,OAAO,GAAG,SAAS,GAAG,OAAO,CAU3E"}
@@ -0,0 +1,32 @@
1
+ import { AccessibilityInfo, findNodeHandle, Platform } from 'react-native';
2
+ import { asFocusTarget, hostElement } from './dom-boundary.js';
3
+ /** Native view tag behind a ref, or null when the ref is empty or unmounted. */
4
+ export function nativeNodeHandle(ref) {
5
+ const host = hostElement(ref);
6
+ if (host === null)
7
+ return null;
8
+ try {
9
+ return findNodeHandle(host);
10
+ }
11
+ catch {
12
+ return null;
13
+ }
14
+ }
15
+ /**
16
+ * Moves screen-reader focus to the element behind `ref`. Web focuses the DOM
17
+ * element without scrolling; native asks VoiceOver or TalkBack to focus the
18
+ * view. Returns false when there was nothing to focus.
19
+ */
20
+ export function focusAccessibilityElement(ref) {
21
+ if (Platform.OS === 'web') {
22
+ const target = asFocusTarget(ref);
23
+ target?.focus({ preventScroll: true });
24
+ return target !== null;
25
+ }
26
+ const handle = nativeNodeHandle(ref);
27
+ if (handle === null)
28
+ return false;
29
+ AccessibilityInfo.setAccessibilityFocus(handle);
30
+ return true;
31
+ }
32
+ //# sourceMappingURL=native-focus.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"native-focus.js","sourceRoot":"","sources":["../src/native-focus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAE3E,OAAO,EAAE,aAAa,EAAE,WAAW,EAAgB,MAAM,mBAAmB,CAAC;AAE7E,gFAAgF;AAChF,MAAM,UAAU,gBAAgB,CAAC,GAAwB;IACvD,MAAM,IAAI,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;IAC9B,IAAI,IAAI,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAC/B,IAAI,CAAC;QACH,OAAO,cAAc,CAAC,IAA4C,CAAC,CAAC;IACtE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,yBAAyB,CAAC,GAAwB;IAChE,IAAI,QAAQ,CAAC,EAAE,KAAK,KAAK,EAAE,CAAC;QAC1B,MAAM,MAAM,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;QAClC,MAAM,EAAE,KAAK,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;QACvC,OAAO,MAAM,KAAK,IAAI,CAAC;IACzB,CAAC;IACD,MAAM,MAAM,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC;IACrC,IAAI,MAAM,KAAK,IAAI;QAAE,OAAO,KAAK,CAAC;IAClC,iBAAiB,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAC;IAChD,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -1,5 +1,6 @@
1
1
  import { type RefObject } from 'react';
2
2
  import { type View, type ViewProps } from 'react-native';
3
+ import type { HostRef } from './dom-boundary.js';
3
4
  import { type FocusTrapProps } from './use-focus-trap.js';
4
5
  /**
5
6
  * Runs `task` once the overlay has laid out and returns a canceller. Products
@@ -15,7 +16,7 @@ export interface OverlayA11yOptions {
15
16
  deferFocus?: DeferFocus | undefined;
16
17
  /** Container whose outside siblings go inert. Defaults to `containerRef`. */
17
18
  inertContainerRef?: RefObject<View | null> | undefined;
18
- initialFocusRef?: RefObject<View | null> | undefined;
19
+ initialFocusRef?: HostRef | undefined;
19
20
  onEscape?: (() => void) | undefined;
20
21
  /** Native tag of the opener, when the caller already resolved it. */
21
22
  triggerHandle?: number | null | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"use-overlay-a11y.d.ts","sourceRoot":"","sources":["../src/use-overlay-a11y.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAC1D,OAAO,EAKL,KAAK,IAAI,EACT,KAAK,SAAS,EACf,MAAM,cAAc,CAAC;AAGtB,OAAO,EAAgB,KAAK,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGxE;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG,CAAC,IAAI,EAAE,MAAM,IAAI,KAAK;IAAE,MAAM,EAAE,MAAM,IAAI,CAAA;CAAE,CAAC;AAEtE,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,OAAO,CAAC;IAChB,YAAY,EAAE,SAAS,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;IACrC,+DAA+D;IAC/D,UAAU,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC;IACpC,6EAA6E;IAC7E,iBAAiB,CAAC,EAAE,SAAS,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,SAAS,CAAC;IACvD,eAAe,CAAC,EAAE,SAAS,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,SAAS,CAAC;IACrD,QAAQ,CAAC,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,SAAS,CAAC;IACpC,qEAAqE;IACrE,aAA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,CAAC;IACvD,eAAe,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACtC,QAAQ,CAAC,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,SAAS,CAAC;IACpC,qEAAqE;IACrE,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAC1C,UAAU,CAAC,EAAE,SAAS,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,SAAS,CAAC;CACjD;AAED,MAAM,MAAM,sBAAsB,GAAG,IAAI,CACvC,SAAS,EACT,6BAA6B,GAAG,2BAA2B,CAC5D,CAAC;AAEF,MAAM,WAAW,iBAAiB;IAChC,eAAe,EAAE,sBAAsB,CAAC;IACxC,cAAc,EAAE,cAAc,CAAC;CAChC;AASD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,EAC7B,MAAM,EACN,YAAY,EACZ,UAAuC,EACvC,iBAAiB,EACjB,eAAe,EACf,QAAQ,EACR,aAAa,EACb,UAAU,GACX,EAAE,kBAAkB,GAAG,iBAAiB,CA6BxC"}
@@ -1,6 +1,6 @@
1
1
  import { useEffect, useRef } from 'react';
2
- import { AccessibilityInfo, findNodeHandle, InteractionManager, Platform, } from 'react-native';
3
- import { hostElement } from './dom-boundary.js';
2
+ import { AccessibilityInfo, InteractionManager, Platform, } from 'react-native';
3
+ import { nativeNodeHandle } from './native-focus.js';
4
4
  import { useFocusTrap } from './use-focus-trap.js';
5
5
  import { useInert } from './use-inert.js';
6
6
  // InteractionManager is deprecated in React Native 0.86 with no replacement for
@@ -9,17 +9,6 @@ import { useInert } from './use-inert.js';
9
9
  const deferUntilInteractionsDone = (task) =>
10
10
  // eslint-disable-next-line @typescript-eslint/no-deprecated
11
11
  InteractionManager.runAfterInteractions(task);
12
- function nodeHandle(ref) {
13
- const host = hostElement(ref);
14
- if (host === null)
15
- return null;
16
- try {
17
- return findNodeHandle(host);
18
- }
19
- catch {
20
- return null;
21
- }
22
- }
23
12
  /**
24
13
  * One contract for overlay focus on both platforms. Web traps Tab, closes on
25
14
  * Escape, and makes the background inert. Native moves accessibility focus into
@@ -32,9 +21,9 @@ export function useOverlayA11y({ active, containerRef, deferFocus = deferUntilIn
32
21
  useEffect(() => {
33
22
  if (Platform.OS === 'web' || !active)
34
23
  return;
35
- triggerHandleRef.current = triggerHandle ?? nodeHandle(triggerRef);
24
+ triggerHandleRef.current = triggerHandle ?? nativeNodeHandle(triggerRef);
36
25
  const task = deferFocus(() => {
37
- const containerHandle = nodeHandle(containerRef);
26
+ const containerHandle = nativeNodeHandle(containerRef);
38
27
  if (containerHandle !== null)
39
28
  AccessibilityInfo.setAccessibilityFocus(containerHandle);
40
29
  });
@@ -1 +1 @@
1
- {"version":3,"file":"use-overlay-a11y.js","sourceRoot":"","sources":["../src/use-overlay-a11y.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAkB,MAAM,OAAO,CAAC;AAC1D,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,kBAAkB,EAClB,QAAQ,GAGT,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAuB,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAgC1C,gFAAgF;AAChF,+EAA+E;AAC/E,8EAA8E;AAC9E,MAAM,0BAA0B,GAAe,CAAC,IAAI,EAAE,EAAE;AACtD,4DAA4D;AAC5D,kBAAkB,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAC;AAEhD,SAAS,UAAU,CAAC,GAAuC;IACzD,MAAM,IAAI,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;IAC9B,IAAI,IAAI,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAC/B,IAAI,CAAC;QACH,OAAO,cAAc,CAAC,IAA4C,CAAC,CAAC;IACtE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAA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CAAC,CAAC;QACzE,MAAM,IAAI,GAAG,UAAU,CAAC,GAAG,EAAE;YAC3B,MAAM,eAAe,GAAG,gBAAgB,CAAC,YAAY,CAAC,CAAC;YACvD,IAAI,eAAe,KAAK,IAAI;gBAAE,iBAAiB,CAAC,qBAAqB,CAAC,eAAe,CAAC,CAAC;QACzF,CAAC,CAAC,CAAC;QAEH,OAAO,GAAG,EAAE;YACV,IAAI,CAAC,MAAM,EAAE,CAAC;YACd,MAAM,YAAY,GAAG,gBAAgB,CAAC,OAAO,CAAC;YAC9C,gBAAgB,CAAC,OAAO,GAAG,IAAI,CAAC;YAChC,IAAI,YAAY,KAAK,IAAI;gBAAE,iBAAiB,CAAC,qBAAqB,CAAC,YAAY,CAAC,CAAC;QACnF,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,UAAU,CAAC,CAAC,CAAC;IAElE,OAAO;QACL,eAAe,EACb,QAAQ,CAAC,EAAE,KAAK,KAAK,IAAI,MAAM;YAC7B,CAAC,CAAC,EAAE,2BAA2B,EAAE,IAAI,EAAE,yBAAyB,EAAE,qBAAqB,EAAE;YACzF,CAAC,CAAC,EAAE;QACR,cAAc;KACf,CAAC;AACJ,CAAC"}
@@ -0,0 +1,42 @@
1
+ import { type RefObject } from 'react';
2
+ export interface RovingMenuOption {
3
+ readonly disabled?: boolean | undefined;
4
+ readonly selected?: boolean | undefined;
5
+ }
6
+ export interface RovingMenuOptions {
7
+ readonly active: boolean;
8
+ readonly options: readonly RovingMenuOption[];
9
+ }
10
+ export interface RovingMenuKeyEvent {
11
+ nativeEvent: {
12
+ key: string;
13
+ target?: unknown;
14
+ };
15
+ preventDefault: () => void;
16
+ }
17
+ export interface RovingMenuItemProps {
18
+ readonly onKeyDown: (event: RovingMenuKeyEvent) => void;
19
+ readonly ref: (node: object | null) => void;
20
+ readonly tabIndex: 0 | -1;
21
+ }
22
+ export interface RovingMenuResult {
23
+ /** The item holding the tab stop, or null when no item is enabled. */
24
+ readonly activeIndex: number | null;
25
+ /** A stable ref to the active item's host; its `current` is null when no item is enabled. */
26
+ readonly initialFocusRef: RefObject<object | null>;
27
+ readonly itemProps: (index: number) => RovingMenuItemProps;
28
+ }
29
+ /**
30
+ * Maps an arrow, Home, or End key to the enabled item it moves to, or null to
31
+ * ignore the key. Movement is relative to `currentIndex` even when that item is
32
+ * disabled or gone, and wraps at both ends.
33
+ */
34
+ export declare function nextEnabledMenuIndex(key: string, currentIndex: number, options: readonly RovingMenuOption[]): number | null;
35
+ /**
36
+ * Keyboard and focus state for an action menu: one tab stop on an enabled item,
37
+ * arrow keys that skip disabled items, and Home and End. It renders nothing,
38
+ * invokes no action, and leaves Escape, focus containment, and restoration to
39
+ * `useOverlayA11y`. Call it before `useOverlayA11y` and pass `initialFocusRef` on.
40
+ */
41
+ export declare function useRovingMenu({ active, options }: RovingMenuOptions): RovingMenuResult;
42
+ //# sourceMappingURL=use-roving-menu.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-roving-menu.d.ts","sourceRoot":"","sources":["../src/use-roving-menu.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4C,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAKjF,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACxC,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CACzC;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,SAAS,gBAAgB,EAAE,CAAC;CAC/C;AAED,MAAM,WAAW,kBAAkB;IACjC,WAAW,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;IAC/C,cAAc,EAAE,MAAM,IAAI,CAAC;CAC5B;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,SAAS,EAAE,CAAC,KAAK,EAAE,kBAAkB,KAAK,IAAI,CAAC;IACxD,QAAQ,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;IAC5C,QAAQ,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;CAC3B;AAED,MAAM,WAAW,gBAAgB;IAC/B,sEAAsE;IACtE,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,6FAA6F;IAC7F,QAAQ,CAAC,eAAe,EAAE,SAAS,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IACnD,QAAQ,CAAC,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,mBAAmB,CAAC;CAC5D;AAqBD;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,MAAM,EACX,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,SAAS,gBAAgB,EAAE,GACnC,MAAM,GAAG,IAAI,CAkBf;AA2BD;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,iBAAiB,GAAG,gBAAgB,CA2DtF"}
@@ -0,0 +1,125 @@
1
+ import { useCallback, useEffect, useRef, useState } from 'react';
2
+ import { activeFocusTarget, asFocusTarget } from './dom-boundary.js';
3
+ import { hasDocument } from './platform.js';
4
+ function isEnabled(option) {
5
+ return option !== undefined && option.disabled !== true;
6
+ }
7
+ function enabledIndexes(options) {
8
+ return options.flatMap((option, index) => (isEnabled(option) ? [index] : []));
9
+ }
10
+ function nextAfter(enabled, currentIndex) {
11
+ return enabled.find((index) => index > currentIndex) ?? enabled[0];
12
+ }
13
+ function previousBefore(enabled, currentIndex) {
14
+ const before = enabled.filter((index) => index < currentIndex);
15
+ return before[before.length - 1] ?? enabled[enabled.length - 1];
16
+ }
17
+ /**
18
+ * Maps an arrow, Home, or End key to the enabled item it moves to, or null to
19
+ * ignore the key. Movement is relative to `currentIndex` even when that item is
20
+ * disabled or gone, and wraps at both ends.
21
+ */
22
+ export function nextEnabledMenuIndex(key, currentIndex, options) {
23
+ const enabled = enabledIndexes(options);
24
+ if (enabled.length === 0)
25
+ return null;
26
+ switch (key) {
27
+ case 'ArrowDown':
28
+ case 'ArrowRight':
29
+ return nextAfter(enabled, currentIndex) ?? null;
30
+ case 'ArrowLeft':
31
+ case 'ArrowUp':
32
+ return previousBefore(enabled, currentIndex) ?? null;
33
+ case 'Home':
34
+ return enabled[0] ?? null;
35
+ case 'End':
36
+ return enabled[enabled.length - 1] ?? null;
37
+ default:
38
+ return null;
39
+ }
40
+ }
41
+ function initialMenuIndex(options) {
42
+ const selected = options.findIndex((option) => option.selected === true && isEnabled(option));
43
+ if (selected >= 0)
44
+ return selected;
45
+ const firstEnabled = options.findIndex(isEnabled);
46
+ return firstEnabled >= 0 ? firstEnabled : null;
47
+ }
48
+ function resolveMenuIndex(movedIndex, options) {
49
+ if (movedIndex !== null && isEnabled(options[movedIndex]))
50
+ return movedIndex;
51
+ return initialMenuIndex(options);
52
+ }
53
+ /** True when the key came from a host nested inside the item, such as a field. */
54
+ function isNestedTarget(target, item) {
55
+ return typeof target === 'object' && target !== null && item !== null && target !== item;
56
+ }
57
+ function focusFellToDocument() {
58
+ if (!hasDocument())
59
+ return false;
60
+ return document.activeElement === null || document.activeElement === document.body;
61
+ }
62
+ /**
63
+ * Keyboard and focus state for an action menu: one tab stop on an enabled item,
64
+ * arrow keys that skip disabled items, and Home and End. It renders nothing,
65
+ * invokes no action, and leaves Escape, focus containment, and restoration to
66
+ * `useOverlayA11y`. Call it before `useOverlayA11y` and pass `initialFocusRef` on.
67
+ */
68
+ export function useRovingMenu({ active, options }) {
69
+ const itemNodes = useRef([]);
70
+ const itemRefs = useRef(new Map());
71
+ const initialFocusRef = useRef(null);
72
+ const focusedItemRemoved = useRef(false);
73
+ const [movedIndex, setMovedIndex] = useState(null);
74
+ const [wasActive, setWasActive] = useState(active);
75
+ if (wasActive !== active) {
76
+ setWasActive(active);
77
+ setMovedIndex(null);
78
+ }
79
+ const activeIndex = resolveMenuIndex(movedIndex, options);
80
+ useEffect(() => {
81
+ initialFocusRef.current =
82
+ activeIndex === null ? null : (itemNodes.current[activeIndex] ?? null);
83
+ if (!focusedItemRemoved.current)
84
+ return;
85
+ focusedItemRemoved.current = false;
86
+ if (active && focusFellToDocument())
87
+ asFocusTarget(initialFocusRef)?.focus();
88
+ });
89
+ const itemRef = useCallback((index) => {
90
+ const cached = itemRefs.current.get(index);
91
+ if (cached !== undefined)
92
+ return cached;
93
+ const attach = (node) => {
94
+ const previous = itemNodes.current[index] ?? null;
95
+ if (node === null && previous !== null && previous === activeFocusTarget()) {
96
+ focusedItemRemoved.current = true;
97
+ }
98
+ itemNodes.current[index] = node;
99
+ };
100
+ itemRefs.current.set(index, attach);
101
+ return attach;
102
+ }, []);
103
+ const onItemKeyDown = (event, index) => {
104
+ if (isNestedTarget(event.nativeEvent.target, itemNodes.current[index] ?? null))
105
+ return;
106
+ const nextIndex = nextEnabledMenuIndex(event.nativeEvent.key, index, options);
107
+ if (nextIndex === null)
108
+ return;
109
+ event.preventDefault();
110
+ setMovedIndex(nextIndex);
111
+ asFocusTarget({ current: itemNodes.current[nextIndex] ?? null })?.focus();
112
+ };
113
+ return {
114
+ activeIndex,
115
+ initialFocusRef,
116
+ itemProps: (index) => ({
117
+ onKeyDown: (event) => {
118
+ onItemKeyDown(event, index);
119
+ },
120
+ ref: itemRef(index),
121
+ tabIndex: index === activeIndex ? 0 : -1,
122
+ }),
123
+ };
124
+ }
125
+ //# sourceMappingURL=use-roving-menu.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-roving-menu.js","sourceRoot":"","sources":["../src/use-roving-menu.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAkB,MAAM,OAAO,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Ae;QACf,SAAS,EAAE,CAAC,KAAa,EAAE,EAAE,CAAC,CAAC;YAC7B,SAAS,EAAE,CAAC,KAAyB,EAAE,EAAE;gBACvC,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;YAC9B,CAAC;YACD,GAAG,EAAE,OAAO,CAAC,KAAK,CAAC;YACnB,QAAQ,EAAE,KAAK,KAAK,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;SACzC,CAAC;KACH,CAAC;AACJ,CAAC"}
package/dist/web.d.ts CHANGED
@@ -8,5 +8,6 @@ export * from './dom-boundary.js';
8
8
  export * from './route-focus.js';
9
9
  export * from './use-focus-trap.js';
10
10
  export * from './use-inert.js';
11
+ export * from './use-roving-menu.js';
11
12
  export * from './use-single-flight.js';
12
13
  //# sourceMappingURL=web.d.ts.map
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,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,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC"}
package/dist/web.js CHANGED
@@ -8,5 +8,6 @@ export * from './dom-boundary.js';
8
8
  export * from './route-focus.js';
9
9
  export * from './use-focus-trap.js';
10
10
  export * from './use-inert.js';
11
+ export * from './use-roving-menu.js';
11
12
  export * from './use-single-flight.js';
12
13
  //# sourceMappingURL=web.js.map
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,cAAc,wBAAwB,CAAC"}
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,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.0",
3
+ "version": "0.5.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",
@@ -24,11 +24,13 @@
24
24
  "exports": {
25
25
  ".": {
26
26
  "types": "./dist/index.d.ts",
27
- "import": "./dist/index.js"
27
+ "import": "./dist/index.js",
28
+ "default": "./dist/index.js"
28
29
  },
29
30
  "./web": {
30
31
  "types": "./dist/web.d.ts",
31
- "import": "./dist/web.js"
32
+ "import": "./dist/web.js",
33
+ "default": "./dist/web.js"
32
34
  }
33
35
  },
34
36
  "files": [
@@ -36,6 +38,13 @@
36
38
  "README.md",
37
39
  "LICENSE"
38
40
  ],
41
+ "scripts": {
42
+ "build": "tsc -p tsconfig.json",
43
+ "prepare": "pnpm run build",
44
+ "test": "tsc -p tsconfig.test.json && vitest run --config ../../vitest.config.ts && node ../../scripts/test-packed-exports.mjs",
45
+ "lint": "eslint src --max-warnings=0",
46
+ "format:check": "prettier --check src package.json tsconfig.json tsconfig.test.json"
47
+ },
39
48
  "devDependencies": {
40
49
  "@testing-library/dom": "10.4.1",
41
50
  "@testing-library/react": "16.3.2",
@@ -55,11 +64,5 @@
55
64
  "react-native": {
56
65
  "optional": true
57
66
  }
58
- },
59
- "scripts": {
60
- "build": "tsc -p tsconfig.json",
61
- "test": "vitest run --config ../../vitest.config.ts",
62
- "lint": "eslint src --max-warnings=0",
63
- "format:check": "prettier --check src package.json tsconfig.json"
64
67
  }
65
- }
68
+ }