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

Fix:Input-Password onVisibleChange #46558

Closed

Conversation

Eloi0424
Copy link
Contributor

[中文版模板 / Chinese template]

🤔 This is a ...

  • New feature
  • Bug fix
  • Site / documentation update
  • Demo update
  • Component style update
  • TypeScript definition update
  • Bundle size optimization
  • Performance optimization
  • Enhancement feature
  • Internationalization
  • Refactoring
  • Code style optimization
  • Test Case
  • Branch merge
  • Workflow
  • Other (about what?)

🔗 Related issue link

💡 Background and solution

问题:input.password 在 由 icon 控制时 onVisibleChange 回调会被触发,而由外部控件控制visible 时,不会触发回调。
复现链接

解决办法:
使用useEffect 在当 visbleChange 后 回调函数,符合语义

📝 Changelog

我的理解onVisibleChange 回调 本来就不应该在“onVisibleChange” 点击事件处理函数里调用,
源码里的“onVisibleChange” 函数是 icon 的点击处理

Language Changelog
🇺🇸 English Fixed onVisibleChange callback for issues that cannot be motivated by visible switch controls other than icon
🇨🇳 Chinese 修正onVisibleChange回调,无法被除icon 以外的visible switch 控件 激发的问题

☑️ Self-Check before Merge

⚠️ Please check all items below before requesting a reviewing. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • TypeScript definition is updated/provided or not needed
  • Changelog is provided or not needed

Copy link

stackblitz bot commented Dec 21, 2023

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link
Contributor

github-actions bot commented Dec 21, 2023

Preview Is ready

Copy link
Contributor

github-actions bot commented Dec 21, 2023

Visual Regression Report for PR #46558 Passed ✅

Target branch: master (eff7208)


Congrats! No visual-regression diff found

@MadCcc
Copy link
Member

MadCcc commented Dec 21, 2023

onChange 不应该监听 value 本身,会形成死循环

Copy link

codesandbox-ci bot commented Dec 21, 2023

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit c962526:

Sandbox Source
antd reproduction template (forked) Configuration

@Eloi0424
Copy link
Contributor Author

onChange 不应该监听 value 本身,会形成死循环

我的理解这不应该是用户需要关注的点吗?
”不能在onChange里加监听对象的修改“?
这样改应该是符合语义的?

Copy link

codecov bot commented Dec 21, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (eff7208) 100.00% compared to head (c962526) 100.00%.
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master    #46558   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          708       708           
  Lines        12120     12121    +1     
  Branches      3217      3217           
=========================================
+ Hits         12120     12121    +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@MadCcc
Copy link
Member

MadCcc commented Dec 21, 2023

不是符合语义的问题,所有 onChange 方法都应该由内部逻辑触发,而不是监听受控属性变化

@Eloi0424
Copy link
Contributor Author

不是符合语义的问题,所有 onChange 方法都应该由内部逻辑触发,而不是监听受控属性变化

已修改。
还是说本来外部控件修改visible,本来就不该触发回调,这不是个bug?

@afc163
Copy link
Member

afc163 commented Dec 21, 2023

你可以试试 <input value={value} onChange={e => setValue(e.target.value)} /> 原生组件。

如果控制 value 也会触发 onChange,就死循环了。

@Eloi0424 Eloi0424 closed this Dec 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants