@homecode/ui 4.30.14 → 4.30.16
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.
|
@@ -109,6 +109,7 @@ function Autocomplete(props) {
|
|
|
109
109
|
const displayCount = displayItems.length;
|
|
110
110
|
const hasMore = totalCount > 0 && displayCount < totalCount;
|
|
111
111
|
const classes = cn(S.root, className, popupProps.className);
|
|
112
|
+
const mergedPopupIsOpen = isOpen !== undefined ? isOpen : popupProps?.isOpen;
|
|
112
113
|
const handleFocus = (e) => {
|
|
113
114
|
isFocusedRef.current = true;
|
|
114
115
|
setIsFocused(true);
|
|
@@ -162,17 +163,21 @@ function Autocomplete(props) {
|
|
|
162
163
|
setTotalCount(0);
|
|
163
164
|
fetchOptionsCore(option.label, 0);
|
|
164
165
|
onSelect?.(option);
|
|
165
|
-
//
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
166
|
+
// Uncontrolled only: refocusing fires input onFocus; with controlled isOpen that often reopens
|
|
167
|
+
// the popup right after onSelect closed it (see ControllablePopup pattern).
|
|
168
|
+
if (isOpen === undefined) {
|
|
169
|
+
requestAnimationFrame(() => {
|
|
170
|
+
const input = inputRef.current;
|
|
171
|
+
if (!input)
|
|
172
|
+
return;
|
|
173
|
+
input.focus();
|
|
174
|
+
input.setSelectionRange(option.label.length, option.label.length);
|
|
175
|
+
});
|
|
176
|
+
}
|
|
173
177
|
};
|
|
178
|
+
const isPopupOpenForInput = isOpen !== undefined ? isOpen : isFocused;
|
|
174
179
|
const { focusedIndex, setFocusedIndex } = useListKeyboardControl({
|
|
175
|
-
isActive:
|
|
180
|
+
isActive: isPopupOpenForInput,
|
|
176
181
|
itemsCount: displayItems.length,
|
|
177
182
|
onSelect: index => handleSelect(displayItems[index]),
|
|
178
183
|
});
|
|
@@ -347,7 +352,7 @@ function Autocomplete(props) {
|
|
|
347
352
|
if (props.renderItem) {
|
|
348
353
|
return props.renderItem(itemPropsForRender);
|
|
349
354
|
}
|
|
350
|
-
return (jsx(Menu.Item, { ...itemProps, focused: itemPropsForRender.focused, selected: itemPropsForRender.isSelected, className: itemPropsForRender.className, onClick: itemPropsForRender.onClick, onMouseEnter: itemPropsForRender.onMouseEnter, style:
|
|
355
|
+
return (jsx(Menu.Item, { ...itemProps, focused: itemPropsForRender.focused, selected: itemPropsForRender.isSelected, className: itemPropsForRender.className, onClick: itemPropsForRender.onClick, onMouseEnter: itemPropsForRender.onMouseEnter, style: { ...itemProps.style, height: itemHeight }, children: option.render ? option.render(option) : option.label }));
|
|
351
356
|
}, [
|
|
352
357
|
displayItems,
|
|
353
358
|
focusedIndex,
|
|
@@ -356,6 +361,7 @@ function Autocomplete(props) {
|
|
|
356
361
|
handleSelect,
|
|
357
362
|
setFocusedIndex,
|
|
358
363
|
props.renderItem,
|
|
364
|
+
itemHeight,
|
|
359
365
|
]);
|
|
360
366
|
const LoadingPlaceholder = loadingPlaceholder ?? (jsxs("div", { className: S.loadingPlaceholder, children: [isLoadingMore && jsx(Shimmer, { size: size, round: round }), "Loading..."] }));
|
|
361
367
|
const optionsList = useMemo(() => {
|
|
@@ -401,7 +407,7 @@ function Autocomplete(props) {
|
|
|
401
407
|
scrollToSelected,
|
|
402
408
|
LoadingPlaceholder,
|
|
403
409
|
]);
|
|
404
|
-
return (jsx(Popup, { className: classes,
|
|
410
|
+
return (jsx(Popup, { className: classes, focusControl: true, round: round, size: size, blur: blur, direction: "bottom", ...popupProps, isOpen: mergedPopupIsOpen, trigger: jsx(Input, { ref: inputRef,
|
|
405
411
|
// @ts-ignore
|
|
406
412
|
size: size, round: round, ...inputProps, value: inputDisplayValue, onChange: handleInputChange, onFocus: handleFocus, onBlur: handleBlur, className: cn(inputProps.className, selectable && !isFocused && S.inputSelectableDisplay) }), content: optionsList, contentProps: {
|
|
407
413
|
...popupProps?.contentProps,
|
|
@@ -208,9 +208,7 @@ function Select2(props) {
|
|
|
208
208
|
const { label, className, ...rest } = triggerProps;
|
|
209
209
|
const props = omit(rest, ['name', 'inputProps']);
|
|
210
210
|
isMultiple$1 && value && value.length > 0;
|
|
211
|
-
const fullSelectedLabel = [
|
|
212
|
-
// ?
|
|
213
|
-
// : [selectedLabel, label, additionalLabel].filter(Boolean);
|
|
211
|
+
const fullSelectedLabel = [selectedLabel, additionalLabel].filter(Boolean);
|
|
214
212
|
const hasSelected = fullSelectedLabel.length > 0;
|
|
215
213
|
const displayLabel = hasSelected ? fullSelectedLabel : label;
|
|
216
214
|
const title = hasSelected && !isMultiple$1 ? fullSelectedLabel : null;
|