@primer/react 0.0.0-20260306181027 → 0.0.0-20260306181113

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-20260306181027
3
+ ## 0.0.0-20260306181113
4
4
 
5
5
  ### Minor Changes
6
6
 
@@ -20,6 +20,8 @@
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
+ - [#7549](https://github.com/primer/react/pull/7549) [`b1b5603`](https://github.com/primer/react/commit/b1b5603e2ad27559ce54aef1e413e05ee1fc6c1f) Thanks [@hectahertz](https://github.com/hectahertz)! - perf(Autocomplete): eliminate re-renders on arrow-key navigation by converting highlightedItem to a ref
24
+
23
25
  - [#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
24
26
 
25
27
  - [#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
@@ -28,8 +30,6 @@
28
30
 
29
31
  - [#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.
30
32
 
31
- - [#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
32
-
33
33
  ## 38.14.0
34
34
 
35
35
  ### Minor Changes
@@ -1 +1 @@
1
- {"version":3,"file":"AutocompleteMenu.d.ts","sourceRoot":"","sources":["../../src/Autocomplete/AutocompleteMenu.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAyD,MAAM,OAAO,CAAA;AAK7E,OAAO,KAAK,EAAC,mBAAmB,EAAC,MAAM,eAAe,CAAA;AAGtD,OAAO,KAAK,EAAC,cAAc,EAAE,YAAY,EAAW,MAAM,gBAAgB,CAAA;AAI1E,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,wBAAwB,CAAA;AAOrD,KAAK,gBAAgB,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,IAAI,CAAA;AAClD,MAAM,MAAM,oBAAoB,GAAG,YAAY,CAAC,mBAAmB,EAAE,IAAI,CAAC,GAAG;IAE3E,aAAa,CAAC,EAAE,KAAK,CAAC,iBAAiB,CAAC,KAAK,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC,GAAG,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,CAAA;IACrG,IAAI,CAAC,EAAE,MAAM,CAAA;IAEb,cAAc,CAAC,EAAE,KAAK,CAAC,iBAAiB,CAAC,KAAK,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC,GAAG,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,CAAA;CACvG,CAAA;AA4BD,KAAK,qBAAqB,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI,oBAAoB,GAAG;IAAC,QAAQ,CAAC,EAAE,CAAC,CAAA;CAAC,CAAA;AAE3F,MAAM,MAAM,6BAA6B,CAAC,CAAC,SAAS,qBAAqB,IAAI;IAC3E;;;OAGG;IACH,UAAU,CAAC,EAAE,CAAC,GAAG;QACf,aAAa,EAA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C,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,KAAK,OAAO,CAAA;IAE1C;;;OAGG;IACH,KAAK,EAAE,CAAC,EAAE,CAAA;IAEV;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IAEjB;;OAEG;IAEH,eAAe,EAAE,MAAM,EAAE,CAAA;IAEzB;;;OAGG;IACH,aAAa,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,MAAM,CAAA;IAE5D;;OAEG;IACH,gBAAgB,CAAC,EAAE,QAAQ,GAAG,UAAU,CAAA;IAExC;;OAEG;IACH,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAA;IAEtC;;OAEG;IACH,gBAAgB,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAA;IAEtC;;;;OAIG;IACH,wBAAwB,CAAC,EAAE,KAAK,CAAC,gBAAgB,CAAC,WAAW,GAAG,IAAI,CAAC,CAAA;IAErE,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAA;CAC5B,CAAA;AAUD,iBAAS,gBAAgB,CAAC,CAAC,SAAS,qBAAqB,EAAE,KAAK,EAAE,6BAA6B,CAAC,CAAC,CAAC,qBAmRjG;kBAnRQ,gBAAgB;;;;AAuRzB,MAAM,MAAM,qBAAqB,GAAG,cAAc,CAAC,OAAO,gBAAgB,CAAC,CAAA;AAC3E,eAAe,gBAAgB,CAAA"}
@@ -1,4 +1,4 @@
1
- import React, { useContext, useRef, useState, useMemo, useEffect } from 'react';
1
+ import React, { useContext, useRef, useEffect, useState, useMemo } from 'react';
2
2
  import { debounce } from '@github/mini-throttle';
3
3
  import { announce } from '@primer/live-region-element';
4
4
  import { scrollIntoView } from '@primer/behaviors';
@@ -33,6 +33,41 @@ function getdefaultCheckedSelectionChange(setInputValueFn) {
33
33
  };
34
34
  }
35
35
  const isItemSelected = (itemId, selectedItemIds) => selectedItemIds.includes(itemId);
36
+
37
+ /**
38
+ * Memoized wrapper around ActionList.Item that skips re-rendering when props
39
+ * haven't changed. Combined with the `highlightedItem` ref (instead of state),
40
+ * arrow-key navigation no longer triggers re-renders of the item list.
41
+ */
42
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
43
+ const MemoizedAutocompleteItem = /*#__PURE__*/React.memo(function MemoizedAutocompleteItem({
44
+ item
45
+ }) {
46
+ const {
47
+ id,
48
+ onAction,
49
+ children,
50
+ text,
51
+ leadingVisual: LeadingVisual,
52
+ trailingVisual: TrailingVisual,
53
+ role,
54
+ ...itemProps
55
+ } = item;
56
+ // Remove key from itemProps so it doesn't spread onto the DOM
57
+ delete itemProps.key;
58
+ return /*#__PURE__*/jsxs(ActionList.Item, {
59
+ onSelect: () => onAction(item),
60
+ ...itemProps,
61
+ id: id,
62
+ "data-id": id,
63
+ role: role,
64
+ children: [LeadingVisual && /*#__PURE__*/jsx(ActionList.LeadingVisual, {
65
+ children: isElement(LeadingVisual) ? LeadingVisual : /*#__PURE__*/jsx(LeadingVisual, {})
66
+ }), children !== null && children !== void 0 ? children : text, TrailingVisual && /*#__PURE__*/jsx(ActionList.TrailingVisual, {
67
+ children: isElement(TrailingVisual) ? TrailingVisual : /*#__PURE__*/jsx(TrailingVisual, {})
68
+ })]
69
+ });
70
+ });
36
71
  function getItemById(itemId, items) {
37
72
  return items.find(item => item.id === itemId);
38
73
  }
@@ -85,7 +120,19 @@ function AutocompleteMenu(props) {
85
120
  } = props;
86
121
  const listContainerRef = useRef(null);
87
122
  const allItemsToRenderRef = useRef([]);
88
- const [highlightedItem, setHighlightedItem] = useState();
123
+ // Using a ref instead of state to avoid triggering a re-render of all items
124
+ // on every arrow-key press. The active styling was already handled via DOM by
125
+ // useFocusZone (data-is-active-descendant) before this change, but the
126
+ // previous useState caused React to re-render the entire item list anyway.
127
+ const highlightedItemRef = useRef();
128
+ const deferredInputValueRef = useRef(deferredInputValue);
129
+ const selectedItemIdsRef = useRef(selectedItemIds);
130
+ useEffect(() => {
131
+ deferredInputValueRef.current = deferredInputValue;
132
+ }, [deferredInputValue]);
133
+ useEffect(() => {
134
+ selectedItemIdsRef.current = selectedItemIds;
135
+ }, [selectedItemIds]);
89
136
  const [sortedItemIds, setSortedItemIds] = useState(items.map(({
90
137
  id: itemId
91
138
  }) => itemId));
@@ -95,7 +142,6 @@ function AutocompleteMenu(props) {
95
142
  ...selectableItem,
96
143
  role: 'option',
97
144
  id: selectableItem.id,
98
- active: (highlightedItem === null || highlightedItem === void 0 ? void 0 : highlightedItem.id) === selectableItem.id,
99
145
  selected: selectionVariant === 'multiple' ? selectedItemIds.includes(selectableItem.id) : undefined,
100
146
  onAction: item => {
101
147
  const otherSelectedItemIds = selectedItemIds.filter(selectedItemId => selectedItemId !== item.id);
@@ -112,7 +158,7 @@ function AutocompleteMenu(props) {
112
158
  }
113
159
  }
114
160
  };
115
- }), [highlightedItem, items, selectedItemIds, inputRef, onSelectedChange, selectionVariant, setAutocompleteSuggestion, setInputValue, setShowMenu]);
161
+ }), [items, selectedItemIds, inputRef, onSelectedChange, selectionVariant, setAutocompleteSuggestion, setInputValue, setShowMenu]);
116
162
  const itemSortOrderData = useMemo(() => sortedItemIds.reduce((acc, curr, i) => {
117
163
  acc[curr] = i;
118
164
  return acc;
@@ -126,7 +172,6 @@ function AutocompleteMenu(props) {
126
172
  ...addNewItem,
127
173
  role: 'option',
128
174
  key: addNewItem.id,
129
- active: (highlightedItem === null || highlightedItem === void 0 ? void 0 : highlightedItem.id) === addNewItem.id,
130
175
  selected: selectionVariant === 'multiple' ? selectedItemIds.includes(addNewItem.id) : undefined,
131
176
  leadingVisual: () => /*#__PURE__*/jsx(PlusIcon, {}),
132
177
  onAction: item => {
@@ -141,7 +186,7 @@ function AutocompleteMenu(props) {
141
186
  setAutocompleteSuggestion('');
142
187
  }
143
188
  }
144
- }] : [])], [sortedAndFilteredItemsToRender, addNewItem, setAutocompleteSuggestion, selectionVariant, setInputValue, generatedUniqueId, highlightedItem, selectedItemIds]);
189
+ }] : [])], [sortedAndFilteredItemsToRender, addNewItem, setAutocompleteSuggestion, selectionVariant, setInputValue, generatedUniqueId, selectedItemIds]);
145
190
  React.useEffect(() => {
146
191
  allItemsToRenderRef.current = allItemsToRender;
147
192
  });
@@ -159,13 +204,28 @@ function AutocompleteMenu(props) {
159
204
  activeDescendantFocus: inputRef,
160
205
  onActiveDescendantChanged: (current, _previous, directlyActivated) => {
161
206
  activeDescendantRef.current = current || null;
207
+
208
+ // Active styling was already handled via DOM before this change:
209
+ // useFocusZone sets `data-is-active-descendant` on the active element,
210
+ // and ActionList styles that attribute in CSS. The key change is that
211
+ // we no longer call setHighlightedItem (state), avoiding re-renders.
212
+
162
213
  if (current) {
214
+ var _selectedItem$text;
215
+ const currentLi = current.closest('li');
163
216
  const selectedItem = allItemsToRenderRef.current.find(item => {
164
- var _current$closest;
165
- return item.id === ((_current$closest = current.closest('li')) === null || _current$closest === void 0 ? void 0 : _current$closest.getAttribute('data-id'));
217
+ return item.id === (currentLi === null || currentLi === void 0 ? void 0 : currentLi.getAttribute('data-id'));
166
218
  });
167
- setHighlightedItem(selectedItem);
219
+ highlightedItemRef.current = selectedItem;
168
220
  setIsMenuDirectlyActivated(directlyActivated);
221
+
222
+ // Update autocomplete suggestion inline (moved from the useEffect
223
+ // that previously depended on highlightedItem state)
224
+ if (selectedItem !== null && selectedItem !== void 0 && (_selectedItem$text = selectedItem.text) !== null && _selectedItem$text !== void 0 && _selectedItem$text.startsWith(deferredInputValueRef.current) && !selectedItemIdsRef.current.includes(selectedItem.id)) {
225
+ setAutocompleteSuggestion(selectedItem.text);
226
+ } else {
227
+ setAutocompleteSuggestion('');
228
+ }
169
229
  }
170
230
  if (current && customScrollContainerRef && customScrollContainerRef.current && directlyActivated) {
171
231
  scrollIntoView(current, customScrollContainerRef.current, menuScrollMargins);
@@ -175,15 +235,16 @@ function AutocompleteMenu(props) {
175
235
  }
176
236
  }, [loading]);
177
237
  useEffect(() => {
178
- var _highlightedItem$text;
179
- // Use deferredInputValue to avoid running this effect on every keystroke
180
- // The Input component guards against stale suggestions
181
- if (highlightedItem !== null && highlightedItem !== void 0 && (_highlightedItem$text = highlightedItem.text) !== null && _highlightedItem$text !== void 0 && _highlightedItem$text.startsWith(deferredInputValue) && !selectedItemIds.includes(highlightedItem.id)) {
182
- setAutocompleteSuggestion(highlightedItem.text);
238
+ var _highlighted$text;
239
+ // When the input value changes, update the autocomplete suggestion based
240
+ // on the currently highlighted item (tracked via ref, not state).
241
+ const highlighted = highlightedItemRef.current;
242
+ if (highlighted !== null && highlighted !== void 0 && (_highlighted$text = highlighted.text) !== null && _highlighted$text !== void 0 && _highlighted$text.startsWith(deferredInputValue) && !selectedItemIds.includes(highlighted.id)) {
243
+ setAutocompleteSuggestion(highlighted.text);
183
244
  } else {
184
245
  setAutocompleteSuggestion('');
185
246
  }
186
- }, [highlightedItem, deferredInputValue, selectedItemIds, setAutocompleteSuggestion]);
247
+ }, [deferredInputValue, selectedItemIds, setAutocompleteSuggestion]);
187
248
  useEffect(() => {
188
249
  const itemIdSortResult = [...sortedItemIds].sort(sortOnCloseFn ? sortOnCloseFn : getDefaultSortFn(itemId => isItemSelected(itemId, selectedItemIds)));
189
250
  const sortResultMatchesState = itemIdSortResult.length === sortedItemIds.length && itemIdSortResult.every((element, index) => element === sortedItemIds[index]);
@@ -215,29 +276,10 @@ function AutocompleteMenu(props) {
215
276
  id: `${id}-listbox`,
216
277
  "aria-labelledby": ariaLabelledBy,
217
278
  children: allItemsToRender.map(item => {
218
- const {
219
- id,
220
- onAction,
221
- children,
222
- text,
223
- leadingVisual: LeadingVisual,
224
- trailingVisual: TrailingVisual,
225
- key,
226
- role,
227
- ...itemProps
228
- } = item;
229
- return /*#__PURE__*/jsxs(ActionList.Item, {
230
- onSelect: () => onAction(item),
231
- ...itemProps,
232
- id: id,
233
- "data-id": id,
234
- role: role,
235
- children: [LeadingVisual && /*#__PURE__*/jsx(ActionList.LeadingVisual, {
236
- children: isElement(LeadingVisual) ? LeadingVisual : /*#__PURE__*/jsx(LeadingVisual, {})
237
- }), children !== null && children !== void 0 ? children : text, TrailingVisual && /*#__PURE__*/jsx(ActionList.TrailingVisual, {
238
- children: isElement(TrailingVisual) ? TrailingVisual : /*#__PURE__*/jsx(TrailingVisual, {})
239
- })]
240
- }, key !== null && key !== void 0 ? key : id);
279
+ var _item$key;
280
+ return /*#__PURE__*/jsx(MemoizedAutocompleteItem, {
281
+ item: item
282
+ }, (_item$key = item.key) !== null && _item$key !== void 0 ? _item$key : item.id);
241
283
  })
242
284
  }) : emptyStateText !== false && emptyStateText !== null ? /*#__PURE__*/jsx("div", {
243
285
  className: classes.EmptyStateWrapper,
@@ -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,MAAM,MAAM,aAAa,GAAG;IAC1B,YAAY,CAAC,EAAE,KAAK,CAAC,cAAc,CAAC,YAAY,CAAC,CAAA;IACjD,iBAAiB,CAAC,EAAE,KAAK,CAAC,cAAc,CAAC,iBAAiB,CAAC,CAAA;IAC3D,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAA;CAC5B,CAAA;AAED,MAAM,MAAM,wBAAwB,GAAG;IACrC,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,MAAM,IAAI,CAAA;IACnB,IAAI,EAAE,IAAI,CAAA;IACV,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACv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AAG,CAAC,CAAC,KAAK,EAAE;QAAC,UAAU,EAAE,OAAO,CAAA;KAAC,KAAK,KAAK,CAAC,SAAS,CAAC,CAAA;IAG/E,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAqED,MAAM,MAAM,sBAAsB,GAAG;IACnC,KAAK,EAAE,wBAAwB,EAAE,CAAA;IACjC,YAAY,EAAE,MAAM,CAAA;CACrB,CAAA;AA0ED,MAAM,MAAM,yBAAyB,GAAG;IACtC,KAAK,EAAE,wBAAwB,EAAE,CAAA;IACjC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;CACrB,CAAA;AAwED,MAAM,MAAM,wBAAwB,GAAG;IACrC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;IACpB,SAAS,CAAC,EAAE,MAAM,IAAI,CAAA;CACvB,CAAA;AA4CD,eAAO,MAAM,QAAQ;;;;;;;;CAQnB,CAAA"}
@@ -31,8 +31,7 @@ const RootContext = /*#__PURE__*/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);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@primer/react",
3
3
  "type": "module",
4
- "version": "0.0.0-20260306181027",
4
+ "version": "0.0.0-20260306181113",
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",