-
Notifications
You must be signed in to change notification settings - Fork 40
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: fix error when pass disabled and press enter. #81
fix: fix error when pass disabled and press enter. #81
Conversation
Walkthrough此次更改主要集中在 Changes
Assessment against linked issues
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (2)
src/Input.tsx (2)
Line range hint
169-174
: 需要在 handleBlur 中重置 keyLockRef根据 PR 的目标,当输入框失去焦点时应该重置 keyLockRef,但当前实现中缺少这个逻辑。这可能导致在某些场景下 onPressEnter 事件仍然无法正常触发。
建议在 handleBlur 函数中添加重置逻辑:
const handleBlur: React.FocusEventHandler<HTMLInputElement> = (e) => { setFocused(false); + keyLockRef.current = false; onBlur?.(e); };
🧰 Tools
🪛 Biome
[error] 97-97: The assignment should not be in an expression.
The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.(lint/suspicious/noAssignInExpressions)
🪛 eslint
[error] 97-97: Expected an assignment or function call and instead saw an expression.
(@typescript-eslint/no-unused-expressions)
Line range hint
40-42
: 建议添加状态管理相关的代码注释组件使用了多个 ref 来管理不同的状态(compositionRef, keyLockRef),建议添加注释说明每个 ref 的具体用途和状态转换逻辑,以提高代码的可维护性。
建议添加如下注释:
+ // 用于追踪 IME 输入状态 const compositionRef = useRef(false); + // 用于防止重复触发 Enter 键事件 const keyLockRef = useRef(false);🧰 Tools
🪛 Biome
[error] 97-97: The assignment should not be in an expression.
The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.(lint/suspicious/noAssignInExpressions)
🪛 eslint
[error] 97-97: Expected an assignment or function call and instead saw an expression.
(@typescript-eslint/no-unused-expressions)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
src/Input.tsx
(1 hunks)
🧰 Additional context used
🪛 Biome
src/Input.tsx
[error] 97-97: The assignment should not be in an expression.
The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.
(lint/suspicious/noAssignInExpressions)
🪛 eslint
src/Input.tsx
[error] 97-97: Expected an assignment or function call and instead saw an expression.
(@typescript-eslint/no-unused-expressions)
🔇 Additional comments (1)
src/Input.tsx (1)
Line range hint 126-131
: 组合输入事件处理逻辑正确
针对 IME 输入重复触发的问题(#46587)的修复方案是合理的。通过在组合输入结束时提前返回,可以有效避免重复触发事件。
🧰 Tools
🪛 Biome
[error] 97-97: The assignment should not be in an expression.
The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.
(lint/suspicious/noAssignInExpressions)
🪛 eslint
[error] 97-97: Expected an assignment or function call and instead saw an expression.
(@typescript-eslint/no-unused-expressions)
Test case is needed. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #81 +/- ##
==========================================
+ Coverage 92.20% 92.34% +0.14%
==========================================
Files 5 5
Lines 218 222 +4
Branches 77 79 +2
==========================================
+ Hits 201 205 +4
Misses 17 17 ☔ View full report in Codecov by Sentry. |
Added. |
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.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (1)
tests/index.test.tsx (1)
77-87
: 测试用例基本合理,建议增强验证测试用例验证了禁用状态切换后
onPressEnter
的行为,这是个很好的边界场景测试。建议增加以下改进:
- 添加对
disabled
状态的断言- 验证输入框的实际状态变化
建议按如下方式增强测试:
it('should trigger onPressEnter after disabled', () => { const onPressEnter = jest.fn(); const { container, rerender } = render( <Input onPressEnter={onPressEnter} />, ); const inputEl = container.querySelector('input')!; + expect(inputEl.disabled).toBe(false); fireEvent.keyDown(inputEl, { key: 'Enter' }); rerender(<Input onPressEnter={onPressEnter} disabled={true} />); + expect(inputEl.disabled).toBe(true); fireEvent.keyDown(inputEl, { key: 'Enter' }); expect(onPressEnter).toBeCalledTimes(2); + expect(inputEl).toBeDisabled(); });
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
src/Input.tsx
(2 hunks)tests/index.test.tsx
(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- src/Input.tsx
🔇 Additional comments (1)
tests/index.test.tsx (1)
63-75
: 测试用例设计合理!
该测试用例很好地验证了失焦后 onPressEnter
事件的触发行为,完全符合修复需求。测试结构清晰,断言准确。
@afc163 Can you take a look? |
Resolve: #79
Summary by CodeRabbit