@homecode/ui 5.3.0 → 5.3.1
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.
|
@@ -167,6 +167,8 @@ function Autocomplete(props) {
|
|
|
167
167
|
return true;
|
|
168
168
|
};
|
|
169
169
|
const handleSelect = (option) => {
|
|
170
|
+
if (!option)
|
|
171
|
+
return;
|
|
170
172
|
if (selectable) {
|
|
171
173
|
setSelectedId(option.id);
|
|
172
174
|
setSelectedLabel(option.label);
|
|
@@ -196,7 +198,12 @@ function Autocomplete(props) {
|
|
|
196
198
|
const { focusedIndex, setFocusedIndex } = useListKeyboardControl({
|
|
197
199
|
isActive: isPopupOpenForInput,
|
|
198
200
|
itemsCount: displayItems.length,
|
|
199
|
-
onSelect: index =>
|
|
201
|
+
onSelect: index => {
|
|
202
|
+
const option = displayItems[index];
|
|
203
|
+
if (!option)
|
|
204
|
+
return;
|
|
205
|
+
handleSelect(option);
|
|
206
|
+
},
|
|
200
207
|
});
|
|
201
208
|
const fetchOptionsCore = useCallback(async (filter, offset) => {
|
|
202
209
|
const requestKey = `${filter}:${offset}`;
|
|
@@ -26,7 +26,11 @@ const useListKeyboardControl = ({ isActive, itemsCount, onSelect, }) => {
|
|
|
26
26
|
return;
|
|
27
27
|
}
|
|
28
28
|
if (e.key === 'Enter') {
|
|
29
|
-
|
|
29
|
+
if (newIndex < 0 || newIndex >= itemsCount)
|
|
30
|
+
return;
|
|
31
|
+
e.preventDefault();
|
|
32
|
+
e.stopPropagation();
|
|
33
|
+
onSelect?.(newIndex);
|
|
30
34
|
return;
|
|
31
35
|
}
|
|
32
36
|
}, [focusedIndex, itemsCount, onSelect]);
|
|
@@ -37,10 +41,14 @@ const useListKeyboardControl = ({ isActive, itemsCount, onSelect, }) => {
|
|
|
37
41
|
isActive,
|
|
38
42
|
});
|
|
39
43
|
useEffect(() => {
|
|
40
|
-
if (itemsCount
|
|
44
|
+
if (itemsCount <= 0) {
|
|
45
|
+
setFocusedIndex(-1);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (focusedIndex >= itemsCount) {
|
|
41
49
|
setFocusedIndex(itemsCount - 1);
|
|
42
50
|
}
|
|
43
|
-
}, [itemsCount]);
|
|
51
|
+
}, [itemsCount, focusedIndex]);
|
|
44
52
|
return {
|
|
45
53
|
focusedIndex,
|
|
46
54
|
setFocusedIndex,
|