@via-profit/ui-kit 0.1.0-rc.95 → 0.1.0-rc.97
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.
|
@@ -173,9 +173,13 @@ const Autocomplete = react_1.default.forwardRef((props, ref) => {
|
|
|
173
173
|
react_1.default.useEffect(() => {
|
|
174
174
|
if (JSON.stringify(items) !== JSON.stringify(itemsRef.current)) {
|
|
175
175
|
itemsRef.current = items;
|
|
176
|
-
|
|
176
|
+
const newFilteredItems = applyFilterForItems(inputValue, items);
|
|
177
|
+
dispatch((0, context_1.actionSetPartial)({ filteredItems: newFilteredItems }));
|
|
178
|
+
if (!newFilteredItems.length) {
|
|
179
|
+
onRequestClose();
|
|
180
|
+
}
|
|
177
181
|
}
|
|
178
|
-
}, [items, inputValue, applyFilterForItems, dispatch]);
|
|
182
|
+
}, [items, inputValue, applyFilterForItems, dispatch, onRequestClose]);
|
|
179
183
|
react_1.default.useEffect(() => {
|
|
180
184
|
const mouseDownEvent = (event) => {
|
|
181
185
|
var _a;
|
|
@@ -194,8 +198,11 @@ const Autocomplete = react_1.default.forwardRef((props, ref) => {
|
|
|
194
198
|
const newInputValue = currentValue === null
|
|
195
199
|
? ''
|
|
196
200
|
: selectedItemToString(currentValue);
|
|
201
|
+
const newFilteredItems = multiple
|
|
202
|
+
? filteredItems
|
|
203
|
+
: applyFilterForItems(newInputValue, items);
|
|
197
204
|
dispatch((0, context_1.actionSetPartial)({
|
|
198
|
-
filteredItems:
|
|
205
|
+
filteredItems: newFilteredItems,
|
|
199
206
|
inputValue: newInputValue,
|
|
200
207
|
}));
|
|
201
208
|
}
|
|
@@ -249,7 +256,11 @@ const Autocomplete = react_1.default.forwardRef((props, ref) => {
|
|
|
249
256
|
}
|
|
250
257
|
}, onFocus: event => {
|
|
251
258
|
isFocusedRef.current = true;
|
|
252
|
-
if (openOnFocus &&
|
|
259
|
+
if (openOnFocus &&
|
|
260
|
+
!currentOpen &&
|
|
261
|
+
filteredItems.length > 0
|
|
262
|
+
// && inputValue.trim() !== ''
|
|
263
|
+
) {
|
|
253
264
|
onRequestOpen(event);
|
|
254
265
|
}
|
|
255
266
|
if (!openOnFocus && !currentOpen && inputValue !== '' && filteredItems.length > 0) {
|
|
@@ -262,7 +273,11 @@ const Autocomplete = react_1.default.forwardRef((props, ref) => {
|
|
|
262
273
|
if (typeof nativeInputProps.onClick === 'function') {
|
|
263
274
|
nativeInputProps.onClick(event);
|
|
264
275
|
}
|
|
265
|
-
if (isFocusedRef.current &&
|
|
276
|
+
if (isFocusedRef.current &&
|
|
277
|
+
!currentOpen &&
|
|
278
|
+
filteredItems.length > 0
|
|
279
|
+
// && inputValue.trim() !== ''
|
|
280
|
+
) {
|
|
266
281
|
onRequestOpen(event);
|
|
267
282
|
}
|
|
268
283
|
}, onChange: event => {
|
|
@@ -278,14 +293,22 @@ const Autocomplete = react_1.default.forwardRef((props, ref) => {
|
|
|
278
293
|
onRequestOpen(event);
|
|
279
294
|
}
|
|
280
295
|
// console.debug('set filteredItems');
|
|
296
|
+
const newFilteredItems = applyFilterForItems(event.currentTarget.value, items);
|
|
297
|
+
if (newFilteredItems.length === 0 && currentOpen) {
|
|
298
|
+
onRequestClose();
|
|
299
|
+
}
|
|
300
|
+
if (newFilteredItems.length > 0 && !currentOpen) {
|
|
301
|
+
onRequestOpen(event);
|
|
302
|
+
}
|
|
281
303
|
dispatch((0, context_1.actionSetPartial)({
|
|
282
|
-
filteredItems:
|
|
304
|
+
filteredItems: newFilteredItems,
|
|
283
305
|
inputValue: event.currentTarget.value,
|
|
284
306
|
}));
|
|
285
307
|
} }))), [
|
|
286
308
|
overridesMap,
|
|
287
309
|
placeholder,
|
|
288
310
|
label,
|
|
311
|
+
onRequestClose,
|
|
289
312
|
error,
|
|
290
313
|
requiredAsterisk,
|
|
291
314
|
errorText,
|