-
-
Notifications
You must be signed in to change notification settings - Fork 329
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: block default events for the enter key #562
base: master
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
请添加测试用例 |
这个用例并不cover你这个case |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #562 +/- ##
=======================================
Coverage 98.70% 98.71%
=======================================
Files 3 3
Lines 310 311 +1
Branches 137 137
=======================================
+ Hits 306 307 +1
Misses 4 4 ☔ View full report in Codecov by Sentry. |
已加 |
@@ -569,6 +569,24 @@ describe('keyboard support', () => { | |||
|
|||
expect(onChange).toHaveBeenLastCalledWith(60, 10); | |||
}); | |||
|
|||
it('should work for enter key', () => { |
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.
无修复代码的情况下,这个用例仍然通过的
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.
对于单元测试能否还原按下enter键除了键盘事件执行还执行点击事件我不太确定
当点击下一页后按下enter键,预期是出现页数加一,但实际按下enter键除了会触发键盘事件还会默认触发元素的点击事件,所以会出现页数加二的情况,反之点击上一页然后按下enter键也是如此,页数会减二而不是预期的减一,最直接的解决办法是
event.preventDefault
阻止默认事件即可,但是也会想到即使不写键盘事件,点击下一页,此时元素已经获取到焦点,此时按下enter键也会默认触发元素的点击事件,达到页数加一的效果,那么写键盘事件是否是冗余代码?翻看了业内比较知名的mui与element-plus,似乎他们并没有专门关照enter键盘事件close ant-design/ant-design#47531