Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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 @@ -248,6 +248,7 @@ const Pagination: React.FC<PaginationProps> = (props) => {
callback,
...restParams
) {
event.preventDefault();
if (
event.key === 'Enter' ||
event.charCode === KeyCode.ENTER ||
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