1- import { FC , useEffect , useRef , useState } from "react" ;
1+ import { FC , useLayoutEffect , useRef , useState } from "react" ;
22import { FiCheck } from "react-icons/fi" ;
33import { IoMdClose } from "react-icons/io" ;
44import { useDebounceValue } from "../../hooks/useDebounceValue" ;
@@ -23,8 +23,10 @@ const SelectInput: FC<SelectInputProps> = (props) => {
2323 const inputRef = useRef < HTMLInputElement > ( null ) ;
2424 const activeRef = useRef < HTMLSpanElement > ( null ) ;
2525
26- useEffect ( ( ) => {
27- if ( debounceFilterValue . trim ( ) . length < 1 ) {
26+ useLayoutEffect ( ( ) => {
27+ const val = debounceFilterValue . toLowerCase ( ) . trim ( ) ;
28+
29+ if ( val . length < 1 ) {
2830 setOptions ( [ ...props . options ] ) ;
2931 activeRef . current ?. scrollIntoView ( {
3032 block : "nearest" ,
@@ -33,11 +35,7 @@ const SelectInput: FC<SelectInputProps> = (props) => {
3335 return ;
3436 }
3537
36- setOptions (
37- [ ...props . options ] . filter ( ( o ) =>
38- o . includes ( debounceFilterValue . toLowerCase ( ) . trim ( ) )
39- )
40- ) ;
38+ setOptions ( [ ...props . options ] . filter ( ( o ) => o . includes ( val ) ) ) ;
4139 } , [ debounceFilterValue , props . options ] ) ;
4240
4341 const selectValue = ( value : string ) : void => {
@@ -126,10 +124,9 @@ const SelectInput: FC<SelectInputProps> = (props) => {
126124 < li
127125 key = { option }
128126 onClick = { ( ) => selectValue ( option ) }
129- className = { `flex items-center gap-4 py-1 px-2 transition-all duration-150
130- hover:bg-gh-button cursor-pointer text-gh-text min-w-[10rem] ${
131- i === 0 ? "" : "border-t border-solid border-gh-border-dark"
132- } `}
127+ className = "flex items-center gap-4 py-1 px-2 transition-all duration-150
128+ hover:bg-gh-button cursor-pointer text-gh-text min-w-[10rem] border-t
129+ border-solid border-gh-border-dark"
133130 >
134131 { isSelected && (
135132 < span ref = { activeRef } >
0 commit comments