Skip to content

Commit

Permalink
fix(SeachSelect): 修复Form中使用没有赋值initialValue情况下无法重置 #760 (#763)
Browse files Browse the repository at this point in the history
  • Loading branch information
nullptr-z committed Apr 12, 2022
1 parent 15d151f commit d11d652
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/react-search-select/README.md
Expand Up @@ -411,6 +411,7 @@ const Demo = () => {
];
const [option, setOption] = React.useState(selectOption);
const [loading, setLoading] = React.useState(false);
const refForm = React.useRef()

function handleSearch(e) {
setLoading(true)
Expand All @@ -421,9 +422,14 @@ const Demo = () => {
}, 500);
}

const reSetForm = () => {
console.log('form', refForm.current.resetForm())
}

return (
<div>
<Form
ref={refForm}
onSubmitError={(error) => {
if (error.filed) {
return { ...error.filed };
Expand Down Expand Up @@ -500,6 +506,9 @@ const Demo = () => {
<Col fixed>
<Button disabled={!canSubmit()} type="primary" htmlType="submit">提交</Button>
</Col>
<Col fixed>
<Button onClick={reSetForm}>重置</Button>
</Col>
</Row>
<Row>
<Col>
Expand Down
3 changes: 3 additions & 0 deletions packages/react-search-select/src/index.tsx
Expand Up @@ -99,6 +99,9 @@ export default function SearchSelect(props: SearchSelectProps) {
useEffect(() => {
if (valueVerify(value)) {
selectedValueChange(value!);
} else {
setSelectedValue([]);
setSelectedLabel('');
}
}, [JSON.stringify(value)]);

Expand Down

0 comments on commit d11d652

Please sign in to comment.