File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -82,6 +82,7 @@ function SingleSelect({
8282 const [ selectedOption , setSelectedOption ] = useState < ISelectOption | null > (
8383 null
8484 )
85+ const [ newValue , setNewValue ] = useState ( value )
8586 const [ options , setOptions ] = useState < ISelectOption [ ] > ( optionsList )
8687
8788 const handleClick = ( ) => {
@@ -124,6 +125,10 @@ function SingleSelect({
124125 onChangeSelect ?.( option )
125126 }
126127
128+ useEffect ( ( ) => {
129+ setOptions ( optionsList )
130+ } , [ optionsList ] )
131+
127132 useEffect ( ( ) => {
128133 const handleClickOutside = ( e : globalThis . MouseEvent ) => {
129134 if ( selectRef . current && ! selectRef . current . contains ( e . target as Node ) ) {
@@ -138,14 +143,18 @@ function SingleSelect({
138143 } , [ ] )
139144
140145 useEffect ( ( ) => {
141- if ( ! value ) return
146+ if ( ! newValue ) return
142147 setOptions (
143148 optionsList . map ( ( option ) =>
144149 option . value === value ? { ...option , selected : true } : option
145150 )
146151 )
147152 } , [ ] )
148153
154+ useEffect ( ( ) => {
155+ setNewValue ( value )
156+ } , [ value ] )
157+
149158 return (
150159 < div
151160 ref = { selectRef }
@@ -171,7 +180,7 @@ function SingleSelect({
171180 ) }
172181 < input
173182 placeholder = { isFilter ? placeholder : '' }
174- value = { selectedOption ?. label }
183+ value = { selectedOption ?. label || newValue }
175184 { ...otherProps }
176185 className = { composeClasses (
177186 'outline-none w-full bg-transparent truncate text-sm' ,
You can’t perform that action at this time.
0 commit comments