From 31e6ef77a61f91c377052d51e3825fe0f85904ed Mon Sep 17 00:00:00 2001 From: Ponder <190127701@qq.com> Date: Tue, 7 Oct 2025 14:20:12 +0800 Subject: [PATCH] feat: optimize the page jump logic to prevent unnecessary jumps. (#26481) Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- web/app/components/base/pagination/index.tsx | 32 ++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/web/app/components/base/pagination/index.tsx b/web/app/components/base/pagination/index.tsx index 8126f663dd..e0c02df253 100644 --- a/web/app/components/base/pagination/index.tsx +++ b/web/app/components/base/pagination/index.tsx @@ -57,7 +57,34 @@ const CustomizedPagination: FC = ({ if (isNaN(Number.parseInt(value))) return setInputValue('') setInputValue(Number.parseInt(value)) - handlePaging(value) + } + + const handleInputConfirm = () => { + if (inputValue !== '' && String(inputValue) !== String(current + 1)) { + handlePaging(String(inputValue)) + return + } + + if (inputValue === '') + setInputValue(current + 1) + + setShowInput(false) + } + + const handleInputKeyDown = (e: React.KeyboardEvent) => { + if (e.key === 'Enter') { + e.preventDefault() + handleInputConfirm() + } + else if (e.key === 'Escape') { + e.preventDefault() + setInputValue(current + 1) + setShowInput(false) + } + } + + const handleInputBlur = () => { + handleInputConfirm() } return ( @@ -105,7 +132,8 @@ const CustomizedPagination: FC = ({ autoFocus value={inputValue} onChange={handleInputChange} - onBlur={() => setShowInput(false)} + onKeyDown={handleInputKeyDown} + onBlur={handleInputBlur} /> )}