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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ const Pagination: React.FC<PaginationProps> = (props) => {
event.charCode === KeyCode.ENTER ||
event.keyCode === KeyCode.ENTER
) {
event.preventDefault();
callback(...restParams);
}
}
Expand Down
18 changes: 18 additions & 0 deletions tests/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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键除了键盘事件执行还执行点击事件我不太确定

const item50 = $('li.rc-pagination-item-50');
const item51 = $('li.rc-pagination-item-51');
const item52 = $('li.rc-pagination-item-52');
const nextButton = $('li.rc-pagination-next');
const prevButton = $('li.rc-pagination-prev');

expect(item50).toHaveClass('rc-pagination-item-active');
fireEvent.click(nextButton);
expect(item51).toHaveClass('rc-pagination-item-active');
fireEvent.keyDown(nextButton, { key: 'Enter', keyCode: 13, which: 13 });
expect(item52).toHaveClass('rc-pagination-item-active');
fireEvent.click(prevButton);
expect(item51).toHaveClass('rc-pagination-item-active');
fireEvent.keyDown(prevButton, { key: 'Enter', keyCode: 13, which: 13 });
expect(item50).toHaveClass('rc-pagination-item-active');
});
});

describe('select in sequence', () => {
Expand Down
Loading