Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

selicens
Copy link

@selicens selicens commented Feb 21, 2024

当点击下一页后按下enter键,预期是出现页数加一,但实际按下enter键除了会触发键盘事件还会默认触发元素的点击事件,所以会出现页数加二的情况,反之点击上一页然后按下enter键也是如此,页数会减二而不是预期的减一,最直接的解决办法是event.preventDefault阻止默认事件即可,但是也会想到即使不写键盘事件,点击下一页,此时元素已经获取到焦点,此时按下enter键也会默认触发元素的点击事件,达到页数加一的效果,那么写键盘事件是否是冗余代码?翻看了业内比较知名的mui与element-plus,似乎他们并没有专门关照enter键盘事件

close ant-design/ant-design#47531

Copy link

vercel bot commented Feb 21, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
pagination ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 22, 2024 8:50am

@yoyo837
Copy link
Member

yoyo837 commented Feb 22, 2024

请添加测试用例

@selicens
Copy link
Author

请添加测试用例

1708566250623
这个本身就有测试用例了,没必要再写一个吧

@yoyo837
Copy link
Member

yoyo837 commented Feb 22, 2024

这个用例并不cover你这个case

Copy link

codecov bot commented Feb 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (b89cb0e) 98.70% compared to head (0c9b4e7) 98.71%.

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.
📢 Have feedback on the report? Share it here.

@selicens
Copy link
Author

这个用例并不cover你这个case

已加

@@ -569,6 +569,24 @@ describe('keyboard support', () => {

expect(onChange).toHaveBeenLastCalledWith(60, 10);
});

it('should work for enter key', () => {
Copy link
Member

Choose a reason for hiding this comment

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

无修复代码的情况下,这个用例仍然通过的

Copy link
Author

Choose a reason for hiding this comment

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

对于单元测试能否还原按下enter键除了键盘事件执行还执行点击事件我不太确定

src/Pagination.tsx Outdated Show resolved Hide resolved
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.

pagination点击下一页后按下Enter键页数会加二
3 participants