Skip to content

Commit d11d652

Browse files
authoredApr 12, 2022
fix(SeachSelect): 修复Form中使用没有赋值initialValue情况下无法重置 #760 (#763)
1 parent 15d151f commit d11d652

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed
 

‎packages/react-search-select/README.md

+9
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ const Demo = () => {
411411
];
412412
const [option, setOption] = React.useState(selectOption);
413413
const [loading, setLoading] = React.useState(false);
414+
const refForm = React.useRef()
414415

415416
function handleSearch(e) {
416417
setLoading(true)
@@ -421,9 +422,14 @@ const Demo = () => {
421422
}, 500);
422423
}
423424

425+
const reSetForm = () => {
426+
console.log('form', refForm.current.resetForm())
427+
}
428+
424429
return (
425430
<div>
426431
<Form
432+
ref={refForm}
427433
onSubmitError={(error) => {
428434
if (error.filed) {
429435
return { ...error.filed };
@@ -500,6 +506,9 @@ const Demo = () => {
500506
<Col fixed>
501507
<Button disabled={!canSubmit()} type="primary" htmlType="submit">提交</Button>
502508
</Col>
509+
<Col fixed>
510+
<Button onClick={reSetForm}>重置</Button>
511+
</Col>
503512
</Row>
504513
<Row>
505514
<Col>

‎packages/react-search-select/src/index.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ export default function SearchSelect(props: SearchSelectProps) {
9999
useEffect(() => {
100100
if (valueVerify(value)) {
101101
selectedValueChange(value!);
102+
} else {
103+
setSelectedValue([]);
104+
setSelectedLabel('');
102105
}
103106
}, [JSON.stringify(value)]);
104107

0 commit comments

Comments
 (0)
Please sign in to comment.