react-core-ts 1.4.12 → 1.4.13

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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-core-ts",
3
3
 
4
- "version": "1.4.12",
4
+ "version": "1.4.13",
5
5
  "description": "React Components",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -363,53 +363,6 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
363
363
  }
364
364
  }, [dropOpen]);
365
365
 
366
- // Handle keyboard navigation
367
- const handleKeyDown = (e: any) => {
368
- if (!dropOpen) return;
369
-
370
- const atBottom = selectedIndex === filteredData.length - 1;
371
- const atTop = selectedIndex === 0;
372
-
373
- switch (e.key) {
374
- case "ArrowDown":
375
- e.preventDefault();
376
- if (itemRefs.current && scrollContainerRef.current) {
377
- if (!atBottom) {
378
- scrollContainerRef.current.scrollTop += itemRefs.current[selectedIndex]?.offsetHeight || 50;
379
- } else {
380
- scrollContainerRef.current.scrollTop = 0;
381
- }
382
- }
383
- setSelectedIndex((prev) => (prev + 1) % filteredData?.length);
384
- break;
385
-
386
- case "ArrowUp":
387
- e.preventDefault();
388
- if (itemRefs.current && scrollContainerRef.current) {
389
- if (!atTop) {
390
- scrollContainerRef.current.scrollTop -= itemRefs.current[selectedIndex]?.offsetHeight || 50;
391
- } else {
392
- scrollContainerRef.current.scrollTop = 0;
393
- }
394
- }
395
- setSelectedIndex((prev) => (prev - 1 + filteredData?.length) % filteredData?.length);
396
- break;
397
-
398
- case "Enter":
399
- e.preventDefault();
400
- handleSuggestionClick(filteredData[selectedIndex], selectedIndex);
401
- break;
402
-
403
- case "Escape":
404
- e.preventDefault();
405
- setDropOpen(false);
406
- break;
407
-
408
- default:
409
- break;
410
- }
411
- };
412
-
413
366
  const handleClear = () => {
414
367
  setDropOpen(false);
415
368
  setInputValue('');
@@ -583,14 +536,62 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
583
536
  return () => clearTimeout(timer);
584
537
  } else {
585
538
  setShowNoResults(false);
586
- if(filteredData?.length > 0 && !isLoading) {
587
- window.addEventListener("keydown", handleKeyDown);
588
- return(() => {
589
- window.removeEventListener("keydown", handleKeyDown);
590
- })
539
+ }
540
+
541
+ // Handle keyboard navigation
542
+ const handleKeyDown = (e: any) => {
543
+ if (!dropOpen) return;
544
+
545
+ const atBottom = selectedIndex === filteredData.length - 1;
546
+ const atTop = selectedIndex === 0;
547
+
548
+ switch (e.key) {
549
+ case "ArrowDown":
550
+ e.preventDefault();
551
+ if (itemRefs.current && scrollContainerRef.current) {
552
+ if (!atBottom) {
553
+ scrollContainerRef.current.scrollTop += itemRefs.current[selectedIndex]?.offsetHeight || 50;
554
+ } else {
555
+ scrollContainerRef.current.scrollTop = 0;
556
+ }
557
+ }
558
+ setSelectedIndex((prev) => (prev + 1) % filteredData?.length);
559
+ break;
560
+
561
+ case "ArrowUp":
562
+ e.preventDefault();
563
+ if (itemRefs.current && scrollContainerRef.current) {
564
+ if (!atTop) {
565
+ scrollContainerRef.current.scrollTop -= itemRefs.current[selectedIndex]?.offsetHeight || 50;
566
+ } else {
567
+ scrollContainerRef.current.scrollTop = 0;
568
+ }
569
+ }
570
+ setSelectedIndex((prev) => (prev - 1 + filteredData?.length) % filteredData?.length);
571
+ break;
572
+
573
+ case "Enter":
574
+ e.preventDefault();
575
+ handleSuggestionClick(filteredData[selectedIndex], selectedIndex);
576
+ break;
577
+
578
+ case "Escape":
579
+ e.preventDefault();
580
+ setDropOpen(false);
581
+ break;
582
+
583
+ default:
584
+ break;
591
585
  }
586
+ };
587
+
588
+ if(filteredData?.length > 0 && !isLoading) {
589
+ window.addEventListener("keydown", handleKeyDown);
590
+ return(() => {
591
+ window.removeEventListener("keydown", handleKeyDown);
592
+ })
592
593
  }
593
- }, [inputValue, filteredData, isLoading, timerRef.current]);
594
+ }, [inputValue, filteredData, isLoading, timerRef.current, selectedIndex]);
594
595
 
595
596
  const setDropDown = () => {
596
597
  return (
@@ -607,8 +608,8 @@ const ModernAutoComplete: React.FC<AutoSuggestionInputProps> = ({
607
608
  className={`${
608
609
  value?.id === suggestion?.id
609
610
  ? 'bg-blue-navy text-white'
610
- : 'hover:bg-table-hover'
611
- } ${index === selectedIndex ? "is-selected" : ""} cursor-pointer p-1 text-xxs ps-3.5 pl-[10px] qbs-autocomplete-suggections-items`}
611
+ : `${index === selectedIndex ? "is-selected" : ""} hover:bg-table-hover`
612
+ } cursor-pointer p-1 text-xxs ps-3.5 pl-[10px] qbs-autocomplete-suggections-items`}
612
613
  key={suggestion?.id}
613
614
  data-testid={suggestion.name}
614
615
  onClick={() => handleSuggestionClick(suggestion, index)}