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

[Checkbox.Group]:checkbox.group jsx 和options 两种渲染下 onchange 回调值不一致 #2017

Closed
gavin-hao opened this issue May 18, 2022 · 0 comments
Labels
🐛 bug Something isn't working

Comments

@gavin-hao
Copy link
Contributor

Describe the bug
以下两种方式 当依次点击 A-C-B 时 第三次onchange 结果 分别是 [1,2,3] - [1,3,2];期望 始终为[1,2,3]

const Demo = () => <Checkbox.Group onChange={(e) => {
      mockChange(e);
    }} options={[{ value: 1, label: 'A' }, { value: 2, label: 'B' }, { value: 3, label: 'C' }]} />
<Checkbox.Group onChange={(e) => {
        mockChange(e);
        setVal(e);
      }} value={val}>
        <Checkbox value={1}>A</Checkbox>
        <Checkbox value={2}>B</Checkbox>
        <Checkbox value={3}>C</Checkbox>
      </Checkbox.Group>

错误原因为:

 const opts = getOptions();
    onChange?.(
      newValue
        .filter((val) => registeredValues.indexOf(val) !== -1)
        .sort((a, b) => {
          const indexA = opts.findIndex((opt) => opt.value === a);
          const indexB = opts.findIndex((opt) => opt.value === b);
          return indexA - indexB;
        })
    );

getOptions 方法没有收集JSX写法的 props

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

@gavin-hao gavin-hao added the 🐛 bug Something isn't working label May 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants