Skip to content

Conversation

@EmilyyyLiu
Copy link
Contributor

@EmilyyyLiu EmilyyyLiu commented Jul 14, 2025

增加 IME 组合输入时候,Enter键判断调用

Summary by CodeRabbit

  • Bug Fixes

    • 修复了在输入法(IME)输入过程中,按下回车键时会错误触发回车事件的问题。
  • Tests

    • 新增了针对输入法(IME)输入和回车事件的测试用例,确保输入法输入时回车事件的正确处理。

@coderabbitai
Copy link

coderabbitai bot commented Jul 14, 2025

Walkthrough

本次变更在 Input 组件的 handleKeyDown 方法中,增加了对输入法(IME)组合输入状态的判断,避免在输入法组合期间按下 Enter 键时触发 onPressEnter 回调。同时,新增了相关单元测试以覆盖 IME 场景下的行为。

Changes

文件 变更摘要
src/Input.tsx handleKeyDown 内增加对 isComposing 的判断,防止 IME 组合输入时触发 onPressEnter
tests/index.test.tsx 新增“Input IME behavior”测试块,覆盖 IME 组合输入期间 Enter 键行为的测试。

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant InputComponent
    participant onPressEnter

    User->>InputComponent: 开始组合输入 (compositionStart)
    User->>InputComponent: 按下 Enter (isComposing = true)
    InputComponent--x onPressEnter: 不触发回调

    User->>InputComponent: 结束组合输入 (compositionEnd)
    User->>InputComponent: 再次按下 Enter (isComposing = false)
    InputComponent->>onPressEnter: 触发回调
Loading

Possibly related PRs

Suggested reviewers

  • afc163

Poem

小兔子敲键盘,输入法跳舞间,
组合输入不慌乱,Enter 不再误触发。
测试覆盖添保障,代码清晰如春芽。
🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/Input.tsx

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the config "prettier" to extend from. Please check that the name of the config is correct.

The config "prettier" was referenced from the config file in "/.eslintrc.js".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.

tests/index.test.tsx

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the config "prettier" to extend from. Please check that the name of the config is correct.

The config "prettier" was referenced from the config file in "/.eslintrc.js".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@afc163
Copy link
Member

afc163 commented Jul 14, 2025

解决什么问题?

@EmilyyyLiu
Copy link
Contributor Author

解决什么问题?

ant-design/ant-design#54214 这个问题

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
tests/index.test.tsx (1)

4-4: 删除未使用的导入

ElementType 导入在文件中没有使用,应该删除以保持代码整洁。

-import React, { ElementType } from 'react';
+import React from 'react';
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1d77d2d and e4b1e08.

📒 Files selected for processing (2)
  • src/Input.tsx (1 hunks)
  • tests/index.test.tsx (2 hunks)
🔇 Additional comments (2)
src/Input.tsx (1)

163-168: IME组合输入判断逻辑正确!

新增的 !e.nativeEvent.isComposing 条件能够有效防止在输入法组合输入期间触发 onPressEnter 回调,这是处理IME输入的标准做法,实现符合预期。

tests/index.test.tsx (1)

508-543: IME行为测试覆盖全面!

新增的测试套件很好地覆盖了IME场景:

  • 第一个测试准确模拟了IME组合过程中的事件序列,验证了在组合期间Enter键不会触发onPressEnter
  • 第二个测试使用userEvent模拟真实的用户输入行为,确保正常情况下功能正常工作

测试用例设计合理,能够有效验证IME判断逻辑的正确性。

@codecov
Copy link

codecov bot commented Jul 15, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.70%. Comparing base (1d77d2d) to head (e4b1e08).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #125      +/-   ##
==========================================
+ Coverage   97.66%   97.70%   +0.04%     
==========================================
  Files           4        4              
  Lines         214      218       +4     
  Branches       78       84       +6     
==========================================
+ Hits          209      213       +4     
  Misses          5        5              

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@zombieJ zombieJ merged commit f1b2385 into react-component:master Jul 15, 2025
7 checks passed
@EmilyyyLiu EmilyyyLiu deleted the input-IME branch July 15, 2025 06:28
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.

3 participants