@homecode/ui 4.30.7 → 4.30.8
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.
|
@@ -86,6 +86,7 @@ function Autocomplete(props) {
|
|
|
86
86
|
const [isOpen, setIsOpen] = useState(props.isOpen);
|
|
87
87
|
const [isFocused, setIsFocused] = useState(isOpen);
|
|
88
88
|
const [selectedId, setSelectedId] = useState(null);
|
|
89
|
+
const [selectedLabel, setSelectedLabel] = useState(null);
|
|
89
90
|
const isFocusedRef = useRef(false);
|
|
90
91
|
const searchValRef = useRef(value);
|
|
91
92
|
const [searchValue, _setSearchValue] = useState(value);
|
|
@@ -96,11 +97,14 @@ function Autocomplete(props) {
|
|
|
96
97
|
const currentRequest = useRef('');
|
|
97
98
|
// @ts-ignore
|
|
98
99
|
const inputRef = useRef(null);
|
|
100
|
+
const inputDisplayValue = selectable && !isFocused && selectedLabel != null
|
|
101
|
+
? selectedLabel
|
|
102
|
+
: searchValue;
|
|
99
103
|
const displayItems = currentFilter
|
|
100
104
|
? filteredItems
|
|
101
105
|
: itemsWithoutFilter.length
|
|
102
106
|
? itemsWithoutFilter
|
|
103
|
-
: items ?? [];
|
|
107
|
+
: (items ?? []);
|
|
104
108
|
const displayCount = displayItems.length;
|
|
105
109
|
const hasMore = totalCount > 0 && displayCount < totalCount;
|
|
106
110
|
const classes = cn(S.root, className, popupProps.className);
|
|
@@ -137,6 +141,7 @@ function Autocomplete(props) {
|
|
|
137
141
|
const handleSelect = (option) => {
|
|
138
142
|
if (selectable) {
|
|
139
143
|
setSelectedId(option.id);
|
|
144
|
+
setSelectedLabel(option.label);
|
|
140
145
|
onSelect?.(option);
|
|
141
146
|
return;
|
|
142
147
|
}
|
|
@@ -268,6 +273,12 @@ function Autocomplete(props) {
|
|
|
268
273
|
fetchOptions(value, 0);
|
|
269
274
|
}
|
|
270
275
|
}, [value]);
|
|
276
|
+
useEffect(() => {
|
|
277
|
+
if (selectable && !value) {
|
|
278
|
+
setSelectedId(null);
|
|
279
|
+
setSelectedLabel(null);
|
|
280
|
+
}
|
|
281
|
+
}, [selectable, value]);
|
|
271
282
|
useEffect(() => {
|
|
272
283
|
if (!currentFilter && items?.length) {
|
|
273
284
|
setItemsWithoutFilter(items);
|
|
@@ -346,7 +357,7 @@ function Autocomplete(props) {
|
|
|
346
357
|
]);
|
|
347
358
|
return (jsx(Popup, { className: classes, isOpen: isOpen, focusControl: true, round: round, size: size, blur: blur, direction: "bottom", ...popupProps, trigger: jsx(Input, { ref: inputRef,
|
|
348
359
|
// @ts-ignore
|
|
349
|
-
size: size, round: round, ...inputProps, value:
|
|
360
|
+
size: size, round: round, ...inputProps, value: inputDisplayValue, onChange: handleInputChange, onFocus: handleFocus, onBlur: handleBlur, className: cn(inputProps.className, selectable && !isFocused && S.inputSelectableDisplay) }), content: optionsList, contentProps: {
|
|
350
361
|
...popupProps?.contentProps,
|
|
351
362
|
className: cn(S.popupContent, popupProps?.contentProps?.className),
|
|
352
363
|
} }));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import styleInject from '../../../node_modules/style-inject/dist/style-inject.es.js';
|
|
2
2
|
|
|
3
|
-
var css_248z = ".Autocomplete_root__86RQs{position:relative}.Autocomplete_popupContent__Aet6P{margin-top:8px;width:100%}.Autocomplete_scroll__bFG6f{height:200px}.Autocomplete_options__NtttU{max-height:200px;overflow-y:auto}.Autocomplete_option__uBuih{cursor:pointer;padding:8px 12px;position:absolute}.Autocomplete_option__uBuih>span{align-items:center;display:flex}.Autocomplete_loadingPlaceholder__Dn0dT{padding:8px 12px;text-align:center}.Autocomplete_shimmer__s6rri{height:100%;left:0;position:absolute;top:0;width:100%}";
|
|
4
|
-
var S = {"root":"Autocomplete_root__86RQs","popupContent":"Autocomplete_popupContent__Aet6P","scroll":"Autocomplete_scroll__bFG6f","options":"Autocomplete_options__NtttU","option":"Autocomplete_option__uBuih","loadingPlaceholder":"Autocomplete_loadingPlaceholder__Dn0dT","shimmer":"Autocomplete_shimmer__s6rri"};
|
|
3
|
+
var css_248z = ".Autocomplete_root__86RQs{position:relative}.Autocomplete_inputSelectableDisplay__rgFwu{overflow:hidden;text-overflow:ellipsis}.Autocomplete_popupContent__Aet6P{margin-top:8px;width:100%}.Autocomplete_scroll__bFG6f{height:200px}.Autocomplete_options__NtttU{max-height:200px;overflow-y:auto}.Autocomplete_option__uBuih{cursor:pointer;padding:8px 12px;position:absolute}.Autocomplete_option__uBuih>span{align-items:center;display:flex}.Autocomplete_loadingPlaceholder__Dn0dT{padding:8px 12px;text-align:center}.Autocomplete_shimmer__s6rri{height:100%;left:0;position:absolute;top:0;width:100%}";
|
|
4
|
+
var S = {"root":"Autocomplete_root__86RQs","inputSelectableDisplay":"Autocomplete_inputSelectableDisplay__rgFwu","popupContent":"Autocomplete_popupContent__Aet6P","scroll":"Autocomplete_scroll__bFG6f","options":"Autocomplete_options__NtttU","option":"Autocomplete_option__uBuih","loadingPlaceholder":"Autocomplete_loadingPlaceholder__Dn0dT","shimmer":"Autocomplete_shimmer__s6rri"};
|
|
5
5
|
styleInject(css_248z);
|
|
6
6
|
|
|
7
7
|
export { S as default };
|