Skip to content

Commit

Permalink
fix(pagination-nav): enforce a minimum of 4 items shown (#18015)
Browse files Browse the repository at this point in the history
* fix(pagination-nav): enforce a minimum of 4 items shown

* docs(pagination-nav): clarify minimum
  • Loading branch information
janhassel authored Nov 8, 2024
1 parent 43272b5 commit bceb0a0
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/react/src/components/PaginationNav/PaginationNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ interface PaginationNavProps
disableOverflow?: boolean;

/**
* The number of items to be shown.
* The number of items to be shown (minimum of 4 unless props.items < 4).
*/
itemsShown?: number;

Expand Down Expand Up @@ -398,8 +398,8 @@ const PaginationNav = React.forwardRef<HTMLElement, PaginationNavProps>(

// re-calculate cuts if props.totalItems or props.itemsShown change
useEffect(() => {
setItemsDisplayedOnPage(itemsShown >= 4 ? itemsShown : 4);
setCuts(calculateCuts(currentPage, totalItems, itemsShown));
setItemsDisplayedOnPage(Math.max(itemsShown, 4));
setCuts(calculateCuts(currentPage, totalItems, Math.max(itemsShown, 4)));
}, [totalItems, itemsShown]); // eslint-disable-line react-hooks/exhaustive-deps

// update cuts if necessary whenever currentPage changes
Expand Down Expand Up @@ -622,7 +622,7 @@ PaginationNav.propTypes = {
disableOverflow: PropTypes.bool, // eslint-disable-line react/prop-types

/**
* The number of items to be shown.
* The number of items to be shown (minimum of 4 unless props.items < 4).
*/
itemsShown: PropTypes.number,

Expand Down

0 comments on commit bceb0a0

Please sign in to comment.