hi-tm 0.6.9 → 0.7.1
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.
|
@@ -137,6 +137,8 @@ exports.default = react_1.default.memo(function CreatableSelect({ options = [],
|
|
|
137
137
|
const scrollContainerRef = (0, react_1.useRef)(null);
|
|
138
138
|
// Prevent scroll jumping by maintaining position during keyboard navigation
|
|
139
139
|
const handleKeyboardNavigation = (0, react_1.useCallback)((direction) => {
|
|
140
|
+
// Set user interaction flag to prevent external sync
|
|
141
|
+
setIsUserInteracting(true);
|
|
140
142
|
// Don't save scroll position - just update the highlighted index
|
|
141
143
|
if (direction === 'up') {
|
|
142
144
|
highlightedIndexRef.current = Math.max(0, highlightedIndexRef.current - 1);
|
|
@@ -146,15 +148,24 @@ exports.default = react_1.default.memo(function CreatableSelect({ options = [],
|
|
|
146
148
|
}
|
|
147
149
|
// Force re-render of dropdown options only
|
|
148
150
|
setForceUpdate((prev) => prev + 1);
|
|
151
|
+
// Reset the flag after a delay
|
|
152
|
+
setTimeout(() => {
|
|
153
|
+
setIsUserInteracting(false);
|
|
154
|
+
}, 1000);
|
|
149
155
|
}, [filteredOptions.length]);
|
|
150
156
|
// Sync external value prop with internal selectedValues state
|
|
151
157
|
(0, react_1.useEffect)(() => {
|
|
158
|
+
console.log('=== useEffect sync triggered ===');
|
|
159
|
+
console.log('isUserInteracting:', isUserInteracting);
|
|
160
|
+
console.log('external value:', value);
|
|
161
|
+
console.log('current selectedValues:', selectedValues);
|
|
162
|
+
console.log('isMultiSelect:', isMultiSelect);
|
|
152
163
|
// Don't sync if user is actively interacting with the component
|
|
153
164
|
if (isUserInteracting) {
|
|
154
165
|
console.log('Skipping sync - user is interacting');
|
|
155
166
|
return;
|
|
156
167
|
}
|
|
157
|
-
console.log('
|
|
168
|
+
console.log('Proceeding with sync...');
|
|
158
169
|
// Only sync if the external value is actually different from current selectedValues
|
|
159
170
|
const currentValues = selectedValues;
|
|
160
171
|
const externalValue = value;
|
|
@@ -188,7 +199,8 @@ exports.default = react_1.default.memo(function CreatableSelect({ options = [],
|
|
|
188
199
|
setSelectedValues(singleItem);
|
|
189
200
|
}
|
|
190
201
|
}
|
|
191
|
-
|
|
202
|
+
console.log('=== useEffect sync completed ===');
|
|
203
|
+
}, [value, isMultiSelect, isUserInteracting]);
|
|
192
204
|
// Sync options into filtered list when not searching
|
|
193
205
|
(0, react_1.useEffect)(() => {
|
|
194
206
|
if (!hasSearched) {
|
|
@@ -202,6 +214,12 @@ exports.default = react_1.default.memo(function CreatableSelect({ options = [],
|
|
|
202
214
|
setHasSearched(false);
|
|
203
215
|
}
|
|
204
216
|
}, [options, inputValue]);
|
|
217
|
+
// Debug: Log when selectedValues changes
|
|
218
|
+
(0, react_1.useEffect)(() => {
|
|
219
|
+
console.log('=== selectedValues changed ===');
|
|
220
|
+
console.log('New selectedValues:', selectedValues);
|
|
221
|
+
console.log('Stack trace:', new Error().stack);
|
|
222
|
+
}, [selectedValues]);
|
|
205
223
|
// Close on outside click
|
|
206
224
|
(0, react_1.useEffect)(() => {
|
|
207
225
|
const handler = (e) => {
|
|
@@ -246,8 +264,15 @@ exports.default = react_1.default.memo(function CreatableSelect({ options = [],
|
|
|
246
264
|
}
|
|
247
265
|
}, [onChange, fetchOptions, options, deriveLabel]);
|
|
248
266
|
const handleKeyDown = (0, react_1.useCallback)((e) => {
|
|
267
|
+
console.log('=== handleKeyDown called ===');
|
|
268
|
+
console.log('key:', e.key);
|
|
269
|
+
console.log('isDisabled:', isDisabled);
|
|
270
|
+
console.log('current selectedValues:', selectedValues);
|
|
249
271
|
if (isDisabled)
|
|
250
272
|
return;
|
|
273
|
+
// Set user interaction flag for all keyboard events
|
|
274
|
+
console.log('Setting isUserInteracting to true');
|
|
275
|
+
setIsUserInteracting(true);
|
|
251
276
|
switch (e.key) {
|
|
252
277
|
case 'Enter':
|
|
253
278
|
e.preventDefault();
|
|
@@ -289,6 +314,11 @@ exports.default = react_1.default.memo(function CreatableSelect({ options = [],
|
|
|
289
314
|
}
|
|
290
315
|
break;
|
|
291
316
|
}
|
|
317
|
+
// Reset the flag after a delay
|
|
318
|
+
setTimeout(() => {
|
|
319
|
+
console.log('Resetting isUserInteracting to false');
|
|
320
|
+
setIsUserInteracting(false);
|
|
321
|
+
}, 1000);
|
|
292
322
|
}, [
|
|
293
323
|
isDisabled,
|
|
294
324
|
isOpen,
|
|
@@ -297,6 +327,7 @@ exports.default = react_1.default.memo(function CreatableSelect({ options = [],
|
|
|
297
327
|
deriveLabel,
|
|
298
328
|
handleKeyboardNavigation,
|
|
299
329
|
isCreatable,
|
|
330
|
+
selectedValues,
|
|
300
331
|
]);
|
|
301
332
|
const emitSelection = (0, react_1.useCallback)((next) => {
|
|
302
333
|
// Backward-compatible callback
|
|
@@ -331,13 +362,24 @@ exports.default = react_1.default.memo(function CreatableSelect({ options = [],
|
|
|
331
362
|
}
|
|
332
363
|
}, [inputValue, isCreatable, onCreateOption]);
|
|
333
364
|
const toggleDropdown = (0, react_1.useCallback)(() => {
|
|
365
|
+
console.log('=== toggleDropdown called ===');
|
|
366
|
+
console.log('isDisabled:', isDisabled);
|
|
367
|
+
console.log('current isOpen:', isOpen);
|
|
368
|
+
console.log('current selectedValues:', selectedValues);
|
|
334
369
|
if (!isDisabled) {
|
|
370
|
+
console.log('Setting isUserInteracting to true');
|
|
371
|
+
setIsUserInteracting(true);
|
|
335
372
|
setIsOpen((prev) => !prev);
|
|
336
373
|
if (!isOpen && inputRef.current) {
|
|
337
374
|
inputRef.current.focus();
|
|
338
375
|
}
|
|
376
|
+
// Reset the flag after a delay
|
|
377
|
+
setTimeout(() => {
|
|
378
|
+
console.log('Resetting isUserInteracting to false');
|
|
379
|
+
setIsUserInteracting(false);
|
|
380
|
+
}, 1000);
|
|
339
381
|
}
|
|
340
|
-
}, [isDisabled, isOpen]);
|
|
382
|
+
}, [isDisabled, isOpen, selectedValues]);
|
|
341
383
|
const clearValue = (0, react_1.useCallback)((e, option) => {
|
|
342
384
|
e.stopPropagation();
|
|
343
385
|
const next = selectedValues.filter((val) => deriveValue(val) !== deriveValue(option));
|
|
@@ -345,6 +387,8 @@ exports.default = react_1.default.memo(function CreatableSelect({ options = [],
|
|
|
345
387
|
emitSelection(next);
|
|
346
388
|
}, [selectedValues, deriveValue, emitSelection]);
|
|
347
389
|
const selectOption = (0, react_1.useCallback)((option) => {
|
|
390
|
+
// Set user interaction flag to prevent external sync
|
|
391
|
+
setIsUserInteracting(true);
|
|
348
392
|
if (isMultiSelect) {
|
|
349
393
|
const next = [...selectedValues];
|
|
350
394
|
if (!next.some((val) => deriveValue(val) === deriveValue(option))) {
|
|
@@ -365,6 +409,10 @@ exports.default = react_1.default.memo(function CreatableSelect({ options = [],
|
|
|
365
409
|
setIsOpen(false);
|
|
366
410
|
setHasSearched(false);
|
|
367
411
|
}
|
|
412
|
+
// Reset the flag after a delay
|
|
413
|
+
setTimeout(() => {
|
|
414
|
+
setIsUserInteracting(false);
|
|
415
|
+
}, 1000);
|
|
368
416
|
}, [isMultiSelect, selectedValues, deriveValue, emitSelection]);
|
|
369
417
|
const showLoading = isLoading || internalLoading;
|
|
370
418
|
const handleAddIconClick = (0, react_1.useCallback)((e) => {
|