@primer/react 0.0.0-20260508225321 → 0.0.0-20260511070203

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-20260508225321
3
+ ## 0.0.0-20260511070203
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`, `focusOutBehavior`, `wrapAround`, and `dependencies`).
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, focusOutBehavior, preventScroll, wrapAround, }: {
3
- containerRef: React.RefObject<HTMLElement | null>;
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, wrapAround?: boolean): HTMLElement | undefined;
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', wrapAround?: boolean): HTMLElement | undefined;
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,gBAAgB,EAChB,aAAoB,EACpB,UAAkB,GACnB,EAAE;IACD,YAAY,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,CAAA;IACjD,YAAY,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;IACvC,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,gBAAgB,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IAClC,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB,EACD,YAAY,GAAE,KAAK,CAAC,cAAmB,QA6DxC;AAID,wBAAgB,uBAAuB,CACrC,aAAa,EAAE,WAAW,EAC1B,KAAK,EAAE,aAAa,EACpB,UAAU,GAAE,OAAe,GAC1B,WAAW,GAAG,SAAS,CAgEzB;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,WAAW,GAAG,MAAM,GAAG,QAAQ,GAAG,KAAK,CAa/E;AAED,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,WAAW,EACpB,SAAS,EAAE,MAAM,GAAG,UAAU,EAC9B,UAAU,UAAQ,GACjB,WAAW,GAAG,SAAS,CA6BzB;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,WAAW,GAAG,WAAW,GAAG,SAAS,CAGlF;AAED,wBAAgB,gBAAgB,CA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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(20);
7
+ const $ = c(12);
8
8
  const {
9
9
  containerRef,
10
10
  mouseDownRef,
11
- focusOutBehavior,
12
- preventScroll: t2,
13
- wrapAround: t3
11
+ preventScroll: t2
14
12
  } = t0;
15
13
  const preventScroll = t2 === undefined ? true : t2;
16
- const wrapAround = t3 === undefined ? false : t3;
17
- let t4;
14
+ let t3;
18
15
  if ($[0] !== t1) {
19
- t4 = t1 === undefined ? [] : t1;
16
+ t3 = t1 === undefined ? [] : t1;
20
17
  $[0] = t1;
21
- $[1] = t4;
18
+ $[1] = t3;
22
19
  } else {
23
- t4 = $[1];
20
+ t3 = $[1];
24
21
  }
25
- const dependencies = t4;
26
- let t5;
27
- if ($[2] !== wrapAround) {
28
- t5 = (direction, from, event) => {
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
- $[6] = containerRef;
73
- $[7] = mouseDownRef;
74
- $[8] = t7;
40
+ $[2] = containerRef;
41
+ $[3] = mouseDownRef;
42
+ $[4] = t4;
75
43
  } else {
76
- t7 = $[8];
44
+ t4 = $[4];
77
45
  }
78
- let t8;
79
- if ($[9] !== containerRef || $[10] !== preventScroll || $[11] !== t5 || $[12] !== t6 || $[13] !== t7) {
80
- t8 = {
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: t5,
85
- ...t6,
86
- focusInStrategy: t7
52
+ getNextFocusable: _temp,
53
+ focusInStrategy: t4
87
54
  };
88
- $[9] = containerRef;
89
- $[10] = preventScroll;
90
- $[11] = t5;
91
- $[12] = t6;
92
- $[13] = t7;
93
- $[14] = t8;
55
+ $[5] = containerRef;
56
+ $[6] = preventScroll;
57
+ $[7] = t4;
58
+ $[8] = t5;
94
59
  } else {
95
- t8 = $[14];
60
+ t5 = $[8];
96
61
  }
97
- let t9;
98
- if ($[15] !== dependencies || $[16] !== focusOutBehavior || $[17] !== preventScroll || $[18] !== wrapAround) {
99
- t9 = [preventScroll, focusOutBehavior, wrapAround, ...dependencies];
100
- $[15] = dependencies;
101
- $[16] = focusOutBehavior;
102
- $[17] = preventScroll;
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
- t9 = $[19];
69
+ t6 = $[11];
107
70
  }
108
- useFocusZone(t8, t9);
71
+ useFocusZone(t5, t6);
109
72
  }
110
73
 
111
74
  // DOM utilities used for focus management
112
-
113
- function getNextFocusableElement(activeElement, event, wrapAround = false) {
114
- // If focus is on a non-treeitem child (e.g. GroupHeadingWrap), resolve to the closest treeitem ancestor.
115
- const treeitem = activeElement.getAttribute('role') === 'treeitem' ? activeElement : activeElement.closest('[role="treeitem"]');
116
- if (!treeitem) return;
117
- const elementState = getElementState(treeitem);
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(treeitem);
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(treeitem);
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(treeitem);
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(treeitem, 'previous', wrapAround);
116
+ return getVisibleElement(activeElement, 'previous');
146
117
  case 'ArrowDown':
147
118
  // Focus next visible element
148
- return getVisibleElement(treeitem, 'next', wrapAround);
119
+ return getVisibleElement(activeElement, 'next');
149
120
  case 'Backspace':
150
- return getParentElement(treeitem);
121
+ return getParentElement(activeElement);
151
122
  case 'Home':
152
123
  // Focus first visible element
153
- return getFirstElement(treeitem);
124
+ return getFirstElement(activeElement);
154
125
  case 'End':
155
126
  // Focus last visible element
156
- return getLastElement(treeitem);
127
+ return getLastElement(activeElement);
157
128
  case 'PageUp':
158
- return getPreviousPageElement(treeitem);
129
+ return getPreviousPageElement(activeElement);
159
130
  case 'PageDown':
160
- return getNextPageElement(treeitem);
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, wrapAround = false) {
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) {
@@ -146,6 +146,57 @@
146
146
  }
147
147
  ]
148
148
  },
149
+ "useRovingTabIndex": {
150
+ "name": "useRovingTabIndex",
151
+ "importPath": "@primer/react",
152
+ "stories": [
153
+ {
154
+ "id": "hooks-userovingtabindex--basic-roving-tab-index"
155
+ }
156
+ ],
157
+ "parameters": [
158
+ {
159
+ "name": "options",
160
+ "type": "UseRovingTabIndexOptions",
161
+ "required": true,
162
+ "description": "Configuration options for the roving tabindex focus management."
163
+ },
164
+ {
165
+ "name": "dependencies",
166
+ "type": "React.DependencyList",
167
+ "defaultValue": "[]",
168
+ "description": "Dependency list that triggers re-initialization of the focus zone when values change."
169
+ }
170
+ ],
171
+ "relatedTypes": [
172
+ {
173
+ "name": "UseRovingTabIndexOptions",
174
+ "properties": [
175
+ {
176
+ "name": "containerRef",
177
+ "type": "React.RefObject<HTMLElement>",
178
+ "required": true,
179
+ "description": "Ref to the container element (e.g. a tree) whose treeitem children will participate in roving tabindex focus management."
180
+ },
181
+ {
182
+ "name": "mouseDownRef",
183
+ "type": "React.RefObject<boolean>",
184
+ "description": "Optional ref that tracks whether the mouse is currently pressed. When true, the focus-in strategy is bypassed so clicked elements receive focus naturally."
185
+ },
186
+ {
187
+ "name": "preventScroll",
188
+ "type": "boolean",
189
+ "defaultValue": "true",
190
+ "description": "When true, prevents the browser from scrolling the focused element into view."
191
+ }
192
+ ]
193
+ }
194
+ ],
195
+ "returns": {
196
+ "type": "void",
197
+ "description": "This hook does not return a value. It sets up keyboard focus management on the container ref as a side effect."
198
+ }
199
+ },
149
200
  "useDetails": {
150
201
  "name": "useDetails",
151
202
  "importPath": "@primer/react",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@primer/react",
3
3
  "type": "module",
4
- "version": "0.0.0-20260508225321",
4
+ "version": "0.0.0-20260511070203",
5
5
  "description": "An implementation of GitHub's Primer Design System using React",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.js",