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} /> )}