-
-
Notifications
You must be signed in to change notification settings - Fork 463
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: autoClearSearchValue invalid #949
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
src/Select.tsx
Outdated
@@ -544,7 +544,7 @@ const Select = React.forwardRef( | |||
const newRawValues = Array.from(new Set<RawValueType>([...rawValues, formatted])); | |||
triggerChange(newRawValues); | |||
triggerSelect(formatted, true); | |||
setSearchValue(''); | |||
if(autoClearSearchValue) setSearchValue(''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
建议改为
if(autoClearSearchValue){
setSearchValue('');
}
现在这样写不利于维护
@vaynevayne 辛苦添加一下test case |
Codecov Report
@@ Coverage Diff @@
## master #949 +/- ##
=======================================
Coverage 99.63% 99.63%
=======================================
Files 37 37
Lines 1356 1357 +1
Branches 393 394 +1
=======================================
+ Hits 1351 1352 +1
Misses 4 4
Partials 1 1
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
@BoyYangzai 你好 请问这个 pr 进度如何了, 业务那边比较着急 |
召唤豆酱 @zombieJ |
@@ -544,7 +544,9 @@ const Select = React.forwardRef( | |||
const newRawValues = Array.from(new Set<RawValueType>([...rawValues, formatted])); | |||
triggerChange(newRawValues); | |||
triggerSelect(formatted, true); | |||
setSearchValue(''); | |||
if(autoClearSearchValue) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我给这两个 case 打了断点,不会跑到这里。确认一下是否是搞错地方了?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在这里回复了:ant-design/ant-design#42933 (comment)
|
看这个 pr, 失去焦点也有问题 |
@zombieJ 按照我那个debug 步骤走一下就能复现, 讲道理你两处以 type submit 来调用的判断方式不一样 if (which === KeyCode.ENTER /**here */ && mode === 'tags' && !compositionStatusRef.current && !open) {
// When menu isn't open, OptionList won't trigger a value change
// So when enter is pressed, the tag's input value should be emitted here to let selector know
onSearchSubmit?.((event.target as HTMLInputElement).value);
} const onContainerBlur: React.FocusEventHandler<HTMLElement> = (...args) => {
...
if (mergedSearchValue) {
// `tags` mode should move `searchValue` into values
if (mode === 'tags') {
onSearch(mergedSearchValue, { source: 'submit' }); // here
}
} 我有点不太理解, 为什么两段 type=submit 的判断逻辑不一致, 一个需要key===enter, 一个只需要 blur 即可(这也是导致我使用 searchValue 和 onSearch 会引出性 bug 的逻辑) |
|
我按 enter 键,你把搜索值放到 options 里还正常, 问题是 blur 时为什么也要放入 options, 我觉得我觉得我描述的场景够清楚了 我也知道你的意思了,永远不会处理这个问题罢了 |
这是两个问题:
我理解这是个 XY 问题,真实要解的应该是交互设计,而不是给 https://codesandbox.io/s/duo-xuan-antd-5-6-1-forked-64q66p?file=/demo.tsx |
resolve #947