@primer/react 0.0.0-20260306180541 → 0.0.0-20260306180554

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-20260306180541
3
+ ## 0.0.0-20260306180554
4
4
 
5
5
  ### Minor Changes
6
6
 
@@ -20,8 +20,6 @@
20
20
 
21
21
  - [#7624](https://github.com/primer/react/pull/7624) [`f6d4311`](https://github.com/primer/react/commit/f6d431194d217fbb7d456e58bcbbcbb434896fe1) Thanks [@llastflowers](https://github.com/llastflowers)! - Fix FormControl + SelectPanel accessible name to address SR issues
22
22
 
23
- - [#7600](https://github.com/primer/react/pull/7600) [`f688fd5`](https://github.com/primer/react/commit/f688fd5541b0d6382c597c85b9c075fa384eaab6) Thanks [@hectahertz](https://github.com/hectahertz)! - perf(TextInput): skip redundant character counter updates
24
-
25
23
  - [#7617](https://github.com/primer/react/pull/7617) [`79c855a`](https://github.com/primer/react/commit/79c855abeb6f46d3fefafb236f00ea65dfcd1ed4) Thanks [@llastflowers](https://github.com/llastflowers)! - Push margin-top of TimelineBody +1px
26
24
 
27
25
  - [#7550](https://github.com/primer/react/pull/7550) [`9585669`](https://github.com/primer/react/commit/958566907a580b54b484ff2339b32315b8a3b4b7) Thanks [@hectahertz](https://github.com/hectahertz)! - perf(Spinner): replace Web Animations API with CSS animation-delay sync
@@ -30,6 +28,8 @@
30
28
 
31
29
  - [#7588](https://github.com/primer/react/pull/7588) [`e649da3`](https://github.com/primer/react/commit/e649da3c89b38f477fb574acf5bb06a49b41ee9d) Thanks [@lukasoppermann](https://github.com/lukasoppermann)! - ToggleSwitch: Updated with a 1px space around the knob to work better with updated primitives.
32
30
 
31
+ - [#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
32
+
33
33
  ## 38.14.0
34
34
 
35
35
  ### Minor Changes
@@ -1 +1 @@
1
- {"version":3,"file":"TextInput.d.ts","sourceRoot":"","sources":["../../src/TextInput/TextInput.tsx"],"names":[],"mappings":"AACA,OAAO,KAAwD,MAAM,OAAO,CAAA;AAE5E,OAAO,KAAK,EAAC,mBAAmB,IAAI,8BAA8B,EAAC,MAAM,sBAAsB,CAAA;AAO/F,OAAO,KAAK,EAAC,KAAK,EAAC,MAAM,gBAAgB,CAAA;AACzC,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,yCAAyC,CAAA;AAQ/E,MAAM,MAAM,4BAA4B,GAAG;IACzC,uEAAuE;IACvE,IAAI,CAAC,EAAE,KAAK,CAAC,WAAW,CAAA;IACxB,2DAA2D;IAC3D,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB;;;;;QAKI;IACJ,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,UAAU,CAAA;IAChD,0DAA0D;IAC1D,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB;;OAEG;IACH,aAAa,CAAC,EAAE,KAAK,CAAC,WAAW,GAAG,KAAK,CAAC,SAAS,CAAA;IACnD;;OAEG;IACH,cAAc,CAAC,EAAE,KAAK,CAAC,WAAW,GAAG,KAAK,CAAC,SAAS,CAAA;IACpD;;OAEG;IACH,cAAc,CAAC,EAAE,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAAC,CAAA;IACvE;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB,GAAG,OAAO,CACT,IAAI,CACF,kBAAkB,EAChB,OAAO,GACP,UAAU,GACV,UAAU,GACV,WAAW,GACX,OAAO,GACP,UAAU,GACV,UAAU,GACV,SAAS,GACT,MAAM,GACN,kBAAkB,CACrB,CACF,CAAA;AAED,MAAM,MAAM,cAAc,GAAG,KAAK,CAAC,KAAK,C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B,CAAC,OAAO,CAAC,EAAE,4BAA4B,CAAC,CAAA;;;;;;;;;;;AAiOzG,wBAGE"}
@@ -51,10 +51,6 @@ const TextInput = /*#__PURE__*/React.forwardRef(({
51
51
  const [isOverLimit, setIsOverLimit] = useState(false);
52
52
  const [screenReaderMessage, setScreenReaderMessage] = useState('');
53
53
  const characterCounterRef = useRef(null);
54
- const lastCountedLengthRef = useRef(null);
55
- const lastCharacterCountRef = useRef('');
56
- const lastIsOverLimitRef = useRef(false);
57
- const lastScreenReaderMessageRef = useRef('');
58
54
 
59
55
  // this class is necessary to style FilterSearch, plz no touchy!
60
56
  const wrapperClasses = clsx(className, 'TextInput-wrapper');
@@ -88,31 +84,17 @@ const TextInput = /*#__PURE__*/React.forwardRef(({
88
84
  if (characterLimit) {
89
85
  characterCounterRef.current = new CharacterCounter({
90
86
  onCountUpdate: (count, overLimit, message) => {
91
- if (message !== lastCharacterCountRef.current) {
92
- lastCharacterCountRef.current = message;
93
- setCharacterCount(message);
94
- }
95
- if (overLimit !== lastIsOverLimitRef.current) {
96
- lastIsOverLimitRef.current = overLimit;
97
- setIsOverLimit(overLimit);
98
- }
87
+ setCharacterCount(message);
88
+ setIsOverLimit(overLimit);
99
89
  },
100
90
  onScreenReaderAnnounce: message_0 => {
101
- if (message_0 !== lastScreenReaderMessageRef.current) {
102
- lastScreenReaderMessageRef.current = message_0;
103
- setScreenReaderMessage(message_0);
104
- }
91
+ setScreenReaderMessage(message_0);
105
92
  }
106
93
  });
107
- lastCountedLengthRef.current = null;
108
94
  return () => {
109
95
  var _characterCounterRef$;
110
96
  (_characterCounterRef$ = characterCounterRef.current) === null || _characterCounterRef$ === void 0 ? void 0 : _characterCounterRef$.cleanup();
111
97
  characterCounterRef.current = null;
112
- lastCountedLengthRef.current = null;
113
- lastCharacterCountRef.current = '';
114
- lastIsOverLimitRef.current = false;
115
- lastScreenReaderMessageRef.current = '';
116
98
  };
117
99
  }
118
100
  }, [characterLimit]);
@@ -121,22 +103,14 @@ const TextInput = /*#__PURE__*/React.forwardRef(({
121
103
  useEffect(() => {
122
104
  if (characterLimit && characterCounterRef.current) {
123
105
  const currentValue = value !== undefined ? String(value) : defaultValue !== undefined ? String(defaultValue) : '';
124
- const currentLength = currentValue.length;
125
- if (currentLength !== lastCountedLengthRef.current) {
126
- lastCountedLengthRef.current = currentLength;
127
- characterCounterRef.current.updateCharacterCount(currentLength, characterLimit);
128
- }
106
+ characterCounterRef.current.updateCharacterCount(currentValue.length, characterLimit);
129
107
  }
130
108
  }, [value, defaultValue, characterLimit]);
131
109
 
132
110
  // Handle input change with character counter
133
111
  const handleInputChange = useCallback(e_2 => {
134
112
  if (characterLimit && characterCounterRef.current) {
135
- const currentLength_0 = e_2.target.value.length;
136
- if (currentLength_0 !== lastCountedLengthRef.current) {
137
- lastCountedLengthRef.current = currentLength_0;
138
- characterCounterRef.current.updateCharacterCount(currentLength_0, characterLimit);
139
- }
113
+ characterCounterRef.current.updateCharacterCount(e_2.target.value.length, characterLimit);
140
114
  }
141
115
  onChange === null || onChange === void 0 ? void 0 : onChange(e_2);
142
116
  }, [onChange, characterLimit]);
@@ -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-20260306180541",
4
+ "version": "0.0.0-20260306180554",
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",