Skip to content

Commit

Permalink
Pagination: pagination input sanitizes decimal values (#452)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoorayimhelping authored Jul 25, 2024
1 parent a83228a commit 4e0a802
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
17 changes: 17 additions & 0 deletions src/components/Pagination/Pagination.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useState } from "react";
import { Pagination } from "./Pagination";

export default {
Expand All @@ -11,9 +12,25 @@ export default {
},
};

const PaginationRenderer = () => {
const [currentPage, setCurrentPage] = useState<number>(1);

const handleChange = (page: number) => {
setCurrentPage(page);
};

return (
<Pagination
currentPage={currentPage}
onChange={handleChange}
/>
);
};

export const Playground = {
args: {
currentPage: 1,
options: [250, 500],
},
render: () => <PaginationRenderer />,
};
8 changes: 4 additions & 4 deletions src/components/Pagination/Pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,16 @@ export const Pagination = ({
};

const onChange = (value: string) => {
const valueToNumber = Number(value);
const sanitizedValue = parseInt(value, 10);
if (
valueToNumber < 1 ||
sanitizedValue < 1 ||
inputRef.current?.disabled ||
(typeof totalPages !== "undefined" ? valueToNumber > totalPages : false)
(typeof totalPages !== "undefined" ? sanitizedValue > totalPages : false)
) {
return;
}

onChangeProp(valueToNumber);
onChangeProp(sanitizedValue);
};

const onPageSizeChange = (value: string) => {
Expand Down

0 comments on commit 4e0a802

Please sign in to comment.