Skip to content

Commit

Permalink
fix(paginator): delete number 1 from input (#103)
Browse files Browse the repository at this point in the history
* fix(paginator): delete number 1 from input

* fix(paginator): fixs from comments

* fix(paginator): fixs from comments

* fix(paginator): fix in siglequotes
  • Loading branch information
malegreIndec authored Jan 30, 2024
1 parent 7756528 commit 3629830
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/components/Pagination/Pagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ const Pagination = ({
const [search, setSearch] = useState(currentPage);
const hasArrowRight = Math.max(...pages) < totalPages;
const hasArrowLeft = Math.min(...pages) > 1;
const handleChangeInput = value => setSearch(parseInt(value, 10));

const handleChangeInput = value => setSearch(Number(value) || '');

const handleMoveLeft = () => {
const pagesNumbers = getPagesNumber(pages);
Expand Down Expand Up @@ -58,6 +59,8 @@ const Pagination = ({
}
};

const handleBlur = () => !Number.isNaN(search) && setSearch(1);

useEffect(() => {
setPages(getPagesRange(null, currentPage, totalPages) || []);
}, [totalPages]);
Expand Down Expand Up @@ -115,8 +118,10 @@ const Pagination = ({
min={1}
max={totalPages}
onChange={handleChangeInput}
value={!Number.isNaN(search) ? search : 1}
defaultValue={1}
value={!Number.isNaN(search) ? search : undefined}
onKeyDown={handleKeyDown}
onBlur={handleBlur}
>
<NumberInputField p="0 10px" data-testid="input"/>
</NumberInput>
Expand Down

0 comments on commit 3629830

Please sign in to comment.