fix(select): ignore the Enter that confirms an IME composition#4305
Open
greymoth-jp wants to merge 2 commits into
Open
fix(select): ignore the Enter that confirms an IME composition#4305greymoth-jp wants to merge 2 commits into
greymoth-jp wants to merge 2 commits into
Conversation
Collaborator
TDesign Component Site Preview Open
|
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

🤔 这个 PR 的性质是?
🔗 相关 Issue
无
💡 需求背景和解决方案
Select开启filterable后,在过滤输入框里用输入法(中文 / 日文等)打字时,按 Enter 确认候选词会被当成“选中当前高亮项”,候选词刚上屏就误选了一个选项。原因在
select/hooks/useKeyboardControl.ts的handleKeyDown:它用switch (e.code)判断按键,而e.code在输入法合成期间各浏览器都仍是'Enter',所以确认候选词的那次 Enter 也进入了case 'Enter'的选中分支,并没有判断当前是否处于合成态。同仓库的
TagInput已经处理过同类场景:onInputEnter里用if (!isCompositionRef.current)跳过确认合成的 Enter,避免误加标签。这里沿用相同约定,在case 'Enter'开头加一行if (e.nativeEvent.isComposing) break;,确认候选词的 Enter 不再选中选项,普通 Enter 行为保持不变。另外补了一个测试:filterable 的 Select 下,合成态的 Enter 不会触发
onChange,普通 Enter 仍会选中高亮项。补充说明:本地没能跑通完整测试套件,
packages/common子仓库在我这边没有检出、根工作区还引用了一个缺失的 AIGC 包,pnpm install无法装完。改动只涉及基础组件,逻辑已按代码路径逐处核对,测试也是照现有用例的写法写的,麻烦 CI 跑一下确认。📝 更新日志
tdesign-react
☑️ 请求合并前的自查清单