hi-tm 0.6.3 → 0.6.4
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.
|
@@ -112,7 +112,6 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
112
112
|
const anyOption = option;
|
|
113
113
|
const label = anyOption.label ?? anyOption.content ?? anyOption.value;
|
|
114
114
|
const result = String(label ?? '');
|
|
115
|
-
console.log('deriveLabel for option:', option, 'returning:', result);
|
|
116
115
|
return result;
|
|
117
116
|
}, [getOptionLabel]);
|
|
118
117
|
const deriveValue = (0, react_1.useCallback)((option) => {
|
|
@@ -121,7 +120,6 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
121
120
|
const anyOption = option;
|
|
122
121
|
const base = anyOption.value ?? anyOption.label ?? anyOption.content;
|
|
123
122
|
const str = String(base ?? deriveLabel(option));
|
|
124
|
-
console.log('deriveValue for option:', option, 'returning:', str);
|
|
125
123
|
return str;
|
|
126
124
|
}, [getOptionValue, deriveLabel]);
|
|
127
125
|
const [isOpen, setIsOpen] = (0, react_1.useState)(false);
|
|
@@ -134,20 +132,22 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
134
132
|
const [isUserInteracting, setIsUserInteracting] = (0, react_1.useState)(false);
|
|
135
133
|
const containerRef = (0, react_1.useRef)(null);
|
|
136
134
|
const inputRef = (0, react_1.useRef)(null);
|
|
135
|
+
const selectedValuesRef = (0, react_1.useRef)([]);
|
|
136
|
+
// Keep ref in sync with state
|
|
137
|
+
(0, react_1.useEffect)(() => {
|
|
138
|
+
selectedValuesRef.current = selectedValues;
|
|
139
|
+
}, [selectedValues]);
|
|
137
140
|
// Sync external value prop with internal selectedValues state
|
|
138
141
|
(0, react_1.useEffect)(() => {
|
|
139
142
|
// Don't sync if user is actively interacting with the component
|
|
140
143
|
if (isUserInteracting) {
|
|
141
|
-
console.log('Skipping sync - user is interacting');
|
|
142
144
|
return;
|
|
143
145
|
}
|
|
144
|
-
console.log('useEffect triggered with value:', value, 'isMultiSelect:', isMultiSelect);
|
|
145
146
|
// Only sync if the external value is actually different from current selectedValues
|
|
146
|
-
const currentValues =
|
|
147
|
+
const currentValues = selectedValuesRef.current;
|
|
147
148
|
const externalValue = value;
|
|
148
149
|
if (externalValue === null || externalValue === undefined) {
|
|
149
150
|
if (currentValues.length > 0) {
|
|
150
|
-
console.log('Setting selectedValues to empty array');
|
|
151
151
|
setSelectedValues([]);
|
|
152
152
|
}
|
|
153
153
|
}
|
|
@@ -156,14 +156,12 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
156
156
|
const externalArray = externalValue;
|
|
157
157
|
// Only update if the arrays are actually different
|
|
158
158
|
if (JSON.stringify(externalArray) !== JSON.stringify(currentValues)) {
|
|
159
|
-
console.log('Setting selectedValues to array:', externalArray);
|
|
160
159
|
setSelectedValues(externalArray);
|
|
161
160
|
}
|
|
162
161
|
}
|
|
163
162
|
else {
|
|
164
163
|
const firstItem = externalValue.length > 0 ? [externalValue[0]] : [];
|
|
165
164
|
if (JSON.stringify(firstItem) !== JSON.stringify(currentValues)) {
|
|
166
|
-
console.log('Setting selectedValues to first item of array:', firstItem);
|
|
167
165
|
setSelectedValues(firstItem);
|
|
168
166
|
}
|
|
169
167
|
}
|
|
@@ -171,11 +169,10 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
171
169
|
else {
|
|
172
170
|
const singleItem = [externalValue];
|
|
173
171
|
if (JSON.stringify(singleItem) !== JSON.stringify(currentValues)) {
|
|
174
|
-
console.log('Setting selectedValues to single item:', singleItem);
|
|
175
172
|
setSelectedValues(singleItem);
|
|
176
173
|
}
|
|
177
174
|
}
|
|
178
|
-
}, [value, isMultiSelect,
|
|
175
|
+
}, [value, isMultiSelect, isUserInteracting]);
|
|
179
176
|
// Sync options into filtered list when not searching
|
|
180
177
|
(0, react_1.useEffect)(() => {
|
|
181
178
|
if (!hasSearched) {
|
|
@@ -206,6 +203,8 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
206
203
|
setInputValue(next);
|
|
207
204
|
setIsOpen(true);
|
|
208
205
|
setIsUserInteracting(true);
|
|
206
|
+
// Reset the flag after a delay to allow for user interactions
|
|
207
|
+
setTimeout(() => setIsUserInteracting(false), 1000);
|
|
209
208
|
if (onChange)
|
|
210
209
|
onChange(e);
|
|
211
210
|
if (fetchOptions && next.trim() !== '') {
|