Skip to content

Conversation

EmilyyyLiu
Copy link
Contributor

@EmilyyyLiu EmilyyyLiu commented Jul 15, 2025

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

close ant-design/ant-design#54214

Summary by CodeRabbit

  • Bug Fixes

    • 修复了在使用输入法(IME)组合输入时,按下回车键不会错误触发 onPressEnter 回调的问题。
  • Tests

    • 新增了针对输入法(IME)组合输入和回车键处理的测试用例,确保 onPressEnter 行为符合预期。
  • Chores

    • 升级了依赖 @rc-component/input 至 ~1.1.0。

Copy link

coderabbitai bot commented Jul 15, 2025

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (1)
  • tests/__snapshots__/allowClear.test.tsx.snap is excluded by !**/*.snap

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

"""

Walkthrough

本次更改主要针对 TextArea 组件的回车键(Enter)事件处理进行了优化,确保在输入法(IME)组合输入阶段不会误触发 onPressEnter 回调。同时,更新了相关依赖版本,并新增了针对 IME 行为的测试用例。

Changes

文件/文件组 变更摘要
package.json @rc-component/input 依赖版本由 ~1.0.0 升级为 ~1.1.0
src/TextArea.tsx handleKeyDown 函数增加对 isComposing 的判断,避免组合输入时触发 onPressEnter
tests/index.spec.tsx 新增“TextArea IME 行为”测试用例,覆盖 IME 组合输入与普通输入场景。

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant TextArea
    participant IME
    participant App

    User->>TextArea: 按下任意键
    TextArea->>IME: 检查是否为组合输入
    alt 组合输入中 (isComposing = true)
        User->>TextArea: 按下 Enter
        TextArea--xApp: 不触发 onPressEnter
    else 组合输入结束 (isComposing = false)
        User->>TextArea: 按下 Enter
        TextArea->>App: 触发 onPressEnter
    end
Loading

Assessment against linked issues

Objective Addressed Explanation
IME 输入法下,只有在组合输入结束后再按 Enter 时才触发 onPressEnter(#54214)
新增自动化测试覆盖 IME 组合输入与 Enter 键的行为(#54214)

Poem

兔子键盘轻轻敲,
输入法下不乱跑。
组合输入不触发,
回车确认才来到。
新测试护航保,
代码升级步步高!
(づ。◕‿‿◕。)づ
"""

✨ Finishing Touches
🧪 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.

Copy link

socket-security bot commented Jul 15, 2025

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updated@​rc-component/​input@​1.0.1 ⏵ 1.1.079 +110010089 +7100

View full report

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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 97237a7 and 60f0d79.

📒 Files selected for processing (3)
  • package.json (1 hunks)
  • src/TextArea.tsx (1 hunks)
  • tests/index.spec.tsx (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
tests/index.spec.tsx

[error] 385-385: Don't focus the test.

The 'only' method is often used for debugging or during implementation. It should be removed before deploying to production.
Consider removing 'only' to ensure all tests are executed.
Unsafe fix: Remove focus from test.

(lint/suspicious/noFocusedTests)

🔇 Additional comments (4)
package.json (1)

47-47: 手动验证 @rc-component/[email protected] 的 IME 功能支持

自动检查结果:

  • npm 上已发布 @rc-component/[email protected]
  • README.md 和 CHANGELOG.md 中未找到 “IME”、“composition” 或 “输入法” 相关说明

请手动确认该版本在 TextArea 或 Input 组件中的 IME 支持是否已正确实现,并在发布日志或源码中补充对应文档。

src/TextArea.tsx (1)

157-157: IME 组合输入处理实现正确

通过检查 !e.nativeEvent.isComposing 条件来避免在 IME 组合输入期间触发 onPressEnter 回调,这个实现完全符合预期需求。使用标准的 DOM API 确保了跨浏览器的兼容性。

tests/index.spec.tsx (2)

386-410: IME 组合输入测试用例设计完善

测试用例正确模拟了 IME 组合输入的完整流程:

  1. compositionStart 开始组合
  2. 带有 isComposing: true 的 Enter 键按下
  3. compositionUpdate 更新组合内容
  4. 验证 onPressEnter 未被调用
  5. compositionEnd 结束组合后的正常 Enter 键处理

这个测试完全覆盖了新功能的核心场景。


412-424: 正常输入测试用例补充必要

为 IME 功能添加正常输入场景的测试是很好的实践,确保新功能不会影响现有的正常输入行为。测试逻辑清晰且覆盖充分。

@zombieJ zombieJ requested a review from Copilot July 15, 2025 06:20
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds IME handling for the Enter key to prevent onPressEnter from firing during composition, includes new tests for this behavior, and upgrades a dependency.

  • Prevent onPressEnter during IME composition by checking e.nativeEvent.isComposing
  • Add tests verifying Enter is ignored during composition and fires after composition ends
  • Bump @rc-component/input dependency to ~1.1.0

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/TextArea.tsx Skip onPressEnter when nativeEvent.isComposing is true
tests/index.spec.tsx New tests for IME composition behavior around Enter key
package.json Upgrade @rc-component/input from ~1.0.0 to ~1.1.0
Comments suppressed due to low confidence (2)

src/TextArea.tsx:157

  • [nitpick] Consider adding an inline comment explaining that the !e.nativeEvent.isComposing check prevents onPressEnter from firing during IME composition, for future maintainers.
      if (e.key === 'Enter' && onPressEnter && !e.nativeEvent.isComposing) {

package.json:47

  • After bumping the dependency version in package.json, please update the corresponding lockfile (e.g., yarn.lock or package-lock.json) to ensure CI and local installs use the intended version.
    "@rc-component/input": "~1.1.0",

Copy link

codecov bot commented Jul 15, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.03%. Comparing base (97237a7) to head (0ed3741).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master      #71   +/-   ##
=======================================
  Coverage   99.03%   99.03%           
=======================================
  Files           3        3           
  Lines         208      208           
  Branches       64       64           
=======================================
  Hits          206      206           
  Misses          2        2           

☔ 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 7599531 into react-component:master Jul 15, 2025
7 checks passed
@EmilyyyLiu EmilyyyLiu deleted the keydown-isComposing branch July 15, 2025 06:27
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.

Support handling Enter key properly in IME (e.g. Japanese input) in Input / TextArea
2 participants