Fix select not resetting on new views
This commit is contained in:
parent
dc86e712cb
commit
c51c16de09
1 changed files with 7 additions and 3 deletions
|
|
@ -13,7 +13,6 @@ interface Props
|
||||||
HTMLSelectElement
|
HTMLSelectElement
|
||||||
> {
|
> {
|
||||||
open: boolean
|
open: boolean
|
||||||
placeholder?: string
|
|
||||||
trigger?: React.ReactNode
|
trigger?: React.ReactNode
|
||||||
children?: React.ReactNode
|
children?: React.ReactNode
|
||||||
onClick?: () => void
|
onClick?: () => void
|
||||||
|
|
@ -25,7 +24,8 @@ const Select = (props: Props) => {
|
||||||
const [value, setValue] = useState('')
|
const [value, setValue] = useState('')
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (props.value) setValue(`${props.value}`)
|
if (props.value && props.value !== '') setValue(`${props.value}`)
|
||||||
|
else setValue('')
|
||||||
}, [props.value])
|
}, [props.value])
|
||||||
|
|
||||||
function onValueChange(newValue: string) {
|
function onValueChange(newValue: string) {
|
||||||
|
|
@ -33,8 +33,12 @@ const Select = (props: Props) => {
|
||||||
if (props.onValueChange) props.onValueChange(newValue)
|
if (props.onValueChange) props.onValueChange(newValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(value)
|
||||||
return (
|
return (
|
||||||
<RadixSelect.Root value={value} onValueChange={onValueChange}>
|
<RadixSelect.Root
|
||||||
|
value={value !== '' ? value : undefined}
|
||||||
|
onValueChange={onValueChange}
|
||||||
|
>
|
||||||
<RadixSelect.Trigger
|
<RadixSelect.Trigger
|
||||||
className={classNames('SelectTrigger', props.triggerClass)}
|
className={classNames('SelectTrigger', props.triggerClass)}
|
||||||
placeholder={props.placeholder}
|
placeholder={props.placeholder}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue