@primer/react 0.0.0-20260312164952 → 0.0.0-20260312165019
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-
|
|
3
|
+
## 0.0.0-20260312165019
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
- [#7625](https://github.com/primer/react/pull/7625) [`2e8c707`](https://github.com/primer/react/commit/2e8c70702d5096551049c29c8e79749bf63a919f) Thanks [@liuliu-dev](https://github.com/liuliu-dev)! - Banner: stack inline actions vertically on narrow viewports.
|
|
14
14
|
|
|
15
|
-
- [#
|
|
15
|
+
- [#7600](https://github.com/primer/react/pull/7600) [`77be5b9`](https://github.com/primer/react/commit/77be5b98b788d49d8cc695b96e8cb412d7ca2935) Thanks [@hectahertz](https://github.com/hectahertz)! - perf(TextInput): skip redundant character counter updates
|
|
16
16
|
|
|
17
17
|
- [#7654](https://github.com/primer/react/pull/7654) [`a09a60c`](https://github.com/primer/react/commit/a09a60cb8218adf8fe2ab71e46da76fbf8331bc6) Thanks [@copilot-swe-agent](https://github.com/apps/copilot-swe-agent)! - SelectPanel: use `100dvh` and `env(safe-area-inset-bottom)` in fullscreen-on-narrow mode to prevent content from being obscured by iOS Safari's browser chrome.
|
|
18
18
|
|
|
@@ -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,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,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,qBAqRjG;kBArRQ,gBAAgB;;;;AAyRzB,MAAM,MAAM,qBAAqB,GAAG,cAAc,CAAC,OAAO,gBAAgB,CAAC,CAAA;AAC3E,eAAe,gBAAgB,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useContext, useRef,
|
|
1
|
+
import React, { useContext, useRef, useState, useMemo, useEffect } 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,41 +33,6 @@ 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
|
-
});
|
|
71
36
|
function getItemById(itemId, items) {
|
|
72
37
|
return items.find(item => item.id === itemId);
|
|
73
38
|
}
|
|
@@ -120,19 +85,7 @@ function AutocompleteMenu(props) {
|
|
|
120
85
|
} = props;
|
|
121
86
|
const listContainerRef = useRef(null);
|
|
122
87
|
const allItemsToRenderRef = useRef([]);
|
|
123
|
-
|
|
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]);
|
|
88
|
+
const [highlightedItem, setHighlightedItem] = useState();
|
|
136
89
|
const [sortedItemIds, setSortedItemIds] = useState(items.map(({
|
|
137
90
|
id: itemId
|
|
138
91
|
}) => itemId));
|
|
@@ -142,6 +95,7 @@ function AutocompleteMenu(props) {
|
|
|
142
95
|
...selectableItem,
|
|
143
96
|
role: 'option',
|
|
144
97
|
id: selectableItem.id,
|
|
98
|
+
active: (highlightedItem === null || highlightedItem === void 0 ? void 0 : highlightedItem.id) === selectableItem.id,
|
|
145
99
|
selected: selectionVariant === 'multiple' ? selectedItemIds.includes(selectableItem.id) : undefined,
|
|
146
100
|
onAction: item => {
|
|
147
101
|
const otherSelectedItemIds = selectedItemIds.filter(selectedItemId => selectedItemId !== item.id);
|
|
@@ -158,7 +112,7 @@ function AutocompleteMenu(props) {
|
|
|
158
112
|
}
|
|
159
113
|
}
|
|
160
114
|
};
|
|
161
|
-
}), [items, selectedItemIds, inputRef, onSelectedChange, selectionVariant, setAutocompleteSuggestion, setInputValue, setShowMenu]);
|
|
115
|
+
}), [highlightedItem, items, selectedItemIds, inputRef, onSelectedChange, selectionVariant, setAutocompleteSuggestion, setInputValue, setShowMenu]);
|
|
162
116
|
const itemSortOrderData = useMemo(() => sortedItemIds.reduce((acc, curr, i) => {
|
|
163
117
|
acc[curr] = i;
|
|
164
118
|
return acc;
|
|
@@ -172,6 +126,7 @@ function AutocompleteMenu(props) {
|
|
|
172
126
|
...addNewItem,
|
|
173
127
|
role: 'option',
|
|
174
128
|
key: addNewItem.id,
|
|
129
|
+
active: (highlightedItem === null || highlightedItem === void 0 ? void 0 : highlightedItem.id) === addNewItem.id,
|
|
175
130
|
selected: selectionVariant === 'multiple' ? selectedItemIds.includes(addNewItem.id) : undefined,
|
|
176
131
|
leadingVisual: () => /*#__PURE__*/jsx(PlusIcon, {}),
|
|
177
132
|
onAction: item => {
|
|
@@ -186,7 +141,7 @@ function AutocompleteMenu(props) {
|
|
|
186
141
|
setAutocompleteSuggestion('');
|
|
187
142
|
}
|
|
188
143
|
}
|
|
189
|
-
}] : [])], [sortedAndFilteredItemsToRender, addNewItem, setAutocompleteSuggestion, selectionVariant, setInputValue, generatedUniqueId, selectedItemIds]);
|
|
144
|
+
}] : [])], [sortedAndFilteredItemsToRender, addNewItem, setAutocompleteSuggestion, selectionVariant, setInputValue, generatedUniqueId, highlightedItem, selectedItemIds]);
|
|
190
145
|
React.useEffect(() => {
|
|
191
146
|
allItemsToRenderRef.current = allItemsToRender;
|
|
192
147
|
});
|
|
@@ -204,28 +159,13 @@ function AutocompleteMenu(props) {
|
|
|
204
159
|
activeDescendantFocus: inputRef,
|
|
205
160
|
onActiveDescendantChanged: (current, _previous, directlyActivated) => {
|
|
206
161
|
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
|
-
|
|
213
162
|
if (current) {
|
|
214
|
-
var _selectedItem$text;
|
|
215
|
-
const currentLi = current.closest('li');
|
|
216
163
|
const selectedItem = allItemsToRenderRef.current.find(item => {
|
|
217
|
-
|
|
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'));
|
|
218
166
|
});
|
|
219
|
-
|
|
167
|
+
setHighlightedItem(selectedItem);
|
|
220
168
|
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
|
-
}
|
|
229
169
|
}
|
|
230
170
|
if (current && customScrollContainerRef && customScrollContainerRef.current && directlyActivated) {
|
|
231
171
|
scrollIntoView(current, customScrollContainerRef.current, menuScrollMargins);
|
|
@@ -235,16 +175,15 @@ function AutocompleteMenu(props) {
|
|
|
235
175
|
}
|
|
236
176
|
}, [loading]);
|
|
237
177
|
useEffect(() => {
|
|
238
|
-
var
|
|
239
|
-
//
|
|
240
|
-
//
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
setAutocompleteSuggestion(highlighted.text);
|
|
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);
|
|
244
183
|
} else {
|
|
245
184
|
setAutocompleteSuggestion('');
|
|
246
185
|
}
|
|
247
|
-
}, [deferredInputValue, selectedItemIds, setAutocompleteSuggestion]);
|
|
186
|
+
}, [highlightedItem, deferredInputValue, selectedItemIds, setAutocompleteSuggestion]);
|
|
248
187
|
useEffect(() => {
|
|
249
188
|
const itemIdSortResult = [...sortedItemIds].sort(sortOnCloseFn ? sortOnCloseFn : getDefaultSortFn(itemId => isItemSelected(itemId, selectedItemIds)));
|
|
250
189
|
const sortResultMatchesState = itemIdSortResult.length === sortedItemIds.length && itemIdSortResult.every((element, index) => element === sortedItemIds[index]);
|
|
@@ -276,10 +215,29 @@ function AutocompleteMenu(props) {
|
|
|
276
215
|
id: `${id}-listbox`,
|
|
277
216
|
"aria-labelledby": ariaLabelledBy,
|
|
278
217
|
children: allItemsToRender.map(item => {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
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);
|
|
283
241
|
})
|
|
284
242
|
}) : emptyStateText !== false && emptyStateText !== null ? /*#__PURE__*/jsx("div", {
|
|
285
243
|
className: classes.EmptyStateWrapper,
|
|
@@ -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;IAC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,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,CAAC,wBAAwB,CAAC,OAAO,CAAC,EAAE,4BAA4B,CAAC,CAAA;;;;;;;;;;;AA+PzG,wBAGE"}
|
|
@@ -51,6 +51,10 @@ 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('');
|
|
54
58
|
|
|
55
59
|
// this class is necessary to style FilterSearch, plz no touchy!
|
|
56
60
|
const wrapperClasses = clsx(className, 'TextInput-wrapper');
|
|
@@ -84,17 +88,31 @@ const TextInput = /*#__PURE__*/React.forwardRef(({
|
|
|
84
88
|
if (characterLimit) {
|
|
85
89
|
characterCounterRef.current = new CharacterCounter({
|
|
86
90
|
onCountUpdate: (count, overLimit, message) => {
|
|
87
|
-
|
|
88
|
-
|
|
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
|
+
}
|
|
89
99
|
},
|
|
90
100
|
onScreenReaderAnnounce: message_0 => {
|
|
91
|
-
|
|
101
|
+
if (message_0 !== lastScreenReaderMessageRef.current) {
|
|
102
|
+
lastScreenReaderMessageRef.current = message_0;
|
|
103
|
+
setScreenReaderMessage(message_0);
|
|
104
|
+
}
|
|
92
105
|
}
|
|
93
106
|
});
|
|
107
|
+
lastCountedLengthRef.current = null;
|
|
94
108
|
return () => {
|
|
95
109
|
var _characterCounterRef$;
|
|
96
110
|
(_characterCounterRef$ = characterCounterRef.current) === null || _characterCounterRef$ === void 0 ? void 0 : _characterCounterRef$.cleanup();
|
|
97
111
|
characterCounterRef.current = null;
|
|
112
|
+
lastCountedLengthRef.current = null;
|
|
113
|
+
lastCharacterCountRef.current = '';
|
|
114
|
+
lastIsOverLimitRef.current = false;
|
|
115
|
+
lastScreenReaderMessageRef.current = '';
|
|
98
116
|
};
|
|
99
117
|
}
|
|
100
118
|
}, [characterLimit]);
|
|
@@ -103,14 +121,22 @@ const TextInput = /*#__PURE__*/React.forwardRef(({
|
|
|
103
121
|
useEffect(() => {
|
|
104
122
|
if (characterLimit && characterCounterRef.current) {
|
|
105
123
|
const currentValue = value !== undefined ? String(value) : defaultValue !== undefined ? String(defaultValue) : '';
|
|
106
|
-
|
|
124
|
+
const currentLength = currentValue.length;
|
|
125
|
+
if (currentLength !== lastCountedLengthRef.current) {
|
|
126
|
+
lastCountedLengthRef.current = currentLength;
|
|
127
|
+
characterCounterRef.current.updateCharacterCount(currentLength, characterLimit);
|
|
128
|
+
}
|
|
107
129
|
}
|
|
108
130
|
}, [value, defaultValue, characterLimit]);
|
|
109
131
|
|
|
110
132
|
// Handle input change with character counter
|
|
111
133
|
const handleInputChange = useCallback(e_2 => {
|
|
112
134
|
if (characterLimit && characterCounterRef.current) {
|
|
113
|
-
|
|
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
|
+
}
|
|
114
140
|
}
|
|
115
141
|
onChange === null || onChange === void 0 ? void 0 : onChange(e_2);
|
|
116
142
|
}, [onChange, characterLimit]);
|
package/package.json
CHANGED