hi-tm 0.6.7 → 0.6.8

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.
@@ -127,11 +127,12 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
127
127
  const [isOpen, setIsOpen] = (0, react_1.useState)(false);
128
128
  const [inputValue, setInputValue] = (0, react_1.useState)('');
129
129
  const [filteredOptions, setFilteredOptions] = (0, react_1.useState)(options ?? []);
130
- const [highlightedIndex, setHighlightedIndex] = (0, react_1.useState)(0);
130
+ const highlightedIndexRef = (0, react_1.useRef)(0);
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
134
  const [isUserInteracting, setIsUserInteracting] = (0, react_1.useState)(false);
135
+ const [forceUpdate, setForceUpdate] = (0, react_1.useState)(0);
135
136
  const containerRef = (0, react_1.useRef)(null);
136
137
  const inputRef = (0, react_1.useRef)(null);
137
138
  const scrollContainerRef = (0, react_1.useRef)(null);
@@ -155,11 +156,13 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
155
156
  const handleKeyboardNavigation = (0, react_1.useCallback)((direction) => {
156
157
  saveScrollPosition();
157
158
  if (direction === 'up') {
158
- setHighlightedIndex((prev) => (prev > 0 ? prev - 1 : filteredOptions.length - 1));
159
+ highlightedIndexRef.current = Math.max(0, highlightedIndexRef.current - 1);
159
160
  }
160
161
  else {
161
- setHighlightedIndex((prev) => (prev < filteredOptions.length - 1 ? prev + 1 : 0));
162
+ highlightedIndexRef.current = Math.min(filteredOptions.length - 1, highlightedIndexRef.current + 1);
162
163
  }
164
+ // Force re-render of dropdown options only
165
+ setForceUpdate((prev) => prev + 1);
163
166
  // Restore scroll position after state update
164
167
  requestAnimationFrame(() => {
165
168
  restoreScrollPosition();
@@ -213,13 +216,13 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
213
216
  setFilteredOptions(options ?? []);
214
217
  }
215
218
  }, [options, hasSearched]);
216
- // Restore scroll position after highlightedIndex changes
219
+ // Restore scroll position after filteredOptions changes
217
220
  (0, react_1.useEffect)(() => {
218
221
  // Use requestAnimationFrame to ensure DOM has updated
219
222
  requestAnimationFrame(() => {
220
223
  restoreScrollPosition();
221
224
  });
222
- }, [highlightedIndex, restoreScrollPosition]);
225
+ }, [filteredOptions, restoreScrollPosition]);
223
226
  // Reset filtered list when input cleared
224
227
  (0, react_1.useEffect)(() => {
225
228
  if (inputValue === '') {
@@ -277,8 +280,9 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
277
280
  case 'Enter':
278
281
  e.preventDefault();
279
282
  if (isOpen) {
280
- if (filteredOptions.length > 0 && highlightedIndex < filteredOptions.length) {
281
- selectOption(filteredOptions[highlightedIndex]);
283
+ if (filteredOptions.length > 0 &&
284
+ highlightedIndexRef.current < filteredOptions.length) {
285
+ selectOption(filteredOptions[highlightedIndexRef.current]);
282
286
  }
283
287
  else if (isCreatable &&
284
288
  inputValue &&
@@ -317,11 +321,10 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
317
321
  isDisabled,
318
322
  isOpen,
319
323
  filteredOptions,
320
- highlightedIndex,
321
- isCreatable,
322
324
  inputValue,
323
325
  deriveLabel,
324
326
  handleKeyboardNavigation,
327
+ isCreatable,
325
328
  ]);
326
329
  const emitSelection = (0, react_1.useCallback)((next) => {
327
330
  // Backward-compatible callback
@@ -398,16 +401,30 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
398
401
  onAddClick(true);
399
402
  }
400
403
  }, [onAddClick]);
404
+ const scrollContainer = (0, react_1.useMemo)(() => (react_1.default.createElement("div", { ref: scrollContainerRef, className: "flex-grow flex items-center overflow-x-auto creatable-dropdown-scroll", key: "scroll-container-stable" },
405
+ react_1.default.createElement("div", { className: "flex items-center gap-2 flex-nowrap" },
406
+ selectedValues.length > 0 &&
407
+ selectedValues.map((val) => (react_1.default.createElement("div", { key: deriveValue(val), className: "flex-shrink-0 flex items-center bg-gray-200 rounded-md px-2 py-1" },
408
+ react_1.default.createElement("span", { className: "truncate" }, deriveLabel(val)),
409
+ react_1.default.createElement("button", { onClick: (e) => clearValue(e, val), className: styles.clearButton }, renderIcon(icons.clear, styles.icon))))),
410
+ react_1.default.createElement("input", { ref: inputRef, type: "text", className: `${styles.input} ${isDisabled ? 'bg-gray-100' : ''} min-w-[80px] flex-shrink-0`, placeholder: selectedValues.length > 0 ? '' : placeholder, value: inputValue, onChange: handleInputChange, disabled: isDisabled, onClick: (e) => e.stopPropagation() })))), [
411
+ selectedValues,
412
+ isDisabled,
413
+ inputValue,
414
+ inputRef,
415
+ clearValue,
416
+ deriveValue,
417
+ deriveLabel,
418
+ icons.clear,
419
+ styles.input,
420
+ styles.clearButton,
421
+ placeholder,
422
+ handleInputChange,
423
+ ]);
401
424
  return (react_1.default.createElement("div", { ref: containerRef, className: `relative w-full ${className} ${styles.container}`, onKeyDown: handleKeyDown },
402
425
  label && react_1.default.createElement("label", { className: "block text-sm font-medium text-gray-700 mb-1" }, label),
403
426
  react_1.default.createElement("div", { className: `${styles.trigger} ${isDisabled ? 'bg-gray-100 cursor-not-allowed' : ''} ${isOpen ? 'border-blue-500 ring-2 ring-blue-100' : 'border-gray-300'}`, onClick: toggleDropdown },
404
- react_1.default.createElement("div", { ref: scrollContainerRef, className: "flex-grow flex items-center overflow-x-auto creatable-dropdown-scroll" },
405
- react_1.default.createElement("div", { className: "flex items-center gap-2 flex-nowrap" },
406
- selectedValues.length > 0 &&
407
- selectedValues.map((val) => (react_1.default.createElement("div", { key: deriveValue(val), className: "flex-shrink-0 flex items-center bg-gray-200 rounded-md px-2 py-1" },
408
- react_1.default.createElement("span", { className: "truncate" }, deriveLabel(val)),
409
- react_1.default.createElement("button", { onClick: (e) => clearValue(e, val), className: styles.clearButton }, renderIcon(icons.clear, styles.icon))))),
410
- react_1.default.createElement("input", { ref: inputRef, type: "text", className: `${styles.input} ${isDisabled ? 'bg-gray-100' : ''} min-w-[80px] flex-shrink-0`, placeholder: selectedValues.length > 0 ? '' : placeholder, value: inputValue, onChange: handleInputChange, disabled: isDisabled, onClick: (e) => e.stopPropagation() }))),
427
+ scrollContainer,
411
428
  react_1.default.createElement("div", { className: "flex-shrink-0 flex items-center gap-1 ml-2" },
412
429
  iconSrc.hasAdd && (react_1.default.createElement("button", { onClick: handleAddIconClick, className: styles.clearButton }, renderIcon(iconSrc.hasAdd, styles.icon))),
413
430
  styles.separator && react_1.default.createElement("div", { className: styles.separator }),
@@ -417,7 +434,9 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
417
434
  isOpen && (react_1.default.createElement("div", { className: styles.dropdown }, showLoading ? (react_1.default.createElement("div", { className: styles.loadingState },
418
435
  renderIcon(iconSrc.loading, `animate-spin mr-2 ${styles.icon}`),
419
436
  loadingMessage)) : (react_1.default.createElement(react_1.default.Fragment, null,
420
- filteredOptions.length > 0 && (react_1.default.createElement(react_1.default.Fragment, null, filteredOptions.map((option, index) => (react_1.default.createElement("div", { key: deriveValue(option), className: `${styles.option} ${index === highlightedIndex ? styles.highlightedOption : 'hover:bg-gray-50'}`, onClick: () => selectOption(option), onMouseEnter: () => setHighlightedIndex(index) },
437
+ filteredOptions.length > 0 && (react_1.default.createElement(react_1.default.Fragment, null, filteredOptions.map((option, index) => (react_1.default.createElement("div", { key: `${deriveValue(option)}-${forceUpdate}`, className: `${styles.option} ${index === highlightedIndexRef.current
438
+ ? styles.highlightedOption
439
+ : 'hover:bg-gray-50'}`, onClick: () => selectOption(option), onMouseEnter: () => (highlightedIndexRef.current = index) },
421
440
  selectedValues.some((val) => deriveValue(val) === deriveValue(option)) &&
422
441
  renderIcon(iconSrc.checkmark, 'w-4 h-4 mr-2 text-blue-500'),
423
442
  react_1.default.createElement("span", { className: selectedValues.some((val) => deriveValue(val) === deriveValue(option))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hi-tm",
3
- "version": "0.6.7",
3
+ "version": "0.6.8",
4
4
  "styles": "dist/styles/globals.css",
5
5
  "main": "dist/index.js",
6
6
  "exports": {