Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

select onSearch第一次促发查询出列表数据后,选中一个option,然后重新输入查询,这次没有查出数据, 此时失去焦点期望select为空,但实际上却是第一次选中的值 #16310

Closed
1 task
hualinIT opened this issue Apr 25, 2019 · 7 comments
Assignees
Labels
🤔 Need Reproduce We cannot reproduce your problem

Comments

@hualinIT
Copy link

hualinIT commented Apr 25, 2019

  • I have searched the issues of this repository and believe that this is not a duplicate.

Reproduction link

https://codesandbox.io/embed/n94yx206rl

Steps to reproduce

  1. select onSearch 输入查询条件,查询出数据, 选中一条数据的option
  2. 此时调用接口,返回的数据为空数组, 没有option
  3. select框此时失去焦点, 发现select框的值恢复成了第一次选中的值

What is expected?

期望 步骤3的值为空

What is actually happening?

实际结果恢复成步骤1选中的值了

Environment Info
antd 2.13.14
React 16.2.0
System mac
Browser 73.0.3683.103
@ant-design-bot
Copy link
Contributor

Hello @hualinIT. Please provide a online reproduction by forking this link https://u.ant.design/codesandbox-repro or a minimal GitHub repository. Issues labeled by Need Reproduce will be closed if no activities in 7 days.

你好 @hualinIT, 我们需要你提供一个在线的重现实例以便于我们帮你排查问题。你可以通过点击 此处 创建一个 codesandbox 或者提供一个最小化的 GitHub 仓库。7 天内未跟进的 issue 将会被自动关闭。

@zombieJ zombieJ added the 🤔 Need Reproduce We cannot reproduce your problem label Apr 25, 2019
@XianZhengquan
Copy link
Contributor

我的也是这个情况

@XianZhengquan
Copy link
Contributor

repo: https://codesandbox.io/embed/xvox9o3zlz
输入 a 等待 1S,选择 a
再输入其他的,然后失焦

@zombieJ
Copy link
Member

zombieJ commented Apr 26, 2019

value 是受控属性。如果设置了 value,无论是否 Option 里是否有这个值都会展示它。它就是 Select 的值。

@zombieJ zombieJ closed this as completed Apr 26, 2019
@hualinIT
Copy link
Author

@hualinIT
Copy link
Author

value 是受控属性。如果设置了 value,无论是否 Option 里是否有这个值都会展示它。它就是 Select 的值。

@zombieJ 要怎么处理它使它失去焦点为空呢,而不是恢复成以前的选中的值 https://codesandbox.io/embed/xvox9o3zlz

@afc163
Copy link
Member

afc163 commented Apr 26, 2019

  function handleSearch(val) {
    if (val === "a") {
      setTimeout(() => {
        setOptions([{ label: "a", value: "a" }]);
      }, 1000);
    } else {
      setOptions([]);
+     setValue(undefined);
    }
  }

https://codesandbox.io/s/n94yx206rl

@afc163 afc163 reopened this Apr 26, 2019
@afc163 afc163 closed this as completed Apr 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤔 Need Reproduce We cannot reproduce your problem
Projects
None yet
Development

No branches or pull requests

5 participants