@homecode/ui 4.20.2 → 4.20.3

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.
@@ -61,6 +61,7 @@ function Autocomplete(props) {
61
61
  const isMounted = useIsMounted();
62
62
  const [options, setOptions] = useState([]);
63
63
  const [isLoading, setIsLoading] = useState(false);
64
+ const isFocusedRef = useRef(false);
64
65
  const searchValRef = useRef(value);
65
66
  const [searchValue, _setSearchValue] = useState(value);
66
67
  const setSearchValue = (val) => {
@@ -72,6 +73,15 @@ function Autocomplete(props) {
72
73
  const inputRef = useRef(null);
73
74
  const isOpen = options.length > 0;
74
75
  const classes = cn(S.root, className);
76
+ const handleFocus = (e) => {
77
+ isFocusedRef.current = true;
78
+ fetchOptions(searchValue);
79
+ inputProps?.onFocus?.(e);
80
+ };
81
+ const handleBlur = (e) => {
82
+ isFocusedRef.current = false;
83
+ inputProps?.onBlur?.(e);
84
+ };
75
85
  const handleInputChange = (e, value) => {
76
86
  const val = (value || e?.target.value) ?? '';
77
87
  setOptions([]);
@@ -123,13 +133,10 @@ function Autocomplete(props) {
123
133
  }
124
134
  }, debounceDelay);
125
135
  useEffect(() => {
126
- if (value !== searchValRef.current) {
127
- if (isOpen)
128
- fetchOptions(value);
129
- }
130
- else {
131
- setSearchValue(value);
132
- }
136
+ setSearchValue(value);
137
+ setOptions([]);
138
+ if (isFocusedRef.current || isOpen)
139
+ fetchOptions(value);
133
140
  }, [value]);
134
141
  const optionsList = useMemo(() => {
135
142
  if (!options.length)
@@ -138,7 +145,7 @@ function Autocomplete(props) {
138
145
  }, [options, focusedIndex]);
139
146
  return (jsx(Popup, { className: classes, isOpen: isOpen, focusControl: true, size: size, direction: "bottom", ...popupProps, trigger: jsxs("div", { className: inputWrapperClassName, children: [jsx(Input, { ref: inputRef,
140
147
  // @ts-ignore
141
- size: size, ...inputProps, value: searchValue, onChange: handleInputChange, className: inputProps.className }), isLoading && (jsx(Shimmer, { className: S.shimmer, size: size, round: inputProps?.round }))] }), content: optionsList, contentProps: {
148
+ size: size, ...inputProps, value: searchValue, onChange: handleInputChange, onFocus: handleFocus, onBlur: handleBlur, className: inputProps.className }), isLoading && (jsx(Shimmer, { className: S.shimmer, size: size, round: inputProps?.round }))] }), content: optionsList, contentProps: {
142
149
  className: S.popupContent,
143
150
  } }));
144
151
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homecode/ui",
3
- "version": "4.20.2",
3
+ "version": "4.20.3",
4
4
  "description": "React UI components library",
5
5
  "scripts": {
6
6
  "test": "jest",