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]Select.AutoComplete与Field混合使用时无法在重置Field后正确重置可选项 #4873

Closed
zqh971026 opened this issue Jun 27, 2024 · 6 comments · Fixed by #4914
Assignees
Labels
🐞 Bug Something isn't working 💬 Discussion Next release issues to close in next release

Comments

@zqh971026
Copy link

Component

Select

Reproduction link

https://hitu.antgroup-inc.cn/codeblocks/f2bece99

Code

import React from 'react';
import { createRoot } from 'react-dom/client';
import { Button, Field, Form, Select } from '@alifd/next';
import '@alifd/next/dist/next.css';

const dataSource = ['a', 'b', 'c', 'd'].map((item) => ({
  label: item,
  value: item,
}));

const App = () => {
  const field = Field.useField();
  return (
    <div>
      <Form field={field}>
        <Form.Item label="Test">
          <Select.AutoComplete name="test" dataSource={dataSource} />
        </Form.Item>
      </Form>
      <Button onClick={() => field.resetToDefault()}>Reset</Button>
    </div>
  );
};

createRoot(document.getElementById('root')!).render(<App />);

Steps to reproduce

在Select中选择"a" -> 点击下方的Reset按钮 -> 重新点击Select,此时可选项只有"a"

Copy link

这是您为 Fusion/Next 提的第一个 issue,感谢您对 Fusion 的信任和支持,我们会尽快进行处理。

@eternalsky
Copy link
Contributor

重置只会重置值,而不会重置其他属性。如果需要联动重置值,可以在调 reset 的时候自己把 dataSource 重置回来。

@zqh971026
Copy link
Author

上述例子中,<Select.AutoComplete />中传入的dataSource是固定的:

[
  {label: 'a', value: 'a'},
  {label: 'b', value: 'b'},
  {label: 'c', value: 'c'},
  {label: 'd', value: 'd'}
]

可选项的展示筛选是组件自行完成的,值重置后,应该会展示全部可选项才对。

@zqh971026
Copy link
Author

@eternalsky

@eternalsky eternalsky added the 🐞 Bug Something isn't working label Jul 16, 2024
@eternalsky eternalsky added the Next release issues to close in next release label Jul 29, 2024
@zizairufengLT
Copy link
Collaborator

@zqh971026

目前快速的解决方法有两种:

  1. 如果你的数据源不会变的话,推荐用children属性传入数据
<Select.AutoComplete name="test">
    <Select.Option value={1}>1</Select.Option>
    <Select.Option value={2}>2</Select.Option>
</Select.AutoComplete>
  1. 如果数据源会动态变化的话,推荐用dataSource属性动态渲染数据,上述的代码可以将dataSource数组移到组件内
const App = () => {
  const dataSource = ['a', 'b', 'c', 'd'].map((item) => ({
    label: item,
    value: item,
  }));
  const field = Field.useField();
  return (
    <div>
      <Form field={field}>
        <Form.Item label="Test">
          <Select.AutoComplete name="test" dataSource={dataSource} />
        </Form.Item>
      </Form>
      <Button onClick={() => field.resetToDefault()}>Reset</Button>
    </div>
  );
};

createRoot(document.getElementById('root')!).render(<App />)

下个版本这个问题应该会修复,可以关注下

@GCHHCG GCHHCG assigned GCHHCG and unassigned GCHHCG Aug 16, 2024
@zizairufengLT zizairufengLT self-assigned this Aug 17, 2024
@eternalsky
Copy link
Contributor

fix in 1.27.23, https://hitu.antgroup-inc.cn/codeblocks/c1b98471

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 Bug Something isn't working 💬 Discussion Next release issues to close in next release
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants