hi-tm 0.6.6 → 0.6.7

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.
@@ -134,6 +134,37 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
134
134
  const [isUserInteracting, setIsUserInteracting] = (0, react_1.useState)(false);
135
135
  const containerRef = (0, react_1.useRef)(null);
136
136
  const inputRef = (0, react_1.useRef)(null);
137
+ const scrollContainerRef = (0, react_1.useRef)(null);
138
+ const scrollPositionRef = (0, react_1.useRef)(0);
139
+ // Save scroll position before re-renders
140
+ const saveScrollPosition = (0, react_1.useCallback)(() => {
141
+ if (scrollContainerRef.current) {
142
+ scrollPositionRef.current = scrollContainerRef.current.scrollLeft;
143
+ }
144
+ }, []);
145
+ // Restore scroll position after re-renders
146
+ const restoreScrollPosition = (0, react_1.useCallback)(() => {
147
+ if (scrollContainerRef.current && scrollPositionRef.current > 0) {
148
+ // Only restore if the position has actually changed
149
+ if (scrollContainerRef.current.scrollLeft !== scrollPositionRef.current) {
150
+ scrollContainerRef.current.scrollLeft = scrollPositionRef.current;
151
+ }
152
+ }
153
+ }, []);
154
+ // Prevent scroll jumping by maintaining position during keyboard navigation
155
+ const handleKeyboardNavigation = (0, react_1.useCallback)((direction) => {
156
+ saveScrollPosition();
157
+ if (direction === 'up') {
158
+ setHighlightedIndex((prev) => (prev > 0 ? prev - 1 : filteredOptions.length - 1));
159
+ }
160
+ else {
161
+ setHighlightedIndex((prev) => (prev < filteredOptions.length - 1 ? prev + 1 : 0));
162
+ }
163
+ // Restore scroll position after state update
164
+ requestAnimationFrame(() => {
165
+ restoreScrollPosition();
166
+ });
167
+ }, [filteredOptions.length, saveScrollPosition, restoreScrollPosition]);
137
168
  // Sync external value prop with internal selectedValues state
138
169
  (0, react_1.useEffect)(() => {
139
170
  // Don't sync if user is actively interacting with the component
@@ -182,6 +213,13 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
182
213
  setFilteredOptions(options ?? []);
183
214
  }
184
215
  }, [options, hasSearched]);
216
+ // Restore scroll position after highlightedIndex changes
217
+ (0, react_1.useEffect)(() => {
218
+ // Use requestAnimationFrame to ensure DOM has updated
219
+ requestAnimationFrame(() => {
220
+ restoreScrollPosition();
221
+ });
222
+ }, [highlightedIndex, restoreScrollPosition]);
185
223
  // Reset filtered list when input cleared
186
224
  (0, react_1.useEffect)(() => {
187
225
  if (inputValue === '') {
@@ -259,7 +297,7 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
259
297
  case 'ArrowUp':
260
298
  e.preventDefault();
261
299
  if (isOpen) {
262
- setHighlightedIndex((prev) => (prev > 0 ? prev - 1 : filteredOptions.length - 1));
300
+ handleKeyboardNavigation('up');
263
301
  }
264
302
  else {
265
303
  setIsOpen(true);
@@ -268,14 +306,23 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
268
306
  case 'ArrowDown':
269
307
  e.preventDefault();
270
308
  if (isOpen) {
271
- setHighlightedIndex((prev) => (prev < filteredOptions.length - 1 ? prev + 1 : 0));
309
+ handleKeyboardNavigation('down');
272
310
  }
273
311
  else {
274
312
  setIsOpen(true);
275
313
  }
276
314
  break;
277
315
  }
278
- }, [isDisabled, isOpen, filteredOptions, highlightedIndex, isCreatable, inputValue, deriveLabel]);
316
+ }, [
317
+ isDisabled,
318
+ isOpen,
319
+ filteredOptions,
320
+ highlightedIndex,
321
+ isCreatable,
322
+ inputValue,
323
+ deriveLabel,
324
+ handleKeyboardNavigation,
325
+ ]);
279
326
  const emitSelection = (0, react_1.useCallback)((next) => {
280
327
  // Backward-compatible callback
281
328
  if (onClick) {
@@ -354,7 +401,7 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
354
401
  return (react_1.default.createElement("div", { ref: containerRef, className: `relative w-full ${className} ${styles.container}`, onKeyDown: handleKeyDown },
355
402
  label && react_1.default.createElement("label", { className: "block text-sm font-medium text-gray-700 mb-1" }, label),
356
403
  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 },
357
- react_1.default.createElement("div", { className: "flex-grow flex items-center overflow-x-auto no-scrollbar" },
404
+ react_1.default.createElement("div", { ref: scrollContainerRef, className: "flex-grow flex items-center overflow-x-auto creatable-dropdown-scroll" },
358
405
  react_1.default.createElement("div", { className: "flex items-center gap-2 flex-nowrap" },
359
406
  selectedValues.length > 0 &&
360
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" },
@@ -87,6 +87,21 @@ li.activeSidebar-subset::after {
87
87
  .noDisplay-scrollbar::-webkit-scrollbar {
88
88
  display: none; /* For Chrome, Safari, and Opera */
89
89
  }
90
+
91
+ /* Custom scroll behavior for CreatableDropDown */
92
+ .creatable-dropdown-scroll {
93
+ scroll-behavior: smooth;
94
+ scrollbar-width: none;
95
+ -ms-overflow-style: none;
96
+ }
97
+
98
+ .creatable-dropdown-scroll::-webkit-scrollbar {
99
+ display: none;
100
+ }
101
+
102
+ .creatable-dropdown-scroll:focus-within {
103
+ scroll-behavior: auto;
104
+ }
90
105
  .danger {
91
106
  background-color: #ffffff;
92
107
  color: #f54180;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hi-tm",
3
- "version": "0.6.6",
3
+ "version": "0.6.7",
4
4
  "styles": "dist/styles/globals.css",
5
5
  "main": "dist/index.js",
6
6
  "exports": {