@primer/react 0.0.0-20260302143740 → 0.0.0-20260302143751

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,6 +1,6 @@
1
1
  # @primer/react
2
2
 
3
- ## 0.0.0-20260302143740
3
+ ## 0.0.0-20260302143751
4
4
 
5
5
  ### Minor Changes
6
6
 
@@ -22,7 +22,7 @@
22
22
 
23
23
  - [#7551](https://github.com/primer/react/pull/7551) [`2fbfc49`](https://github.com/primer/react/commit/2fbfc49fad6f11edc51850e32e9c0b2ade8ca1f1) Thanks [@hectahertz](https://github.com/hectahertz)! - perf(Text): remove unnecessary useRef and useImperativeHandle hooks
24
24
 
25
- - [#7545](https://github.com/primer/react/pull/7545) [`cd12712`](https://github.com/primer/react/commit/cd12712a0278d7de96c8ececbd336f61e15221c3) Thanks [@hectahertz](https://github.com/hectahertz)! - perf(TreeView): defer scrollIntoView to coalesce reflows during rapid navigation
25
+ - [#7544](https://github.com/primer/react/pull/7544) [`9c24302`](https://github.com/primer/react/commit/9c2430281aba7f606d388a43b619bddf649d1eea) Thanks [@hectahertz](https://github.com/hectahertz)! - perf(TreeView): replace O(n) TreeWalker with O(depth) sibling traversal
26
26
 
27
27
  - [#7571](https://github.com/primer/react/pull/7571) [`59ab235`](https://github.com/primer/react/commit/59ab235cb8089442652daca33746b11cea3e6a5f) Thanks [@liuliu-dev](https://github.com/liuliu-dev)! - AnchoredOverlay: changed `overflow` from `hidden` to `auto` to prevent content clipping at small viewports.
28
28
 
@@ -1 +1 @@
1
- {"version":3,"file":"TreeView.d.ts","sourceRoot":"","sources":["../../src/TreeView/TreeView.tsx"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,IAAI,EACV,MAAM,wBAAwB,CAAA;AAE/B,OAAO,KAA+B,MAAM,OAAO,CAAA;AAsBnD,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,gBAAgB,CAAA;AA4CpD,MA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__*/React.createContext({
31
31
  announceUpdate: () => {},
32
32
  expandedStateCache: {
33
33
  current: new Map()
34
- },
35
- scrollElementIntoView: () => {}
34
+ }
36
35
  });
37
36
  const ItemContext = /*#__PURE__*/React.createContext({
38
37
  itemId: '',
@@ -52,7 +51,7 @@ const ItemContext = /*#__PURE__*/React.createContext({
52
51
  /* Size of toggle icon in pixels. */
53
52
  const TOGGLE_ICON_SIZE = 12;
54
53
  const Root = t0 => {
55
- const $ = c(26);
54
+ const $ = c(23);
56
55
  const {
57
56
  "aria-label": ariaLabel,
58
57
  "aria-labelledby": ariaLabelledby,
@@ -128,132 +127,89 @@ const Root = t0 => {
128
127
  t7 = $[5];
129
128
  }
130
129
  useTypeahead(t7);
131
- const pendingScrollRef = React.useRef(null);
132
- let t8;
133
- if ($[6] === Symbol.for("react.memo_cache_sentinel")) {
134
- t8 = element_0 => {
135
- if (!element_0) {
136
- return;
137
- }
138
- if (pendingScrollRef.current !== null) {
139
- cancelAnimationFrame(pendingScrollRef.current);
140
- }
141
- pendingScrollRef.current = requestAnimationFrame(() => {
142
- pendingScrollRef.current = null;
143
- if (!element_0.isConnected) {
144
- return;
145
- }
146
- element_0.scrollIntoView({
147
- block: "nearest",
148
- inline: "nearest"
149
- });
150
- });
151
- };
152
- $[6] = t8;
153
- } else {
154
- t8 = $[6];
155
- }
156
- const scrollElementIntoView = t8;
157
- let t10;
158
- let t9;
159
- if ($[7] === Symbol.for("react.memo_cache_sentinel")) {
160
- t9 = () => () => {
161
- if (pendingScrollRef.current !== null) {
162
- cancelAnimationFrame(pendingScrollRef.current);
163
- }
164
- };
165
- t10 = [];
166
- $[7] = t10;
167
- $[8] = t9;
168
- } else {
169
- t10 = $[7];
170
- t9 = $[8];
171
- }
172
- useEffect(t9, t10);
173
130
  const expandedStateCache = React.useRef(null);
174
131
  if (expandedStateCache.current === null) {
175
- let t11;
176
- if ($[9] === Symbol.for("react.memo_cache_sentinel")) {
177
- t11 = new Map();
178
- $[9] = t11;
132
+ let t8;
133
+ if ($[6] === Symbol.for("react.memo_cache_sentinel")) {
134
+ t8 = new Map();
135
+ $[6] = t8;
179
136
  } else {
180
- t11 = $[9];
137
+ t8 = $[6];
181
138
  }
182
- expandedStateCache.current = t11;
139
+ expandedStateCache.current = t8;
183
140
  }
184
- let t11;
185
- if ($[10] === Symbol.for("react.memo_cache_sentinel")) {
186
- t11 = {
141
+ let t8;
142
+ if ($[7] === Symbol.for("react.memo_cache_sentinel")) {
143
+ t8 = {
187
144
  announceUpdate,
188
- expandedStateCache,
189
- scrollElementIntoView
145
+ expandedStateCache
190
146
  };
191
- $[10] = t11;
147
+ $[7] = t8;
192
148
  } else {
193
- t11 = $[10];
149
+ t8 = $[7];
194
150
  }
195
- let t12;
196
- if ($[11] !== ariaLiveMessage) {
197
- t12 = /*#__PURE__*/jsx(VisuallyHidden, {
151
+ let t9;
152
+ if ($[8] !== ariaLiveMessage) {
153
+ t9 = /*#__PURE__*/jsx(VisuallyHidden, {
198
154
  children: /*#__PURE__*/jsx(AriaStatus, {
199
155
  announceOnShow: true,
200
156
  children: ariaLiveMessage
201
157
  })
202
158
  });
203
- $[11] = ariaLiveMessage;
204
- $[12] = t12;
159
+ $[8] = ariaLiveMessage;
160
+ $[9] = t9;
205
161
  } else {
206
- t12 = $[12];
207
- }
208
- const t13 = truncate || false;
209
- let t14;
210
- if ($[13] !== className) {
211
- t14 = clsx(className, classes.TreeViewRootUlStyles);
212
- $[13] = className;
213
- $[14] = t14;
162
+ t9 = $[9];
163
+ }
164
+ const t10 = truncate || false;
165
+ let t11;
166
+ if ($[10] !== className) {
167
+ t11 = clsx(className, classes.TreeViewRootUlStyles);
168
+ $[10] = className;
169
+ $[11] = t11;
214
170
  } else {
215
- t14 = $[14];
171
+ t11 = $[11];
216
172
  }
217
- let t15;
218
- if ($[15] !== ariaLabel || $[16] !== ariaLabelledby || $[17] !== children || $[18] !== flat || $[19] !== style || $[20] !== t13 || $[21] !== t14) {
219
- t15 = /*#__PURE__*/jsx("ul", {
173
+ let t12;
174
+ if ($[12] !== ariaLabel || $[13] !== ariaLabelledby || $[14] !== children || $[15] !== flat || $[16] !== style || $[17] !== t10 || $[18] !== t11) {
175
+ t12 = /*#__PURE__*/jsx("ul", {
220
176
  ref: containerRef,
221
177
  role: "tree",
222
178
  "aria-label": ariaLabel,
223
179
  "aria-labelledby": ariaLabelledby,
224
180
  "data-omit-spacer": flat,
225
- "data-truncate-text": t13,
181
+ "data-truncate-text": t10,
226
182
  onMouseDown: onMouseDown,
227
- className: t14,
183
+ className: t11,
228
184
  style: style,
229
185
  children: children
230
186
  });
231
- $[15] = ariaLabel;
232
- $[16] = ariaLabelledby;
233
- $[17] = children;
234
- $[18] = flat;
235
- $[19] = style;
236
- $[20] = t13;
237
- $[21] = t14;
238
- $[22] = t15;
187
+ $[12] = ariaLabel;
188
+ $[13] = ariaLabelledby;
189
+ $[14] = children;
190
+ $[15] = flat;
191
+ $[16] = style;
192
+ $[17] = t10;
193
+ $[18] = t11;
194
+ $[19] = t12;
239
195
  } else {
240
- t15 = $[22];
196
+ t12 = $[19];
241
197
  }
242
- let t16;
243
- if ($[23] !== t12 || $[24] !== t15) {
244
- t16 = /*#__PURE__*/jsx(RootContext.Provider, {
245
- value: t11,
198
+ let t13;
199
+ if ($[20] !== t12 || $[21] !== t9) {
200
+ t13 = /*#__PURE__*/jsx(RootContext.Provider, {
201
+ value: t8,
246
202
  children: /*#__PURE__*/jsxs(Fragment, {
247
- children: [t12, t15]
203
+ children: [t9, t12]
248
204
  })
249
205
  });
250
- $[23] = t12;
251
- $[24] = t15;
252
- $[25] = t16;
206
+ $[20] = t12;
207
+ $[21] = t9;
208
+ $[22] = t13;
253
209
  } else {
254
- t16 = $[25];
210
+ t13 = $[22];
255
211
  }
256
- return t16;
212
+ return t13;
257
213
  };
258
214
  Root.displayName = 'TreeView';
259
215
 
@@ -280,8 +236,7 @@ const Item = /*#__PURE__*/React.forwardRef(({
280
236
  trailingVisual: TrailingVisual
281
237
  });
282
238
  const {
283
- expandedStateCache,
284
- scrollElementIntoView
239
+ expandedStateCache
285
240
  } = React.useContext(RootContext);
286
241
  const labelId = useId();
287
242
  const leadingVisualId = useId();
@@ -402,9 +357,12 @@ const Item = /*#__PURE__*/React.forwardRef(({
402
357
  "data-has-leading-action": slots.leadingAction ? true : undefined,
403
358
  onKeyDown: handleKeyDown,
404
359
  onFocus: event_1 => {
405
- // Defer scroll to the next animation frame so that rapid keyboard
406
- // navigation (held key) coalesces into a single reflow per frame
407
- scrollElementIntoView(event_1.currentTarget.firstElementChild);
360
+ var _event_1$currentTarge;
361
+ // Scroll the first child into view when the item receives focus
362
+ (_event_1$currentTarge = event_1.currentTarget.firstElementChild) === null || _event_1$currentTarge === void 0 ? void 0 : _event_1$currentTarge.scrollIntoView({
363
+ block: 'nearest',
364
+ inline: 'nearest'
365
+ });
408
366
 
409
367
  // Set the focused state
410
368
  setIsFocused(true);
@@ -5,6 +5,20 @@ export declare function useRovingTabIndex({ containerRef, mouseDownRef, }: {
5
5
  }): void;
6
6
  export declare function getNextFocusableElement(activeElement: HTMLElement, event: KeyboardEvent): HTMLElement | undefined;
7
7
  export declare function getElementState(element: HTMLElement): 'open' | 'closed' | 'end';
8
+ /**
9
+ * Find the next or previous visible treeitem using direct DOM traversal.
10
+ *
11
+ * PERFORMANCE: This is O(tree depth) instead of O(n) because it walks
12
+ * siblings and parent/child edges directly, rather than creating a TreeWalker
13
+ * that scans from the root to find the current element on every keystroke.
14
+ *
15
+ * NOTE: This relies on TreeView.SubTree unmounting its children when collapsed
16
+ * (returning null when !isExpanded). Because collapsed subtree children are
17
+ * never in the DOM, we can safely skip them by only entering children of nodes
18
+ * with aria-expanded="true". If SubTree ever changes to keep collapsed children
19
+ * mounted (e.g. via CSS display:none), this logic would need to add filtering
20
+ * for items inside collapsed parents.
21
+ */
8
22
  export declare function getVisibleElement(element: HTMLElement, direction: 'next' | 'previous'): HTMLElement | undefined;
9
23
  export declare function getFirstChildElement(element: HTMLElement): HTMLElement | undefined;
10
24
  export declare function getParentElement(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,CAAC,EAChC,YAAY,EACZ,YAAY,GACb,EAAE;IACD,YAAY,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAA;IAC1C,YAAY,EAAE,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;CACvC,QAwDA;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"}
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,CAAC,EAChC,YAAY,EACZ,YAAY,GACb,EAAE;IACD,YAAY,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAA;IAC1C,YAAY,EAAE,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;CACvC,QAwDA;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;;;;;;;;;;;;;GAaG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,GAAG,UAAU,GAAG,WAAW,GAAG,SAAS,CAK/G;AAsFD,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"}
@@ -123,25 +123,103 @@ function getElementState(element) {
123
123
  return 'end';
124
124
  }
125
125
  }
126
+
127
+ /**
128
+ * Find the next or previous visible treeitem using direct DOM traversal.
129
+ *
130
+ * PERFORMANCE: This is O(tree depth) instead of O(n) because it walks
131
+ * siblings and parent/child edges directly, rather than creating a TreeWalker
132
+ * that scans from the root to find the current element on every keystroke.
133
+ *
134
+ * NOTE: This relies on TreeView.SubTree unmounting its children when collapsed
135
+ * (returning null when !isExpanded). Because collapsed subtree children are
136
+ * never in the DOM, we can safely skip them by only entering children of nodes
137
+ * with aria-expanded="true". If SubTree ever changes to keep collapsed children
138
+ * mounted (e.g. via CSS display:none), this logic would need to add filtering
139
+ * for items inside collapsed parents.
140
+ */
126
141
  function getVisibleElement(element, direction) {
127
- const root = element.closest('[role=tree]');
128
- if (!root) return;
129
- const walker = document.createTreeWalker(root, NodeFilter.SHOW_ELEMENT, node => {
130
- if (!(node instanceof HTMLElement)) return NodeFilter.FILTER_SKIP;
131
- return node.getAttribute('role') === 'treeitem' ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
132
- });
133
- let current = walker.firstChild();
134
- while (current !== element) {
135
- current = walker.nextNode();
136
- }
137
- let next = direction === 'next' ? walker.nextNode() : walker.previousNode();
142
+ if (direction === 'next') {
143
+ return getNextVisibleElement(element);
144
+ }
145
+ return getPreviousVisibleElement(element);
146
+ }
147
+ function getNextVisibleElement(element) {
148
+ // If the current item is expanded, the next visible item is its first child
149
+ if (element.getAttribute('aria-expanded') === 'true') {
150
+ const firstChild = getFirstChildElement(element);
151
+ if (firstChild) return firstChild;
152
+ }
153
+
154
+ // Otherwise, walk up the tree looking for a next sibling
155
+ let current = element;
156
+ while (current) {
157
+ const next = getNextSiblingTreeItem(current);
158
+ if (next) return next;
138
159
 
139
- // If next element is nested inside a collapsed subtree, continue iterating
140
- while (next instanceof HTMLElement && (_next$parentElement = next.parentElement) !== null && _next$parentElement !== void 0 && _next$parentElement.closest('[role=treeitem][aria-expanded=false]')) {
141
- var _next$parentElement;
142
- next = direction === 'next' ? walker.nextNode() : walker.previousNode();
160
+ // No next sibling at this level, try the parent's next sibling
161
+ current = getParentElement(current);
162
+ }
163
+ return undefined;
164
+ }
165
+ function getPreviousVisibleElement(element) {
166
+ const prev = getPreviousSiblingTreeItem(element);
167
+ if (prev) {
168
+ // Navigate to the deepest last visible descendant of the previous sibling
169
+ return getDeepestLastDescendant(prev);
170
+ }
171
+
172
+ // No previous sibling, the parent is the previous visible element
173
+ return getParentElement(element);
174
+ }
175
+
176
+ /**
177
+ * Walk into expanded subtrees to find the deepest last visible descendant.
178
+ * For example, if the last sibling is an expanded directory whose last child
179
+ * is also an expanded directory, we drill all the way down.
180
+ */
181
+ function getDeepestLastDescendant(element) {
182
+ let current = element;
183
+ while (current.getAttribute('aria-expanded') === 'true') {
184
+ const lastChild = getLastChildTreeItem(current);
185
+ if (!lastChild) break;
186
+ current = lastChild;
187
+ }
188
+ return current;
189
+ }
190
+ function getNextSiblingTreeItem(element) {
191
+ let sibling = element.nextElementSibling;
192
+ while (sibling) {
193
+ if (sibling instanceof HTMLElement && sibling.getAttribute('role') === 'treeitem') {
194
+ return sibling;
195
+ }
196
+ sibling = sibling.nextElementSibling;
197
+ }
198
+ return undefined;
199
+ }
200
+ function getPreviousSiblingTreeItem(element) {
201
+ let sibling = element.previousElementSibling;
202
+ while (sibling) {
203
+ if (sibling instanceof HTMLElement && sibling.getAttribute('role') === 'treeitem') {
204
+ return sibling;
205
+ }
206
+ sibling = sibling.previousElementSibling;
207
+ }
208
+ return undefined;
209
+ }
210
+ function getLastChildTreeItem(element) {
211
+ // Find the [role=group] child (the subtree container), then get its last treeitem
212
+ for (let i = element.children.length - 1; i >= 0; i--) {
213
+ const child = element.children[i];
214
+ if (child instanceof HTMLElement && child.getAttribute('role') === 'group') {
215
+ let lastChild = child.lastElementChild;
216
+ while (lastChild && !(lastChild instanceof HTMLElement && lastChild.getAttribute('role') === 'treeitem')) {
217
+ lastChild = lastChild.previousElementSibling;
218
+ }
219
+ return lastChild instanceof HTMLElement ? lastChild : undefined;
220
+ }
143
221
  }
144
- return next instanceof HTMLElement ? next : undefined;
222
+ return undefined;
145
223
  }
146
224
  function getFirstChildElement(element) {
147
225
  const firstChild = element.querySelector('[role=treeitem]');
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@primer/react",
3
3
  "type": "module",
4
- "version": "0.0.0-20260302143740",
4
+ "version": "0.0.0-20260302143751",
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",