@primer/react 0.0.0-20260220174352 → 0.0.0-20260220184804
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 +15 -1
- package/dist/Autocomplete/Autocomplete.js +76 -159
- package/dist/Autocomplete/AutocompleteMenu.js +128 -333
- package/dist/Autocomplete/AutocompleteOverlay.js +49 -130
- package/dist/Banner/Banner.js +64 -238
- package/dist/Button/Button.js +11 -34
- package/dist/Button/IconButton.js +51 -140
- package/dist/Button/LinkButton.js +11 -39
- package/dist/Checkbox/Checkbox.js +55 -163
- package/dist/Dialog/Dialog.js +105 -347
- package/dist/FilteredActionList/FilteredActionList.d.ts +16 -1
- package/dist/FilteredActionList/FilteredActionList.d.ts.map +1 -1
- package/dist/FilteredActionList/FilteredActionList.js +147 -42
- package/dist/Overlay/Overlay-15519c09.css +2 -0
- package/dist/Overlay/Overlay-15519c09.css.map +1 -0
- package/dist/Overlay/Overlay.module.css.js +1 -1
- package/dist/PageLayout/PageLayout.js +622 -1560
- package/dist/SelectPanel/SelectPanel.d.ts +1 -1
- package/dist/SelectPanel/SelectPanel.d.ts.map +1 -1
- package/dist/SelectPanel/SelectPanel.js +3 -1
- package/dist/Text/Text.d.ts +1 -1
- package/dist/Text/Text.d.ts.map +1 -1
- package/dist/Text/Text.js +10 -13
- package/dist/UnderlineNav/UnderlineNavItem.js +56 -149
- package/dist/experimental/SelectPanel2/SelectPanel.js +209 -593
- package/dist/hooks/useRefObjectAsForwardedRef.d.ts.map +1 -1
- package/dist/hooks/useRefObjectAsForwardedRef.js +10 -2
- package/dist/hooks/useScrollFlash.d.ts.map +1 -1
- package/dist/hooks/useScrollFlash.js +14 -22
- package/dist/hooks/useSlots.d.ts +50 -6
- package/dist/hooks/useSlots.d.ts.map +1 -1
- package/dist/hooks/useSlots.js +114 -36
- package/generated/components.json +6 -0
- package/package.json +2 -2
- package/dist/Overlay/Overlay-43cda449.css +0 -2
- package/dist/Overlay/Overlay-43cda449.css.map +0 -1
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import React, { useContext, useRef, useState, useEffect } from 'react';
|
|
1
|
+
import React, { useContext, useRef, useState, useMemo, useEffect } from 'react';
|
|
3
2
|
import { debounce } from '@github/mini-throttle';
|
|
4
3
|
import { announce } from '@primer/live-region-element';
|
|
5
4
|
import { scrollIntoView } from '@primer/behaviors';
|
|
@@ -48,11 +47,10 @@ const debounceAnnouncement = debounce(announcement => {
|
|
|
48
47
|
announce(announcement);
|
|
49
48
|
}, 250);
|
|
50
49
|
function AutocompleteMenu(props) {
|
|
51
|
-
const $ = c(78);
|
|
52
50
|
const autocompleteContext = useContext(AutocompleteContext);
|
|
53
51
|
const deferredInputContext = useContext(AutocompleteDeferredInputContext);
|
|
54
52
|
if (autocompleteContext === null || deferredInputContext === null) {
|
|
55
|
-
throw new Error(
|
|
53
|
+
throw new Error('AutocompleteContext returned null values');
|
|
56
54
|
}
|
|
57
55
|
const {
|
|
58
56
|
activeDescendantRef,
|
|
@@ -66,6 +64,8 @@ function AutocompleteMenu(props) {
|
|
|
66
64
|
setSelectedItemLength,
|
|
67
65
|
showMenu
|
|
68
66
|
} = autocompleteContext;
|
|
67
|
+
// Use deferred input value to avoid re-rendering on every keystroke
|
|
68
|
+
// This allows filtering large lists without blocking typing
|
|
69
69
|
const {
|
|
70
70
|
deferredInputValue
|
|
71
71
|
} = deferredInputContext;
|
|
@@ -73,385 +73,180 @@ function AutocompleteMenu(props) {
|
|
|
73
73
|
items,
|
|
74
74
|
selectedItemIds,
|
|
75
75
|
sortOnCloseFn,
|
|
76
|
-
emptyStateText
|
|
76
|
+
emptyStateText = 'No selectable options',
|
|
77
77
|
addNewItem,
|
|
78
78
|
loading,
|
|
79
|
-
selectionVariant
|
|
79
|
+
selectionVariant = 'single',
|
|
80
80
|
filterFn,
|
|
81
|
-
|
|
81
|
+
'aria-labelledby': ariaLabelledBy,
|
|
82
82
|
onOpenChange,
|
|
83
83
|
onSelectedChange,
|
|
84
84
|
customScrollContainerRef
|
|
85
85
|
} = props;
|
|
86
|
-
const emptyStateText = t0 === undefined ? "No selectable options" : t0;
|
|
87
|
-
const selectionVariant = t1 === undefined ? "single" : t1;
|
|
88
86
|
const listContainerRef = useRef(null);
|
|
89
|
-
|
|
90
|
-
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
|
91
|
-
t2 = [];
|
|
92
|
-
$[0] = t2;
|
|
93
|
-
} else {
|
|
94
|
-
t2 = $[0];
|
|
95
|
-
}
|
|
96
|
-
const allItemsToRenderRef = useRef(t2);
|
|
87
|
+
const allItemsToRenderRef = useRef([]);
|
|
97
88
|
const [highlightedItem, setHighlightedItem] = useState();
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
$[1] = items;
|
|
102
|
-
$[2] = t3;
|
|
103
|
-
} else {
|
|
104
|
-
t3 = $[2];
|
|
105
|
-
}
|
|
106
|
-
const [sortedItemIds, setSortedItemIds] = useState(t3);
|
|
89
|
+
const [sortedItemIds, setSortedItemIds] = useState(items.map(({
|
|
90
|
+
id: itemId
|
|
91
|
+
}) => itemId));
|
|
107
92
|
const generatedUniqueId = useId(id);
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
t4 = items.map(selectableItem => ({
|
|
93
|
+
const selectableItems = useMemo(() => items.map(selectableItem => {
|
|
94
|
+
return {
|
|
111
95
|
...selectableItem,
|
|
112
|
-
role:
|
|
96
|
+
role: 'option',
|
|
113
97
|
id: selectableItem.id,
|
|
114
98
|
active: (highlightedItem === null || highlightedItem === void 0 ? void 0 : highlightedItem.id) === selectableItem.id,
|
|
115
|
-
selected: selectionVariant ===
|
|
99
|
+
selected: selectionVariant === 'multiple' ? selectedItemIds.includes(selectableItem.id) : undefined,
|
|
116
100
|
onAction: item => {
|
|
117
101
|
const otherSelectedItemIds = selectedItemIds.filter(selectedItemId => selectedItemId !== item.id);
|
|
118
102
|
const newSelectedItemIds = selectedItemIds.includes(item.id) ? otherSelectedItemIds : [...otherSelectedItemIds, item.id];
|
|
119
103
|
const onSelectedChangeFn = onSelectedChange ? onSelectedChange : getdefaultCheckedSelectionChange(setInputValue);
|
|
120
104
|
onSelectedChangeFn(newSelectedItemIds.map(newSelectedItemId => getItemById(newSelectedItemId, items)));
|
|
121
|
-
if (selectionVariant ===
|
|
122
|
-
setInputValue(
|
|
123
|
-
setAutocompleteSuggestion(
|
|
105
|
+
if (selectionVariant === 'multiple') {
|
|
106
|
+
setInputValue('');
|
|
107
|
+
setAutocompleteSuggestion('');
|
|
124
108
|
} else {
|
|
125
109
|
var _inputRef$current;
|
|
126
110
|
setShowMenu(false);
|
|
127
111
|
(_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.setSelectionRange(inputRef.current.value.length, inputRef.current.value.length);
|
|
128
112
|
}
|
|
129
113
|
}
|
|
130
|
-
}));
|
|
131
|
-
$[3] = highlightedItem === null || highlightedItem === void 0 ? void 0 : highlightedItem.id;
|
|
132
|
-
$[4] = inputRef;
|
|
133
|
-
$[5] = items;
|
|
134
|
-
$[6] = onSelectedChange;
|
|
135
|
-
$[7] = selectedItemIds;
|
|
136
|
-
$[8] = selectionVariant;
|
|
137
|
-
$[9] = setAutocompleteSuggestion;
|
|
138
|
-
$[10] = setInputValue;
|
|
139
|
-
$[11] = setShowMenu;
|
|
140
|
-
$[12] = t4;
|
|
141
|
-
} else {
|
|
142
|
-
t4 = $[12];
|
|
143
|
-
}
|
|
144
|
-
const selectableItems = t4;
|
|
145
|
-
let t5;
|
|
146
|
-
if ($[13] !== sortedItemIds) {
|
|
147
|
-
t5 = sortedItemIds.reduce(_temp2, {});
|
|
148
|
-
$[13] = sortedItemIds;
|
|
149
|
-
$[14] = t5;
|
|
150
|
-
} else {
|
|
151
|
-
t5 = $[14];
|
|
152
|
-
}
|
|
153
|
-
const itemSortOrderData = t5;
|
|
154
|
-
let t6;
|
|
155
|
-
if ($[15] !== deferredInputValue || $[16] !== filterFn || $[17] !== itemSortOrderData || $[18] !== selectableItems) {
|
|
156
|
-
let t7;
|
|
157
|
-
if ($[20] !== itemSortOrderData) {
|
|
158
|
-
t7 = (a, b) => itemSortOrderData[a.id] - itemSortOrderData[b.id];
|
|
159
|
-
$[20] = itemSortOrderData;
|
|
160
|
-
$[21] = t7;
|
|
161
|
-
} else {
|
|
162
|
-
t7 = $[21];
|
|
163
|
-
}
|
|
164
|
-
t6 = selectableItems.filter(filterFn ? filterFn : getDefaultItemFilter(deferredInputValue)).sort(t7);
|
|
165
|
-
$[15] = deferredInputValue;
|
|
166
|
-
$[16] = filterFn;
|
|
167
|
-
$[17] = itemSortOrderData;
|
|
168
|
-
$[18] = selectableItems;
|
|
169
|
-
$[19] = t6;
|
|
170
|
-
} else {
|
|
171
|
-
t6 = $[19];
|
|
172
|
-
}
|
|
173
|
-
const sortedAndFilteredItemsToRender = t6;
|
|
174
|
-
let t7;
|
|
175
|
-
if ($[22] !== addNewItem || $[23] !== generatedUniqueId || $[24] !== (highlightedItem === null || highlightedItem === void 0 ? void 0 : highlightedItem.id) || $[25] !== selectedItemIds || $[26] !== selectionVariant || $[27] !== setAutocompleteSuggestion || $[28] !== setInputValue) {
|
|
176
|
-
t7 = addNewItem ? [{
|
|
177
|
-
...addNewItem,
|
|
178
|
-
role: "option",
|
|
179
|
-
key: addNewItem.id,
|
|
180
|
-
active: (highlightedItem === null || highlightedItem === void 0 ? void 0 : highlightedItem.id) === addNewItem.id,
|
|
181
|
-
selected: selectionVariant === "multiple" ? selectedItemIds.includes(addNewItem.id) : undefined,
|
|
182
|
-
leadingVisual: _temp3,
|
|
183
|
-
onAction: item_0 => {
|
|
184
|
-
addNewItem.handleAddItem({
|
|
185
|
-
...item_0,
|
|
186
|
-
id: item_0.id || generatedUniqueId,
|
|
187
|
-
leadingVisual: undefined
|
|
188
|
-
});
|
|
189
|
-
if (selectionVariant === "multiple") {
|
|
190
|
-
setInputValue("");
|
|
191
|
-
setAutocompleteSuggestion("");
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}] : [];
|
|
195
|
-
$[22] = addNewItem;
|
|
196
|
-
$[23] = generatedUniqueId;
|
|
197
|
-
$[24] = highlightedItem === null || highlightedItem === void 0 ? void 0 : highlightedItem.id;
|
|
198
|
-
$[25] = selectedItemIds;
|
|
199
|
-
$[26] = selectionVariant;
|
|
200
|
-
$[27] = setAutocompleteSuggestion;
|
|
201
|
-
$[28] = setInputValue;
|
|
202
|
-
$[29] = t7;
|
|
203
|
-
} else {
|
|
204
|
-
t7 = $[29];
|
|
205
|
-
}
|
|
206
|
-
let t8;
|
|
207
|
-
if ($[30] !== sortedAndFilteredItemsToRender || $[31] !== t7) {
|
|
208
|
-
t8 = [...sortedAndFilteredItemsToRender, ...t7];
|
|
209
|
-
$[30] = sortedAndFilteredItemsToRender;
|
|
210
|
-
$[31] = t7;
|
|
211
|
-
$[32] = t8;
|
|
212
|
-
} else {
|
|
213
|
-
t8 = $[32];
|
|
214
|
-
}
|
|
215
|
-
const allItemsToRender = t8;
|
|
216
|
-
let t9;
|
|
217
|
-
if ($[33] !== allItemsToRender) {
|
|
218
|
-
t9 = () => {
|
|
219
|
-
allItemsToRenderRef.current = allItemsToRender;
|
|
220
114
|
};
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
115
|
+
}), [highlightedItem, items, selectedItemIds, inputRef, onSelectedChange, selectionVariant, setAutocompleteSuggestion, setInputValue, setShowMenu]);
|
|
116
|
+
const itemSortOrderData = useMemo(() => sortedItemIds.reduce((acc, curr, i) => {
|
|
117
|
+
acc[curr] = i;
|
|
118
|
+
return acc;
|
|
119
|
+
}, {}), [sortedItemIds]);
|
|
120
|
+
const sortedAndFilteredItemsToRender = useMemo(() => selectableItems.filter(filterFn ? filterFn : getDefaultItemFilter(deferredInputValue)).sort((a, b) => itemSortOrderData[a.id] - itemSortOrderData[b.id]), [selectableItems, itemSortOrderData, filterFn, deferredInputValue]);
|
|
121
|
+
const allItemsToRender = useMemo(() => [
|
|
122
|
+
// sorted and filtered selectable items
|
|
123
|
+
...sortedAndFilteredItemsToRender,
|
|
124
|
+
// menu item used for creating a token from whatever is in the text input
|
|
125
|
+
...(addNewItem ? [{
|
|
126
|
+
...addNewItem,
|
|
127
|
+
role: 'option',
|
|
128
|
+
key: addNewItem.id,
|
|
129
|
+
active: (highlightedItem === null || highlightedItem === void 0 ? void 0 : highlightedItem.id) === addNewItem.id,
|
|
130
|
+
selected: selectionVariant === 'multiple' ? selectedItemIds.includes(addNewItem.id) : undefined,
|
|
131
|
+
leadingVisual: () => /*#__PURE__*/jsx(PlusIcon, {}),
|
|
132
|
+
onAction: item => {
|
|
133
|
+
// TODO: make it possible to pass a leadingVisual when using `addNewItem`
|
|
134
|
+
addNewItem.handleAddItem({
|
|
135
|
+
...item,
|
|
136
|
+
id: item.id || generatedUniqueId,
|
|
137
|
+
leadingVisual: undefined
|
|
138
|
+
});
|
|
139
|
+
if (selectionVariant === 'multiple') {
|
|
140
|
+
setInputValue('');
|
|
141
|
+
setAutocompleteSuggestion('');
|
|
233
142
|
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
143
|
+
}
|
|
144
|
+
}] : [])], [sortedAndFilteredItemsToRender, addNewItem, setAutocompleteSuggestion, selectionVariant, setInputValue, generatedUniqueId, highlightedItem, selectedItemIds]);
|
|
145
|
+
React.useEffect(() => {
|
|
146
|
+
allItemsToRenderRef.current = allItemsToRender;
|
|
147
|
+
});
|
|
148
|
+
React.useEffect(() => {
|
|
149
|
+
if (allItemsToRender.length === 0) {
|
|
150
|
+
debounceAnnouncement(emptyStateText);
|
|
151
|
+
}
|
|
152
|
+
}, [allItemsToRender, emptyStateText]);
|
|
153
|
+
useFocusZone({
|
|
154
|
+
containerRef: listContainerRef,
|
|
155
|
+
focusOutBehavior: 'wrap',
|
|
156
|
+
focusableElementFilter: element => {
|
|
157
|
+
return !(element instanceof HTMLInputElement);
|
|
158
|
+
},
|
|
159
|
+
activeDescendantFocus: inputRef,
|
|
160
|
+
onActiveDescendantChanged: (current, _previous, directlyActivated) => {
|
|
248
161
|
activeDescendantRef.current = current || null;
|
|
249
162
|
if (current) {
|
|
250
|
-
const selectedItem = allItemsToRenderRef.current.find(
|
|
163
|
+
const selectedItem = allItemsToRenderRef.current.find(item => {
|
|
251
164
|
var _current$closest;
|
|
252
|
-
return
|
|
165
|
+
return item.id === ((_current$closest = current.closest('li')) === null || _current$closest === void 0 ? void 0 : _current$closest.getAttribute('data-id'));
|
|
253
166
|
});
|
|
254
167
|
setHighlightedItem(selectedItem);
|
|
255
168
|
setIsMenuDirectlyActivated(directlyActivated);
|
|
256
169
|
}
|
|
257
170
|
if (current && customScrollContainerRef && customScrollContainerRef.current && directlyActivated) {
|
|
258
171
|
scrollIntoView(current, customScrollContainerRef.current, menuScrollMargins);
|
|
259
|
-
} else {
|
|
260
|
-
|
|
261
|
-
scrollIntoView(current, scrollContainerRef.current, menuScrollMargins);
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
};
|
|
265
|
-
$[39] = activeDescendantRef;
|
|
266
|
-
$[40] = customScrollContainerRef;
|
|
267
|
-
$[41] = scrollContainerRef;
|
|
268
|
-
$[42] = setIsMenuDirectlyActivated;
|
|
269
|
-
$[43] = t12;
|
|
270
|
-
} else {
|
|
271
|
-
t12 = $[43];
|
|
272
|
-
}
|
|
273
|
-
let t13;
|
|
274
|
-
if ($[44] !== inputRef || $[45] !== t12) {
|
|
275
|
-
t13 = {
|
|
276
|
-
containerRef: listContainerRef,
|
|
277
|
-
focusOutBehavior: "wrap",
|
|
278
|
-
focusableElementFilter: _temp4,
|
|
279
|
-
activeDescendantFocus: inputRef,
|
|
280
|
-
onActiveDescendantChanged: t12
|
|
281
|
-
};
|
|
282
|
-
$[44] = inputRef;
|
|
283
|
-
$[45] = t12;
|
|
284
|
-
$[46] = t13;
|
|
285
|
-
} else {
|
|
286
|
-
t13 = $[46];
|
|
287
|
-
}
|
|
288
|
-
let t14;
|
|
289
|
-
if ($[47] !== loading) {
|
|
290
|
-
t14 = [loading];
|
|
291
|
-
$[47] = loading;
|
|
292
|
-
$[48] = t14;
|
|
293
|
-
} else {
|
|
294
|
-
t14 = $[48];
|
|
295
|
-
}
|
|
296
|
-
useFocusZone(t13, t14);
|
|
297
|
-
let t15;
|
|
298
|
-
let t16;
|
|
299
|
-
if ($[49] !== deferredInputValue || $[50] !== highlightedItem || $[51] !== selectedItemIds || $[52] !== setAutocompleteSuggestion) {
|
|
300
|
-
t15 = () => {
|
|
301
|
-
var _highlightedItem$text;
|
|
302
|
-
if (highlightedItem !== null && highlightedItem !== void 0 && (_highlightedItem$text = highlightedItem.text) !== null && _highlightedItem$text !== void 0 && _highlightedItem$text.startsWith(deferredInputValue) && !selectedItemIds.includes(highlightedItem.id)) {
|
|
303
|
-
setAutocompleteSuggestion(highlightedItem.text);
|
|
304
|
-
} else {
|
|
305
|
-
setAutocompleteSuggestion("");
|
|
172
|
+
} else if (current && scrollContainerRef.current && directlyActivated) {
|
|
173
|
+
scrollIntoView(current, scrollContainerRef.current, menuScrollMargins);
|
|
306
174
|
}
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
$
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
$
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
}
|
|
319
|
-
useEffect(
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
$[58] = sortOnCloseFn;
|
|
336
|
-
$[59] = sortedItemIds;
|
|
337
|
-
$[60] = t17;
|
|
338
|
-
$[61] = t18;
|
|
339
|
-
} else {
|
|
340
|
-
t17 = $[60];
|
|
341
|
-
t18 = $[61];
|
|
342
|
-
}
|
|
343
|
-
useEffect(t17, t18);
|
|
344
|
-
let t19;
|
|
345
|
-
if ($[62] !== selectedItemIds.length || $[63] !== setSelectedItemLength) {
|
|
346
|
-
t19 = () => {
|
|
347
|
-
if (selectedItemIds.length) {
|
|
348
|
-
setSelectedItemLength(selectedItemIds.length);
|
|
349
|
-
}
|
|
350
|
-
};
|
|
351
|
-
$[62] = selectedItemIds.length;
|
|
352
|
-
$[63] = setSelectedItemLength;
|
|
353
|
-
$[64] = t19;
|
|
354
|
-
} else {
|
|
355
|
-
t19 = $[64];
|
|
356
|
-
}
|
|
357
|
-
let t20;
|
|
358
|
-
if ($[65] !== selectedItemIds || $[66] !== setSelectedItemLength) {
|
|
359
|
-
t20 = [selectedItemIds, setSelectedItemLength];
|
|
360
|
-
$[65] = selectedItemIds;
|
|
361
|
-
$[66] = setSelectedItemLength;
|
|
362
|
-
$[67] = t20;
|
|
363
|
-
} else {
|
|
364
|
-
t20 = $[67];
|
|
365
|
-
}
|
|
366
|
-
useEffect(t19, t20);
|
|
367
|
-
if (selectionVariant === "single" && selectedItemIds.length > 1) {
|
|
368
|
-
throw new Error("Autocomplete: selectionVariant \"single\" cannot be used with multiple selected items");
|
|
175
|
+
}
|
|
176
|
+
}, [loading]);
|
|
177
|
+
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);
|
|
183
|
+
} else {
|
|
184
|
+
setAutocompleteSuggestion('');
|
|
185
|
+
}
|
|
186
|
+
}, [highlightedItem, deferredInputValue, selectedItemIds, setAutocompleteSuggestion]);
|
|
187
|
+
useEffect(() => {
|
|
188
|
+
const itemIdSortResult = [...sortedItemIds].sort(sortOnCloseFn ? sortOnCloseFn : getDefaultSortFn(itemId => isItemSelected(itemId, selectedItemIds)));
|
|
189
|
+
const sortResultMatchesState = itemIdSortResult.length === sortedItemIds.length && itemIdSortResult.every((element, index) => element === sortedItemIds[index]);
|
|
190
|
+
if (showMenu === false && !sortResultMatchesState) {
|
|
191
|
+
// eslint-disable-next-line react-hooks/set-state-in-effect
|
|
192
|
+
setSortedItemIds(itemIdSortResult);
|
|
193
|
+
}
|
|
194
|
+
onOpenChange && onOpenChange(Boolean(showMenu));
|
|
195
|
+
}, [showMenu, onOpenChange, selectedItemIds, sortOnCloseFn, sortedItemIds]);
|
|
196
|
+
useEffect(() => {
|
|
197
|
+
if (selectedItemIds.length) {
|
|
198
|
+
setSelectedItemLength(selectedItemIds.length);
|
|
199
|
+
}
|
|
200
|
+
}, [selectedItemIds, setSelectedItemLength]);
|
|
201
|
+
if (selectionVariant === 'single' && selectedItemIds.length > 1) {
|
|
202
|
+
throw new Error('Autocomplete: selectionVariant "single" cannot be used with multiple selected items');
|
|
369
203
|
}
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
204
|
+
return /*#__PURE__*/jsx(VisuallyHidden, {
|
|
205
|
+
isVisible: showMenu,
|
|
206
|
+
children: loading ? /*#__PURE__*/jsx("div", {
|
|
373
207
|
className: classes.SpinnerWrapper,
|
|
374
208
|
children: /*#__PURE__*/jsx(Spinner, {})
|
|
375
209
|
}) : /*#__PURE__*/jsx("div", {
|
|
376
210
|
ref: listContainerRef,
|
|
377
211
|
children: allItemsToRender.length ? /*#__PURE__*/jsx(ActionList, {
|
|
378
|
-
selectionVariant: selectionVariant
|
|
212
|
+
selectionVariant: selectionVariant // TODO: make this configurable
|
|
213
|
+
,
|
|
379
214
|
role: "listbox",
|
|
380
215
|
id: `${id}-listbox`,
|
|
381
216
|
"aria-labelledby": ariaLabelledBy,
|
|
382
|
-
children: allItemsToRender.map(
|
|
217
|
+
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);
|
|
241
|
+
})
|
|
383
242
|
}) : emptyStateText !== false && emptyStateText !== null ? /*#__PURE__*/jsx("div", {
|
|
384
243
|
className: classes.EmptyStateWrapper,
|
|
385
244
|
children: emptyStateText
|
|
386
245
|
}) : null
|
|
387
|
-
})
|
|
388
|
-
|
|
389
|
-
$[69] = ariaLabelledBy;
|
|
390
|
-
$[70] = emptyStateText;
|
|
391
|
-
$[71] = id;
|
|
392
|
-
$[72] = loading;
|
|
393
|
-
$[73] = selectionVariant;
|
|
394
|
-
$[74] = t21;
|
|
395
|
-
} else {
|
|
396
|
-
t21 = $[74];
|
|
397
|
-
}
|
|
398
|
-
let t22;
|
|
399
|
-
if ($[75] !== showMenu || $[76] !== t21) {
|
|
400
|
-
t22 = /*#__PURE__*/jsx(VisuallyHidden, {
|
|
401
|
-
isVisible: showMenu,
|
|
402
|
-
children: t21
|
|
403
|
-
});
|
|
404
|
-
$[75] = showMenu;
|
|
405
|
-
$[76] = t21;
|
|
406
|
-
$[77] = t22;
|
|
407
|
-
} else {
|
|
408
|
-
t22 = $[77];
|
|
409
|
-
}
|
|
410
|
-
return t22;
|
|
411
|
-
}
|
|
412
|
-
function _temp5(item_2) {
|
|
413
|
-
const {
|
|
414
|
-
id: id_0,
|
|
415
|
-
onAction,
|
|
416
|
-
children,
|
|
417
|
-
text,
|
|
418
|
-
leadingVisual: LeadingVisual,
|
|
419
|
-
trailingVisual: TrailingVisual,
|
|
420
|
-
key,
|
|
421
|
-
role,
|
|
422
|
-
...itemProps
|
|
423
|
-
} = item_2;
|
|
424
|
-
return /*#__PURE__*/jsxs(ActionList.Item, {
|
|
425
|
-
onSelect: () => onAction(item_2),
|
|
426
|
-
...itemProps,
|
|
427
|
-
id: id_0,
|
|
428
|
-
"data-id": id_0,
|
|
429
|
-
role: role,
|
|
430
|
-
children: [LeadingVisual && /*#__PURE__*/jsx(ActionList.LeadingVisual, {
|
|
431
|
-
children: isElement(LeadingVisual) ? LeadingVisual : /*#__PURE__*/jsx(LeadingVisual, {})
|
|
432
|
-
}), children !== null && children !== void 0 ? children : text, TrailingVisual && /*#__PURE__*/jsx(ActionList.TrailingVisual, {
|
|
433
|
-
children: isElement(TrailingVisual) ? TrailingVisual : /*#__PURE__*/jsx(TrailingVisual, {})
|
|
434
|
-
})]
|
|
435
|
-
}, key !== null && key !== void 0 ? key : id_0);
|
|
436
|
-
}
|
|
437
|
-
_temp5.displayName = "_temp5";
|
|
438
|
-
function _temp4(element) {
|
|
439
|
-
return !(element instanceof HTMLInputElement);
|
|
440
|
-
}
|
|
441
|
-
function _temp3() {
|
|
442
|
-
return /*#__PURE__*/jsx(PlusIcon, {});
|
|
443
|
-
}
|
|
444
|
-
_temp3.displayName = "_temp3";
|
|
445
|
-
function _temp2(acc, curr, i) {
|
|
446
|
-
acc[curr] = i;
|
|
447
|
-
return acc;
|
|
448
|
-
}
|
|
449
|
-
function _temp(t0) {
|
|
450
|
-
const {
|
|
451
|
-
id: itemId
|
|
452
|
-
} = t0;
|
|
453
|
-
return itemId;
|
|
246
|
+
})
|
|
247
|
+
});
|
|
454
248
|
}
|
|
249
|
+
AutocompleteMenu.displayName = "AutocompleteMenu";
|
|
455
250
|
AutocompleteMenu.displayName = 'AutocompleteMenu';
|
|
456
251
|
AutocompleteMenu.__SLOT__ = Symbol('Autocomplete.Menu');
|
|
457
252
|
|