diff --git a/src/components/data-entry/QueryItem/Cascader.tsx b/src/components/data-entry/QueryItem/Cascader.tsx index 821937982..d904fd4f8 100644 --- a/src/components/data-entry/QueryItem/Cascader.tsx +++ b/src/components/data-entry/QueryItem/Cascader.tsx @@ -38,7 +38,7 @@ const Cascader = (props: ICascaderProps) => { const [searchValue, setSearchValue] = useState('') const [selectedValue, setSelectedValue] = useState>(props.value ?? []) const [selectedDisplayValue, setSelectedDisplayValue] = useState( - props.value ? (props.value.slice(-1)[0] as any).label : '', + props.value && props.value.length > 0 ? (props.value.slice(-1)[0] as any).label : '', ) const [isOpen, setIsOpen] = useState(false) @@ -46,6 +46,12 @@ const Cascader = (props: ICascaderProps) => { setItems(props.options) }, [props.options]) + useEffect(() => { + if (props.value && props.value.length > 0) { + setSelectedValue(props.value) + } + }, [props.value]) + const onSearch = ({ target: { value } }: { target: { value: string } }) => { if (debouncedLoadData) { if (value.length > 3) { @@ -179,4 +185,4 @@ const Cascader = (props: ICascaderProps) => { } } -export default Cascader \ No newline at end of file +export default Cascader