hi-tm 0.6.1 → 0.6.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.
|
@@ -131,30 +131,51 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
131
131
|
const [internalLoading, setInternalLoading] = (0, react_1.useState)(false);
|
|
132
132
|
const [hasSearched, setHasSearched] = (0, react_1.useState)(false);
|
|
133
133
|
const [selectedValues, setSelectedValues] = (0, react_1.useState)([]);
|
|
134
|
+
const [isUserInteracting, setIsUserInteracting] = (0, react_1.useState)(false);
|
|
134
135
|
const containerRef = (0, react_1.useRef)(null);
|
|
135
136
|
const inputRef = (0, react_1.useRef)(null);
|
|
136
137
|
// Sync external value prop with internal selectedValues state
|
|
137
138
|
(0, react_1.useEffect)(() => {
|
|
139
|
+
// Don't sync if user is actively interacting with the component
|
|
140
|
+
if (isUserInteracting) {
|
|
141
|
+
console.log('Skipping sync - user is interacting');
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
138
144
|
console.log('useEffect triggered with value:', value, 'isMultiSelect:', isMultiSelect);
|
|
139
|
-
if
|
|
140
|
-
|
|
141
|
-
|
|
145
|
+
// Only sync if the external value is actually different from current selectedValues
|
|
146
|
+
const currentValues = selectedValues;
|
|
147
|
+
const externalValue = value;
|
|
148
|
+
if (externalValue === null || externalValue === undefined) {
|
|
149
|
+
if (currentValues.length > 0) {
|
|
150
|
+
console.log('Setting selectedValues to empty array');
|
|
151
|
+
setSelectedValues([]);
|
|
152
|
+
}
|
|
142
153
|
}
|
|
143
|
-
else if (Array.isArray(
|
|
154
|
+
else if (Array.isArray(externalValue)) {
|
|
144
155
|
if (isMultiSelect) {
|
|
145
|
-
|
|
146
|
-
|
|
156
|
+
const externalArray = externalValue;
|
|
157
|
+
// Only update if the arrays are actually different
|
|
158
|
+
if (JSON.stringify(externalArray) !== JSON.stringify(currentValues)) {
|
|
159
|
+
console.log('Setting selectedValues to array:', externalArray);
|
|
160
|
+
setSelectedValues(externalArray);
|
|
161
|
+
}
|
|
147
162
|
}
|
|
148
163
|
else {
|
|
149
|
-
|
|
150
|
-
|
|
164
|
+
const firstItem = externalValue.length > 0 ? [externalValue[0]] : [];
|
|
165
|
+
if (JSON.stringify(firstItem) !== JSON.stringify(currentValues)) {
|
|
166
|
+
console.log('Setting selectedValues to first item of array:', firstItem);
|
|
167
|
+
setSelectedValues(firstItem);
|
|
168
|
+
}
|
|
151
169
|
}
|
|
152
170
|
}
|
|
153
171
|
else {
|
|
154
|
-
|
|
155
|
-
|
|
172
|
+
const singleItem = [externalValue];
|
|
173
|
+
if (JSON.stringify(singleItem) !== JSON.stringify(currentValues)) {
|
|
174
|
+
console.log('Setting selectedValues to single item:', singleItem);
|
|
175
|
+
setSelectedValues(singleItem);
|
|
176
|
+
}
|
|
156
177
|
}
|
|
157
|
-
}, [value, isMultiSelect]);
|
|
178
|
+
}, [value, isMultiSelect, selectedValues, isUserInteracting]);
|
|
158
179
|
// Sync options into filtered list when not searching
|
|
159
180
|
(0, react_1.useEffect)(() => {
|
|
160
181
|
if (!hasSearched) {
|
|
@@ -184,6 +205,7 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
184
205
|
const next = e.target.value;
|
|
185
206
|
setInputValue(next);
|
|
186
207
|
setIsOpen(true);
|
|
208
|
+
setIsUserInteracting(true);
|
|
187
209
|
if (onChange)
|
|
188
210
|
onChange(e);
|
|
189
211
|
if (fetchOptions && next.trim() !== '') {
|
|
@@ -308,15 +330,19 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
308
330
|
}
|
|
309
331
|
setSelectedValues(next);
|
|
310
332
|
emitSelection(next);
|
|
333
|
+
// In multi-select mode, keep the input open and clear input for next search
|
|
334
|
+
setInputValue('');
|
|
335
|
+
setHasSearched(false);
|
|
336
|
+
// Don't close dropdown in multi-select mode
|
|
311
337
|
}
|
|
312
338
|
else {
|
|
313
339
|
const next = [option];
|
|
314
340
|
setSelectedValues(next);
|
|
315
341
|
emitSelection(next);
|
|
342
|
+
setInputValue('');
|
|
343
|
+
setIsOpen(false);
|
|
344
|
+
setHasSearched(false);
|
|
316
345
|
}
|
|
317
|
-
setInputValue('');
|
|
318
|
-
setIsOpen(false);
|
|
319
|
-
setHasSearched(false);
|
|
320
346
|
}, [isMultiSelect, selectedValues, deriveValue, emitSelection]);
|
|
321
347
|
const showLoading = isLoading || internalLoading;
|
|
322
348
|
const handleAddIconClick = (0, react_1.useCallback)((e) => {
|
|
@@ -67,7 +67,7 @@ export type CreatableSelectProps<T = SelectOption> = {
|
|
|
67
67
|
label?: string;
|
|
68
68
|
iconSrc?: IconSourceProps;
|
|
69
69
|
fetchOptions?: (inputValue: string) => Promise<T[]>;
|
|
70
|
-
onAddClick
|
|
70
|
+
onAddClick?: (e: boolean) => void;
|
|
71
71
|
isMultiSelect?: boolean;
|
|
72
72
|
getOptionLabel?: OptionLabelGetter<T>;
|
|
73
73
|
getOptionValue?: OptionValueGetter<T>;
|