Skip to content

Commit 3a4210c

Browse files
fix: update value single select
1 parent 74eede3 commit 3a4210c

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

src/components/Form/SingleSelect.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff 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 = () => {
@@ -142,14 +143,18 @@ function SingleSelect({
142143
}, [])
143144

144145
useEffect(() => {
145-
if (!value) return
146+
if (!newValue) return
146147
setOptions(
147148
optionsList.map((option) =>
148149
option.value === value ? { ...option, selected: true } : option
149150
)
150151
)
151152
}, [])
152153

154+
useEffect(() => {
155+
setNewValue(value)
156+
}, [value])
157+
153158
return (
154159
<div
155160
ref={selectRef}
@@ -175,7 +180,7 @@ function SingleSelect({
175180
)}
176181
<input
177182
placeholder={isFilter ? placeholder : ''}
178-
value={selectedOption?.label}
183+
value={selectedOption?.label || newValue}
179184
{...otherProps}
180185
className={composeClasses(
181186
'outline-none w-full bg-transparent truncate text-sm',

0 commit comments

Comments
 (0)