From ff4beb386f7f981eaea44a1a1658cab44cd6e904 Mon Sep 17 00:00:00 2001 From: ZhouWei <1244620067@qq.com> Date: Wed, 21 Feb 2024 21:42:36 +0800 Subject: [PATCH 1/3] fix: block default events for the enter key --- src/Pagination.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Pagination.tsx b/src/Pagination.tsx index b3c6763c..24504d61 100644 --- a/src/Pagination.tsx +++ b/src/Pagination.tsx @@ -248,6 +248,7 @@ const Pagination: React.FC = (props) => { callback, ...restParams ) { + event.preventDefault(); if ( event.key === 'Enter' || event.charCode === KeyCode.ENTER || From 16883c574f06b73006eb29a4bce0d6f60aa1d790 Mon Sep 17 00:00:00 2001 From: ZhouWei <1244620067@qq.com> Date: Thu, 22 Feb 2024 13:22:31 +0800 Subject: [PATCH 2/3] test: keyboard support enter key event --- tests/index.test.tsx | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/index.test.tsx b/tests/index.test.tsx index a08ed026..b42bae3a 100644 --- a/tests/index.test.tsx +++ b/tests/index.test.tsx @@ -569,6 +569,24 @@ describe('keyboard support', () => { expect(onChange).toHaveBeenLastCalledWith(60, 10); }); + + it('should work for enter key', () => { + 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', () => { From 0c9b4e7a53c40f77a23150b28a87c1160707c554 Mon Sep 17 00:00:00 2001 From: ZhouWei <1244620067@qq.com> Date: Thu, 22 Feb 2024 16:47:58 +0800 Subject: [PATCH 3/3] refactor: consider other keyboard events --- src/Pagination.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Pagination.tsx b/src/Pagination.tsx index 24504d61..60287270 100644 --- a/src/Pagination.tsx +++ b/src/Pagination.tsx @@ -248,12 +248,12 @@ const Pagination: React.FC = (props) => { callback, ...restParams ) { - event.preventDefault(); if ( event.key === 'Enter' || event.charCode === KeyCode.ENTER || event.keyCode === KeyCode.ENTER ) { + event.preventDefault(); callback(...restParams); } }