@primer/react 0.0.0-20260508225321 → 0.0.0-20260511063616
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/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# @primer/react
|
|
2
2
|
|
|
3
|
-
## 0.0.0-
|
|
3
|
+
## 0.0.0-20260511063616
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
7
7
|
- [#7817](https://github.com/primer/react/pull/7817) [`6cb12d0`](https://github.com/primer/react/commit/6cb12d0cb2cbffd80667e0683d29d6844887eaa9) Thanks [@francinelucca](https://github.com/francinelucca)! - - ActionList: Expand `selectableRoles` and `listRoleTypes` to include `treeitem` and `tree`.
|
|
8
8
|
- Export `ActionListContainerContext` as `ActionList.ContainerContext`.
|
|
9
|
-
- Export `useRovingTabIndex` from the public API with additional configuration options (`preventScroll
|
|
9
|
+
- Export `useRovingTabIndex` from the public API with additional configuration options (`preventScroll` and `dependencies`).
|
|
10
10
|
|
|
11
11
|
### Patch Changes
|
|
12
12
|
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import type React from 'react';
|
|
2
|
-
export declare function useRovingTabIndex({ containerRef, mouseDownRef,
|
|
3
|
-
containerRef: React.RefObject<HTMLElement
|
|
2
|
+
export declare function useRovingTabIndex({ containerRef, mouseDownRef, preventScroll, }: {
|
|
3
|
+
containerRef: React.RefObject<HTMLElement>;
|
|
4
4
|
mouseDownRef?: React.RefObject<boolean>;
|
|
5
5
|
preventScroll?: boolean;
|
|
6
|
-
focusOutBehavior?: 'stop' | 'wrap';
|
|
7
|
-
wrapAround?: boolean;
|
|
8
6
|
}, dependencies?: React.DependencyList): void;
|
|
9
|
-
export declare function getNextFocusableElement(activeElement: HTMLElement, event: KeyboardEvent
|
|
7
|
+
export declare function getNextFocusableElement(activeElement: HTMLElement, event: KeyboardEvent): HTMLElement | undefined;
|
|
10
8
|
export declare function getElementState(element: HTMLElement): 'open' | 'closed' | 'end';
|
|
11
|
-
export declare function getVisibleElement(element: HTMLElement, direction: 'next' | 'previous'
|
|
9
|
+
export declare function getVisibleElement(element: HTMLElement, direction: 'next' | 'previous'): HTMLElement | undefined;
|
|
12
10
|
export declare function getFirstChildElement(element: HTMLElement): HTMLElement | undefined;
|
|
13
11
|
export declare function getParentElement(element: HTMLElement): HTMLElement | undefined;
|
|
14
12
|
export declare function getFirstElement(element: HTMLElement): HTMLElement | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRovingTabIndex.d.ts","sourceRoot":"","sources":["../../src/TreeView/useRovingTabIndex.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAI9B,wBAAgB,iBAAiB,CAC/B,EACE,YAAY,EACZ,YAAY,EACZ,
|
|
1
|
+
{"version":3,"file":"useRovingTabIndex.d.ts","sourceRoot":"","sources":["../../src/TreeView/useRovingTabIndex.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAI9B,wBAAgB,iBAAiB,CAC/B,EACE,YAAY,EACZ,YAAY,EACZ,aAAoB,GACrB,EAAE;IACD,YAAY,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAA;IAC1C,YAAY,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;IACvC,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB,EACD,YAAY,GAAE,KAAK,CAAC,cAAmB,QA4DxC;AAID,wBAAgB,uBAAuB,CAAC,aAAa,EAAE,WAAW,EAAE,KAAK,EAAE,aAAa,GAAG,WAAW,GAAG,SAAS,CAyDjH;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,WAAW,GAAG,MAAM,GAAG,QAAQ,GAAG,KAAK,CAa/E;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,GAAG,UAAU,GAAG,WAAW,GAAG,SAAS,CAwB/G;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,WAAW,GAAG,WAAW,GAAG,SAAS,CAGlF;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,WAAW,GAAG,WAAW,GAAG,SAAS,CAI9E;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,WAAW,GAAG,WAAW,GAAG,SAAS,CAI7E;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,WAAW,GAAG,WAAW,GAAG,SAAS,CAuB5E"}
|
|
@@ -4,57 +4,25 @@ import { getScrollContainer } from '../utils/scroll.js';
|
|
|
4
4
|
import { FocusKeys } from '@primer/behaviors';
|
|
5
5
|
|
|
6
6
|
function useRovingTabIndex(t0, t1) {
|
|
7
|
-
const $ = c(
|
|
7
|
+
const $ = c(12);
|
|
8
8
|
const {
|
|
9
9
|
containerRef,
|
|
10
10
|
mouseDownRef,
|
|
11
|
-
|
|
12
|
-
preventScroll: t2,
|
|
13
|
-
wrapAround: t3
|
|
11
|
+
preventScroll: t2
|
|
14
12
|
} = t0;
|
|
15
13
|
const preventScroll = t2 === undefined ? true : t2;
|
|
16
|
-
|
|
17
|
-
let t4;
|
|
14
|
+
let t3;
|
|
18
15
|
if ($[0] !== t1) {
|
|
19
|
-
|
|
16
|
+
t3 = t1 === undefined ? [] : t1;
|
|
20
17
|
$[0] = t1;
|
|
21
|
-
$[1] =
|
|
18
|
+
$[1] = t3;
|
|
22
19
|
} else {
|
|
23
|
-
|
|
20
|
+
t3 = $[1];
|
|
24
21
|
}
|
|
25
|
-
const dependencies =
|
|
26
|
-
let
|
|
27
|
-
if ($[2] !==
|
|
28
|
-
|
|
29
|
-
var _getNextFocusableElem;
|
|
30
|
-
if (!(from instanceof HTMLElement)) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
try {
|
|
34
|
-
if (from.closest("dialog:modal")) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
} catch {}
|
|
38
|
-
return (_getNextFocusableElem = getNextFocusableElement(from, event, wrapAround)) !== null && _getNextFocusableElem !== void 0 ? _getNextFocusableElem : from;
|
|
39
|
-
};
|
|
40
|
-
$[2] = wrapAround;
|
|
41
|
-
$[3] = t5;
|
|
42
|
-
} else {
|
|
43
|
-
t5 = $[3];
|
|
44
|
-
}
|
|
45
|
-
let t6;
|
|
46
|
-
if ($[4] !== focusOutBehavior) {
|
|
47
|
-
t6 = focusOutBehavior ? {
|
|
48
|
-
focusOutBehavior
|
|
49
|
-
} : {};
|
|
50
|
-
$[4] = focusOutBehavior;
|
|
51
|
-
$[5] = t6;
|
|
52
|
-
} else {
|
|
53
|
-
t6 = $[5];
|
|
54
|
-
}
|
|
55
|
-
let t7;
|
|
56
|
-
if ($[6] !== containerRef || $[7] !== mouseDownRef) {
|
|
57
|
-
t7 = () => {
|
|
22
|
+
const dependencies = t3;
|
|
23
|
+
let t4;
|
|
24
|
+
if ($[2] !== containerRef || $[3] !== mouseDownRef) {
|
|
25
|
+
t4 = () => {
|
|
58
26
|
var _containerRef$current, _containerRef$current2, _containerRef$current3;
|
|
59
27
|
if (mouseDownRef !== null && mouseDownRef !== void 0 && mouseDownRef.current) {
|
|
60
28
|
return;
|
|
@@ -69,58 +37,61 @@ function useRovingTabIndex(t0, t1) {
|
|
|
69
37
|
}
|
|
70
38
|
return firstItem instanceof HTMLElement ? firstItem : undefined;
|
|
71
39
|
};
|
|
72
|
-
$[
|
|
73
|
-
$[
|
|
74
|
-
$[
|
|
40
|
+
$[2] = containerRef;
|
|
41
|
+
$[3] = mouseDownRef;
|
|
42
|
+
$[4] = t4;
|
|
75
43
|
} else {
|
|
76
|
-
|
|
44
|
+
t4 = $[4];
|
|
77
45
|
}
|
|
78
|
-
let
|
|
79
|
-
if ($[
|
|
80
|
-
|
|
46
|
+
let t5;
|
|
47
|
+
if ($[5] !== containerRef || $[6] !== preventScroll || $[7] !== t4) {
|
|
48
|
+
t5 = {
|
|
81
49
|
containerRef,
|
|
82
50
|
bindKeys: FocusKeys.ArrowVertical | FocusKeys.ArrowHorizontal | FocusKeys.HomeAndEnd | FocusKeys.Backspace | FocusKeys.PageUpDown,
|
|
83
51
|
preventScroll,
|
|
84
|
-
getNextFocusable:
|
|
85
|
-
|
|
86
|
-
focusInStrategy: t7
|
|
52
|
+
getNextFocusable: _temp,
|
|
53
|
+
focusInStrategy: t4
|
|
87
54
|
};
|
|
88
|
-
$[
|
|
89
|
-
$[
|
|
90
|
-
$[
|
|
91
|
-
$[
|
|
92
|
-
$[13] = t7;
|
|
93
|
-
$[14] = t8;
|
|
55
|
+
$[5] = containerRef;
|
|
56
|
+
$[6] = preventScroll;
|
|
57
|
+
$[7] = t4;
|
|
58
|
+
$[8] = t5;
|
|
94
59
|
} else {
|
|
95
|
-
|
|
60
|
+
t5 = $[8];
|
|
96
61
|
}
|
|
97
|
-
let
|
|
98
|
-
if ($[
|
|
99
|
-
|
|
100
|
-
$[
|
|
101
|
-
$[
|
|
102
|
-
$[
|
|
103
|
-
$[18] = wrapAround;
|
|
104
|
-
$[19] = t9;
|
|
62
|
+
let t6;
|
|
63
|
+
if ($[9] !== dependencies || $[10] !== preventScroll) {
|
|
64
|
+
t6 = [preventScroll, ...dependencies];
|
|
65
|
+
$[9] = dependencies;
|
|
66
|
+
$[10] = preventScroll;
|
|
67
|
+
$[11] = t6;
|
|
105
68
|
} else {
|
|
106
|
-
|
|
69
|
+
t6 = $[11];
|
|
107
70
|
}
|
|
108
|
-
useFocusZone(
|
|
71
|
+
useFocusZone(t5, t6);
|
|
109
72
|
}
|
|
110
73
|
|
|
111
74
|
// DOM utilities used for focus management
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
75
|
+
function _temp(direction, from, event) {
|
|
76
|
+
var _getNextFocusableElem;
|
|
77
|
+
if (!(from instanceof HTMLElement)) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
if (from.closest("dialog:modal")) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
} catch {}
|
|
85
|
+
return (_getNextFocusableElem = getNextFocusableElement(from, event)) !== null && _getNextFocusableElem !== void 0 ? _getNextFocusableElem : from;
|
|
86
|
+
}
|
|
87
|
+
function getNextFocusableElement(activeElement, event) {
|
|
88
|
+
const elementState = getElementState(activeElement);
|
|
118
89
|
|
|
119
90
|
// Reference: https://www.w3.org/WAI/ARIA/apg/patterns/treeview/#keyboard-interaction-24
|
|
120
91
|
switch (`${elementState} ${event.key}`) {
|
|
121
92
|
case 'open ArrowRight':
|
|
122
93
|
// Focus first child node
|
|
123
|
-
return getFirstChildElement(
|
|
94
|
+
return getFirstChildElement(activeElement);
|
|
124
95
|
case 'open ArrowLeft':
|
|
125
96
|
// Close node; don't change focus
|
|
126
97
|
return;
|
|
@@ -129,35 +100,35 @@ function getNextFocusableElement(activeElement, event, wrapAround = false) {
|
|
|
129
100
|
return;
|
|
130
101
|
case 'closed ArrowLeft':
|
|
131
102
|
// Focus parent element
|
|
132
|
-
return getParentElement(
|
|
103
|
+
return getParentElement(activeElement);
|
|
133
104
|
case 'end ArrowRight':
|
|
134
105
|
// Do nothing
|
|
135
106
|
return;
|
|
136
107
|
case 'end ArrowLeft':
|
|
137
108
|
// Focus parent element
|
|
138
|
-
return getParentElement(
|
|
109
|
+
return getParentElement(activeElement);
|
|
139
110
|
}
|
|
140
111
|
|
|
141
112
|
// ArrowUp, ArrowDown, Home, and End behavior are the same regardless of element state
|
|
142
113
|
switch (event.key) {
|
|
143
114
|
case 'ArrowUp':
|
|
144
115
|
// Focus previous visible element
|
|
145
|
-
return getVisibleElement(
|
|
116
|
+
return getVisibleElement(activeElement, 'previous');
|
|
146
117
|
case 'ArrowDown':
|
|
147
118
|
// Focus next visible element
|
|
148
|
-
return getVisibleElement(
|
|
119
|
+
return getVisibleElement(activeElement, 'next');
|
|
149
120
|
case 'Backspace':
|
|
150
|
-
return getParentElement(
|
|
121
|
+
return getParentElement(activeElement);
|
|
151
122
|
case 'Home':
|
|
152
123
|
// Focus first visible element
|
|
153
|
-
return getFirstElement(
|
|
124
|
+
return getFirstElement(activeElement);
|
|
154
125
|
case 'End':
|
|
155
126
|
// Focus last visible element
|
|
156
|
-
return getLastElement(
|
|
127
|
+
return getLastElement(activeElement);
|
|
157
128
|
case 'PageUp':
|
|
158
|
-
return getPreviousPageElement(
|
|
129
|
+
return getPreviousPageElement(activeElement);
|
|
159
130
|
case 'PageDown':
|
|
160
|
-
return getNextPageElement(
|
|
131
|
+
return getNextPageElement(activeElement);
|
|
161
132
|
}
|
|
162
133
|
}
|
|
163
134
|
function getElementState(element) {
|
|
@@ -173,7 +144,7 @@ function getElementState(element) {
|
|
|
173
144
|
return 'end';
|
|
174
145
|
}
|
|
175
146
|
}
|
|
176
|
-
function getVisibleElement(element, direction
|
|
147
|
+
function getVisibleElement(element, direction) {
|
|
177
148
|
const root = element.closest('[role=tree]');
|
|
178
149
|
if (!root) return;
|
|
179
150
|
const walker = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT, node => {
|
|
@@ -191,11 +162,6 @@ function getVisibleElement(element, direction, wrapAround = false) {
|
|
|
191
162
|
var _next$parentElement;
|
|
192
163
|
next = direction === 'next' ? walker.nextNode() : walker.previousNode();
|
|
193
164
|
}
|
|
194
|
-
|
|
195
|
-
// Wrap around if we reached the end/beginning of the tree
|
|
196
|
-
if (!next && wrapAround) {
|
|
197
|
-
return direction === 'next' ? getFirstElement(element) : getLastElement(element);
|
|
198
|
-
}
|
|
199
165
|
return next instanceof HTMLElement ? next : undefined;
|
|
200
166
|
}
|
|
201
167
|
function getFirstChildElement(element) {
|
package/package.json
CHANGED