react-core-ts 1.6.0 → 1.6.2

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.
@@ -1,12 +1,12 @@
1
- import React, { useCallback, useEffect, useRef, useState } from 'react';
2
- import { FieldErrors } from 'react-hook-form';
1
+ import React, { useCallback, useEffect, useRef, useState } from "react";
2
+ import { FieldErrors } from "react-hook-form";
3
3
 
4
- import CustomIcons from './components/customIcons';
5
- import Spinner from './components/loader/Spinner';
6
- import Portal from './components/portal';
7
- import { debounce } from './utilities/debounce';
8
- import { applyPositionClass } from './utilities/getPosition';
9
- import { DropArrow } from './utilities/icons';
4
+ import CustomIcons from "./components/customIcons";
5
+ import Spinner from "./components/loader/Spinner";
6
+ import Portal from "./components/portal";
7
+ import { debounce } from "./utilities/debounce";
8
+ import { applyPositionClass } from "./utilities/getPosition";
9
+ import { DropArrow } from "./utilities/icons";
10
10
 
11
11
  type valueProps = {
12
12
  id?: string | number;
@@ -30,7 +30,7 @@ interface AutoSuggestionInputProps {
30
30
  value?: valueProps;
31
31
  onChange: (value?: valueProps) => void;
32
32
  data?: any[];
33
- type?: 'custom_select' | 'auto_complete' | 'custom_search_select';
33
+ type?: "custom_select" | "auto_complete" | "custom_search_select";
34
34
  placeholder?: string;
35
35
  getData?: ((key?: string) => Promise<any>) | ((key?: string) => any);
36
36
  errors?: FieldErrors;
@@ -63,12 +63,12 @@ const ModernAutoCompleteDropdown: React.FC<AutoSuggestionInputProps> = ({
63
63
  required = false,
64
64
  autoFocus,
65
65
  name,
66
- shortCode = '',
66
+ shortCode = "",
67
67
  fullWidth,
68
68
  placeholder,
69
69
  id,
70
70
  className: propsClassName,
71
- type = 'custom_select',
71
+ type = "custom_select",
72
72
  readOnly,
73
73
  disabled = false,
74
74
  value,
@@ -86,7 +86,7 @@ const ModernAutoCompleteDropdown: React.FC<AutoSuggestionInputProps> = ({
86
86
  labelTitle,
87
87
  isModern = true,
88
88
  }) => {
89
- const [inputValue, setInputValue] = useState<any>(value?.name ?? '');
89
+ const [inputValue, setInputValue] = useState<any>(value?.name ?? "");
90
90
  const [isHovered, setIsHovered] = useState<boolean>(false);
91
91
  const [isLoading, setIsLoading] = useState<boolean>(false);
92
92
  const [dropOpen, setDropOpen] = useState<boolean>(false);
@@ -124,8 +124,8 @@ const ModernAutoCompleteDropdown: React.FC<AutoSuggestionInputProps> = ({
124
124
  ) => {
125
125
  return substring &&
126
126
  mainString &&
127
- typeof mainString === 'string' &&
128
- typeof subString === 'string'
127
+ typeof mainString === "string" &&
128
+ typeof subString === "string"
129
129
  ? mainString
130
130
  .toString()
131
131
  .toLowerCase()
@@ -140,13 +140,13 @@ const ModernAutoCompleteDropdown: React.FC<AutoSuggestionInputProps> = ({
140
140
  return (
141
141
  checkIncludesIfExists(mainString, subString) ||
142
142
  (!!checkParams &&
143
- ((checkArrayContains(checkParams, 'param1') &&
143
+ ((checkArrayContains(checkParams, "param1") &&
144
144
  checkIncludesIfExists(param1, subString)) ||
145
- (checkArrayContains(checkParams, 'param2') &&
145
+ (checkArrayContains(checkParams, "param2") &&
146
146
  checkIncludesIfExists(param2, subString)) ||
147
- (checkArrayContains(checkParams, 'param3') &&
147
+ (checkArrayContains(checkParams, "param3") &&
148
148
  checkIncludesIfExists(param3, subString)) ||
149
- (checkArrayContains(checkParams, 'param4') &&
149
+ (checkArrayContains(checkParams, "param4") &&
150
150
  checkIncludesIfExists(param4, subString))))
151
151
  );
152
152
  };
@@ -158,8 +158,8 @@ const ModernAutoCompleteDropdown: React.FC<AutoSuggestionInputProps> = ({
158
158
  setInputValue(value);
159
159
  handleValChange(value);
160
160
  if (!value) {
161
- setInputValue('');
162
- onChange({ id: undefined, name: '', from: 2 });
161
+ setInputValue("");
162
+ onChange({ id: undefined, name: "", from: 2 });
163
163
  }
164
164
  };
165
165
 
@@ -167,11 +167,11 @@ const ModernAutoCompleteDropdown: React.FC<AutoSuggestionInputProps> = ({
167
167
  debounce(
168
168
  (value: string) => {
169
169
  setDropOpen(true);
170
- onChange({ id: undefined, name: '', from: 1 });
171
- if (value.trim() === '' && type === 'auto_complete') {
170
+ onChange({ id: undefined, name: "", from: 1 });
171
+ if (value.trim() === "" && type === "auto_complete") {
172
172
  setSuggestions([]);
173
173
  if (autoFilter) {
174
- handleDropData('*');
174
+ handleDropData("*");
175
175
  } else {
176
176
  setDropOpen(false);
177
177
  }
@@ -187,11 +187,11 @@ const ModernAutoCompleteDropdown: React.FC<AutoSuggestionInputProps> = ({
187
187
  []
188
188
  );
189
189
  const handleDropData = (value?: string) => {
190
- if (type === 'auto_complete') {
190
+ if (type === "auto_complete") {
191
191
  if (isStaticList) {
192
192
  loadStaticData();
193
193
  const filteredData =
194
- value && value !== '*'
194
+ value && value !== "*"
195
195
  ? data?.filter((item) =>
196
196
  checkIncludes(
197
197
  item.name,
@@ -204,16 +204,16 @@ const ModernAutoCompleteDropdown: React.FC<AutoSuggestionInputProps> = ({
204
204
  : data;
205
205
  setSuggestions(filteredData);
206
206
  } else {
207
- handlePickSuggestions(value);
207
+ handlePickSuggestions(value);
208
208
  }
209
209
  } else if (
210
- (type === 'custom_select' || type === 'custom_search_select') &&
210
+ (type === "custom_select" || type === "custom_search_select") &&
211
211
  (!data || data?.length === 0)
212
212
  ) {
213
213
  handlePickSuggestions();
214
- } else if (type === 'custom_search_select' && data && data?.length > 0) {
214
+ } else if (type === "custom_search_select" && data && data?.length > 0) {
215
215
  const filteredData =
216
- value && value !== '*'
216
+ value && value !== "*"
217
217
  ? data.filter((item) =>
218
218
  checkIncludes(
219
219
  item.name,
@@ -243,10 +243,10 @@ const ModernAutoCompleteDropdown: React.FC<AutoSuggestionInputProps> = ({
243
243
  const onLabelClick = () => {
244
244
  if (!isDisabled) {
245
245
  inputRef?.current?.focus();
246
- if (autoFilter && inputValue === '') {
247
- handleValChange('*');
246
+ if (autoFilter && inputValue === "") {
247
+ handleValChange("*");
248
248
  } else if (
249
- (type === 'custom_select' || type === 'custom_search_select') &&
249
+ (type === "custom_select" || type === "custom_search_select") &&
250
250
  data &&
251
251
  data?.length > 0
252
252
  ) {
@@ -274,7 +274,7 @@ const ModernAutoCompleteDropdown: React.FC<AutoSuggestionInputProps> = ({
274
274
  try {
275
275
  setIsLoading(true);
276
276
  //handlePickSuggestions('*');
277
- const fetchedSuggestions = await getData?.('*');
277
+ const fetchedSuggestions = await getData?.("*");
278
278
  setSuggestions(fetchedSuggestions);
279
279
  setIsLoading(false);
280
280
  } catch (error) {
@@ -284,9 +284,9 @@ const ModernAutoCompleteDropdown: React.FC<AutoSuggestionInputProps> = ({
284
284
  }
285
285
  };
286
286
  useEffect(() => {
287
- document.addEventListener('click', handleClickOutside);
287
+ document.addEventListener("click", handleClickOutside);
288
288
  return () => {
289
- document.removeEventListener('click', handleClickOutside);
289
+ document.removeEventListener("click", handleClickOutside);
290
290
  };
291
291
  }, []);
292
292
 
@@ -297,10 +297,10 @@ const ModernAutoCompleteDropdown: React.FC<AutoSuggestionInputProps> = ({
297
297
  }, [autoFocus]);
298
298
  const onInputFocus = () => {
299
299
  if (!isDisabled) {
300
- if (autoFilter && inputValue === '') {
301
- handleValChange('*');
300
+ if (autoFilter && inputValue === "") {
301
+ handleValChange("*");
302
302
  } else if (
303
- (type === 'custom_select' || type === 'custom_search_select') &&
303
+ (type === "custom_select" || type === "custom_search_select") &&
304
304
  data &&
305
305
  data?.length > 0
306
306
  ) {
@@ -319,7 +319,7 @@ const ModernAutoCompleteDropdown: React.FC<AutoSuggestionInputProps> = ({
319
319
  name: suggestion.name,
320
320
  ...(suggestion?.label ? { label: suggestion?.label } : {}),
321
321
  });
322
- if (type !== 'custom_select') setInputValue(suggestion.name);
322
+ if (type !== "custom_select") setInputValue(suggestion.name);
323
323
  setDropOpen(false);
324
324
  setSelectedIndex(index);
325
325
  };
@@ -327,18 +327,18 @@ const ModernAutoCompleteDropdown: React.FC<AutoSuggestionInputProps> = ({
327
327
  if (!suggestions || suggestions?.length === 0) handleDropData();
328
328
  if (!isLoading) {
329
329
  setDropOpen(!dropOpen);
330
- if (type !== 'custom_select') setInputValue('');
330
+ if (type !== "custom_select") setInputValue("");
331
331
  }
332
332
  };
333
333
 
334
334
  const handleOpenDropdown = (e: any) => {
335
335
  if (!suggestions || suggestions?.length === 0) {
336
- if (autoDropdown && (inputValue === '' || inputValue.trim() === '')) {
336
+ if (autoDropdown && (inputValue === "" || inputValue.trim() === "")) {
337
337
  loadStaticData();
338
338
  } else {
339
- handleDropData()
339
+ handleDropData();
340
340
  }
341
- };
341
+ }
342
342
  if (!isLoading) {
343
343
  setDropOpen(!dropOpen);
344
344
  }
@@ -351,28 +351,28 @@ const ModernAutoCompleteDropdown: React.FC<AutoSuggestionInputProps> = ({
351
351
  useEffect(() => {
352
352
  if (!insideOpen) {
353
353
  setSelectedIndex(0);
354
- window.addEventListener('scroll', handleScroll);
354
+ window.addEventListener("scroll", handleScroll);
355
355
 
356
- const mainElement = document.querySelector('main');
357
- mainElement?.addEventListener('scroll', handleScroll);
356
+ const mainElement = document.querySelector("main");
357
+ mainElement?.addEventListener("scroll", handleScroll);
358
358
 
359
359
  const gridElements = document.querySelectorAll(
360
- '.k-grid-content, .overflow-auto, .overflow-y-auto, .overflow-x-auto'
360
+ ".k-grid-content, .overflow-auto, .overflow-y-auto, .overflow-x-auto"
361
361
  );
362
362
  gridElements.forEach((gridElement: any) => {
363
- gridElement.addEventListener('scroll', handleScroll);
363
+ gridElement.addEventListener("scroll", handleScroll);
364
364
  });
365
365
 
366
- window.addEventListener('resize', getDropPosition);
366
+ window.addEventListener("resize", getDropPosition);
367
367
  getDropPosition();
368
368
  return () => {
369
- window.removeEventListener('scroll', handleScroll);
370
- const mainElement = document.querySelector('main');
371
- mainElement?.removeEventListener('scroll', handleScroll);
372
- window.addEventListener('resize', getDropPosition);
373
- const gridElements = document.querySelectorAll('.k-grid-content');
369
+ window.removeEventListener("scroll", handleScroll);
370
+ const mainElement = document.querySelector("main");
371
+ mainElement?.removeEventListener("scroll", handleScroll);
372
+ window.addEventListener("resize", getDropPosition);
373
+ const gridElements = document.querySelectorAll(".k-grid-content");
374
374
  gridElements.forEach((gridElement: any) => {
375
- gridElement.removeEventListener('scroll', handleScroll);
375
+ gridElement.removeEventListener("scroll", handleScroll);
376
376
  });
377
377
  };
378
378
  }
@@ -380,13 +380,13 @@ const ModernAutoCompleteDropdown: React.FC<AutoSuggestionInputProps> = ({
380
380
 
381
381
  const handleClear = () => {
382
382
  setDropOpen(false);
383
- setInputValue('');
384
- onChange({ id: undefined, name: '', from: 3 });
383
+ setInputValue("");
384
+ onChange({ id: undefined, name: "", from: 3 });
385
385
  onLabelClick();
386
386
  };
387
387
 
388
388
  useEffect(() => {
389
- setInputValue(value?.name ?? '');
389
+ setInputValue(value?.name ?? "");
390
390
  }, [value?.name]);
391
391
 
392
392
  useEffect(() => {
@@ -394,7 +394,7 @@ const ModernAutoCompleteDropdown: React.FC<AutoSuggestionInputProps> = ({
394
394
  }, [data]);
395
395
 
396
396
  const getErrors = (err: any) => {
397
- let errMsg = '';
397
+ let errMsg = "";
398
398
  if (err.message) {
399
399
  errMsg = err?.message;
400
400
  } else if (err?.id?.message) {
@@ -405,59 +405,59 @@ const ModernAutoCompleteDropdown: React.FC<AutoSuggestionInputProps> = ({
405
405
  return errMsg;
406
406
  };
407
407
  const generateClassName = (
408
- type: 'input' | 'label' | 'message' | 'adorement'
408
+ type: "input" | "label" | "message" | "adorement"
409
409
  ): string => {
410
410
  let className = propsClassName;
411
411
  switch (type) {
412
- case 'input':
412
+ case "input":
413
413
  className += `block text-common text-input-text font-normal px-3.5 w-full text-sm text-gray-900 bg-transparent border appearance-none peer h-10 rounded-[4px] disabled:text-input-disabled bg-white disabled:bg-disabled ${
414
414
  label && isModern
415
- ? 'placeholder-transparent'
416
- : 'focus:placeholder-grey-secondary placeholder-input-label'
415
+ ? "placeholder-transparent"
416
+ : "focus:placeholder-grey-secondary placeholder-input-label"
417
417
  } focus:placeholder-grey-secondary`;
418
418
 
419
419
  if (errors && errors[name]) {
420
420
  className +=
421
- ' border-[#FDA29B] focus:border-error-[#FDA29B] focus:ring-[#FDA29B] focus:ring-3 focus:outline-[#FDA29B] input-outline';
421
+ " border-[#FDA29B] focus:border-error-[#FDA29B] focus:ring-[#FDA29B] focus:ring-3 focus:outline-[#FDA29B] input-outline";
422
422
  } else {
423
423
  className +=
424
- ' text-grey-dark border-input-light focus:border-blue-navy focus:outline-none focus:ring-0';
424
+ " text-grey-dark border-input-light focus:border-blue-navy focus:outline-none focus:ring-0";
425
425
  }
426
426
 
427
427
  break;
428
- case 'label':
428
+ case "label":
429
429
  className += ` flex modern-input-label-truncate peer-focus:modern-input-peer-focus-label-size
430
430
  ${
431
431
  isDisabled
432
- ? 'cursor-pointer'
433
- : 'cursor-text peer-focus:cursor-pointer'
432
+ ? "cursor-pointer"
433
+ : "cursor-text peer-focus:cursor-pointer"
434
434
  } ${
435
435
  isDisabled && !checkIsEmptyField()
436
- ? 'disabled-input-label-bg'
436
+ ? "disabled-input-label-bg"
437
437
  : !isDisabled || !checkIsEmptyField()
438
- ? 'active-input-label-bg'
439
- : ''
438
+ ? "active-input-label-bg"
439
+ : ""
440
440
  } absolute duration-300 transform -translate-y-4 top-2 z-1 origin-[0] px-0 peer-placeholder-shown:-translate-y-1/2 peer-placeholder-shown:top-1/2 peer-focus:top-2 peer-focus:-translate-y-4 start-[14px] rtl:peer-focus:translate-x-1/4 rtl:peer-focus:left-auto ${
441
441
  isDisabled
442
- ? 'cursor-pointer'
443
- : 'cursor-text peer-focus:cursor-pointer'
442
+ ? "cursor-pointer"
443
+ : "cursor-text peer-focus:cursor-pointer"
444
444
  }
445
445
  ${
446
446
  checkIsEmptyField()
447
- ? 'modern-input-label-size'
448
- : 'modern-input-peer-focus-label-size'
447
+ ? "modern-input-label-size"
448
+ : "modern-input-peer-focus-label-size"
449
449
  }`;
450
450
  if (errors && errors[name]) {
451
- className += ' text-error-light ';
451
+ className += " text-error-light ";
452
452
  } else {
453
- className += ' text-grey-dark peer-focus:text-blue-navy';
453
+ className += " text-grey-dark peer-focus:text-blue-navy";
454
454
  }
455
455
  break;
456
- case 'message':
457
- className = ' text-error-icon ';
456
+ case "message":
457
+ className = " text-error-icon ";
458
458
  break;
459
- case 'adorement':
460
- className += ' absolute right-0 adorement gap-1 flex items-center ';
459
+ case "adorement":
460
+ className += " absolute right-0 adorement gap-1 flex items-center ";
461
461
  break;
462
462
  default:
463
463
  break;
@@ -482,30 +482,30 @@ const ModernAutoCompleteDropdown: React.FC<AutoSuggestionInputProps> = ({
482
482
  // return 'bottom'
483
483
  // }
484
484
  const filteredData =
485
- inputValue !== '*' &&
486
- inputValue !== '' &&
487
- type !== 'custom_select' &&
485
+ inputValue !== "*" &&
486
+ inputValue !== "" &&
487
+ type !== "custom_select" &&
488
488
  !noLocalFilter
489
489
  ? suggestions?.filter((item: valueProps) =>
490
490
  checkIncludes(
491
491
  item.name,
492
492
  inputValue,
493
- item.param1 ?? '',
494
- item.param2 ?? '',
495
- item.param3 ?? '',
496
- item.param4 ?? ''
493
+ item.param1 ?? "",
494
+ item.param2 ?? "",
495
+ item.param3 ?? "",
496
+ item.param4 ?? ""
497
497
  )
498
498
  )
499
499
  : suggestions;
500
500
 
501
501
  const handleError = (data: any) => {
502
502
  if (
503
- getErrors(data[name]) === 'required' ||
504
- getErrors(data[name]) === 'Required'
503
+ getErrors(data[name]) === "required" ||
504
+ getErrors(data[name]) === "Required"
505
505
  ) {
506
506
  return `${label ?? labelTitle} is ${getErrors(data[name])}`;
507
507
  } else {
508
- return getErrors(data[name]) ?? '';
508
+ return getErrors(data[name]) ?? "";
509
509
  }
510
510
  };
511
511
 
@@ -561,7 +561,7 @@ const ModernAutoCompleteDropdown: React.FC<AutoSuggestionInputProps> = ({
561
561
  const atTop = selectedIndex === 0;
562
562
 
563
563
  switch (e.key) {
564
- case 'ArrowDown':
564
+ case "ArrowDown":
565
565
  e.preventDefault();
566
566
  if (itemRefs.current && scrollContainerRef.current) {
567
567
  if (!atBottom) {
@@ -574,7 +574,7 @@ const ModernAutoCompleteDropdown: React.FC<AutoSuggestionInputProps> = ({
574
574
  setSelectedIndex((prev) => (prev + 1) % filteredData?.length);
575
575
  break;
576
576
 
577
- case 'ArrowUp':
577
+ case "ArrowUp":
578
578
  e.preventDefault();
579
579
  if (itemRefs.current && scrollContainerRef.current) {
580
580
  if (!atTop) {
@@ -589,12 +589,12 @@ const ModernAutoCompleteDropdown: React.FC<AutoSuggestionInputProps> = ({
589
589
  );
590
590
  break;
591
591
 
592
- case 'Enter':
592
+ case "Enter":
593
593
  e.preventDefault();
594
594
  handleSuggestionClick(filteredData[selectedIndex], selectedIndex);
595
595
  break;
596
596
 
597
- case 'Escape':
597
+ case "Escape":
598
598
  e.preventDefault();
599
599
  setDropOpen(false);
600
600
  break;
@@ -605,9 +605,9 @@ const ModernAutoCompleteDropdown: React.FC<AutoSuggestionInputProps> = ({
605
605
  };
606
606
 
607
607
  if (filteredData?.length > 0 && !isLoading) {
608
- window.addEventListener('keydown', handleKeyDown);
608
+ window.addEventListener("keydown", handleKeyDown);
609
609
  return () => {
610
- window.removeEventListener('keydown', handleKeyDown);
610
+ window.removeEventListener("keydown", handleKeyDown);
611
611
  };
612
612
  }
613
613
  }, [
@@ -633,9 +633,9 @@ const ModernAutoCompleteDropdown: React.FC<AutoSuggestionInputProps> = ({
633
633
  <li
634
634
  className={`${
635
635
  value?.id === suggestion?.id
636
- ? 'bg-blue-navy text-white'
636
+ ? "bg-blue-navy text-white"
637
637
  : `${
638
- index === selectedIndex ? 'is-selected' : ''
638
+ index === selectedIndex ? "is-selected" : ""
639
639
  } hover:bg-table-hover`
640
640
  } cursor-pointer p-1 text-xxs ps-3.5 pl-[10px] qbs-autocomplete-suggections-items`}
641
641
  key={suggestion?.id}
@@ -694,7 +694,7 @@ const ModernAutoCompleteDropdown: React.FC<AutoSuggestionInputProps> = ({
694
694
  useEffect(() => {
695
695
  const shouldShowClose =
696
696
  value?.name &&
697
- (value?.id || String(value?.id) === '0') &&
697
+ (value?.id || String(value?.id) === "0") &&
698
698
  !disabled &&
699
699
  !readOnly &&
700
700
  isClose;
@@ -708,7 +708,7 @@ const ModernAutoCompleteDropdown: React.FC<AutoSuggestionInputProps> = ({
708
708
  if (inputRef.current) {
709
709
  const { scrollWidth, clientWidth, value } = inputRef.current;
710
710
  // Check for overflow only when there's content
711
- if (value.trim() !== '') {
711
+ if (value.trim() !== "") {
712
712
  setShowTooltip(scrollWidth > clientWidth + 2);
713
713
  } else {
714
714
  setShowTooltip(false); // No tooltip for empty input
@@ -717,13 +717,13 @@ const ModernAutoCompleteDropdown: React.FC<AutoSuggestionInputProps> = ({
717
717
  };
718
718
 
719
719
  if (inputRef.current) {
720
- inputRef.current.addEventListener('input', checkOverflow);
720
+ inputRef.current.addEventListener("input", checkOverflow);
721
721
  checkOverflow(); // Initial check
722
722
  }
723
723
 
724
724
  return () => {
725
725
  if (inputRef.current) {
726
- inputRef.current.removeEventListener('input', checkOverflow);
726
+ inputRef.current.removeEventListener("input", checkOverflow);
727
727
  }
728
728
  };
729
729
  }, [inputValue]);
@@ -741,7 +741,7 @@ const ModernAutoCompleteDropdown: React.FC<AutoSuggestionInputProps> = ({
741
741
  id={
742
742
  id ? `autocomplete-container-${id}` : `autocomplete-container-${name}`
743
743
  }
744
- className={` flex-grow ${fullWidth ? 'w-full' : 'w-auto'}`}
744
+ className={` flex-grow ${fullWidth ? "w-full" : "w-auto"}`}
745
745
  ref={dropdownref}
746
746
  >
747
747
  {label && !isModern && (
@@ -761,7 +761,7 @@ const ModernAutoCompleteDropdown: React.FC<AutoSuggestionInputProps> = ({
761
761
  )}
762
762
 
763
763
  <div
764
- className={`flex relative ${fullWidth ? 'w-full' : 'w-auto'}`}
764
+ className={`flex relative ${fullWidth ? "w-full" : "w-auto"}`}
765
765
  style={{ width: width }}
766
766
  >
767
767
  <div
@@ -771,8 +771,8 @@ const ModernAutoCompleteDropdown: React.FC<AutoSuggestionInputProps> = ({
771
771
  >
772
772
  <input
773
773
  type="text"
774
- readOnly={readOnly ?? type === 'custom_select'}
775
- value={inputValue ? inputValue : ''}
774
+ readOnly={readOnly ?? type === "custom_select"}
775
+ value={inputValue ? inputValue : ""}
776
776
  onBlur={handleClearInputValue}
777
777
  autoComplete="off"
778
778
  disabled={disabled}
@@ -795,22 +795,23 @@ const ModernAutoCompleteDropdown: React.FC<AutoSuggestionInputProps> = ({
795
795
  }
796
796
  : {}),
797
797
  }}
798
- className={` ${generateClassName('input')}`}
798
+ className={` ${generateClassName("input")}`}
799
799
  onChange={handleChange}
800
800
  placeholder={
801
- type === 'auto_complete'
801
+ type === "auto_complete"
802
802
  ? placeholder && isCustomPlaceholder
803
803
  ? placeholder
804
- : 'Type to search'
805
- : placeholder ?? '--Select--'
804
+ : "Type to search"
805
+ : placeholder ?? "--Select--"
806
806
  }
807
807
  onFocus={onInputFocus}
808
808
  onClick={(e) => {
809
- if (type === 'custom_select') {
809
+ if (type === "custom_select") {
810
810
  setDropOpen(!dropOpen);
811
811
  handleOpen(e);
812
812
  } else {
813
- setDropOpen(!dropOpen);
813
+ if (dropOpen || filteredData?.length > 0)
814
+ setDropOpen(!dropOpen);
814
815
  }
815
816
  }}
816
817
  />
@@ -818,9 +819,9 @@ const ModernAutoCompleteDropdown: React.FC<AutoSuggestionInputProps> = ({
818
819
  <label
819
820
  htmlFor={id}
820
821
  onClick={() => onLabelClick()}
821
- className={generateClassName('label')}
822
+ className={generateClassName("label")}
822
823
  >
823
- {label ? <span className="truncate">{label}</span> : ''}
824
+ {label ? <span className="truncate">{label}</span> : ""}
824
825
  {required ? <span className="text-error"> *</span> : <></>}
825
826
  </label>
826
827
  )}
@@ -829,9 +830,9 @@ const ModernAutoCompleteDropdown: React.FC<AutoSuggestionInputProps> = ({
829
830
  <div
830
831
  ref={adorementRef}
831
832
  className={`${generateClassName(
832
- 'adorement'
833
+ "adorement"
833
834
  )} qbs-autocomplete-adorement mr-[1px] ${
834
- isLoading ? 'bg-white' : ''
835
+ isLoading ? "bg-white" : ""
835
836
  }`}
836
837
  >
837
838
  {showClose && (
@@ -846,31 +847,33 @@ const ModernAutoCompleteDropdown: React.FC<AutoSuggestionInputProps> = ({
846
847
  </button>
847
848
  )}
848
849
  {isLoading && <Spinner />}
849
- {(type !== 'auto_complete' || autoDropdown) && !disabled && !readOnly && (
850
- <button
851
- disabled={disabled ?? readOnly}
852
- onClick={(e) => handleOpenDropdown(e)}
853
- onBlur={handleClose}
854
- className=" text-[#667085] focus-visible:outline-slate-100"
855
- data-testid="drop-arrow"
856
- type="button"
857
- id="autocomplete-drop-icon"
858
- ref={dropBtnRef}
859
- >
860
- {!dropOpen ? (
861
- <DropArrow uniqueDropArrowId="drop-arrow-icon" />
862
- ) : (
863
- <DropArrow
864
- className="rotate-180"
865
- uniqueDropArrowId="drop-arrow-icon"
866
- />
867
- )}
868
- </button>
869
- )}
850
+ {(type !== "auto_complete" || autoDropdown) &&
851
+ !disabled &&
852
+ !readOnly && (
853
+ <button
854
+ disabled={disabled ?? readOnly}
855
+ onClick={(e) => handleOpenDropdown(e)}
856
+ onBlur={handleClose}
857
+ className=" text-[#667085] focus-visible:outline-slate-100"
858
+ data-testid="drop-arrow"
859
+ type="button"
860
+ id="autocomplete-drop-icon"
861
+ ref={dropBtnRef}
862
+ >
863
+ {!dropOpen ? (
864
+ <DropArrow uniqueDropArrowId="drop-arrow-icon" />
865
+ ) : (
866
+ <DropArrow
867
+ className="rotate-180"
868
+ uniqueDropArrowId="drop-arrow-icon"
869
+ />
870
+ )}
871
+ </button>
872
+ )}
870
873
  {errors && errors[name] && (
871
874
  <div
872
875
  className={` text-error-label relative cursor-pointer ${generateClassName(
873
- 'message'
876
+ "message"
874
877
  )}`}
875
878
  onMouseEnter={() => setIsHovered(true)}
876
879
  onMouseLeave={() => setIsHovered(false)}