Skip to content

Commit

Permalink
fix(PaginationNav): add forwardRef (#6647)
Browse files Browse the repository at this point in the history
Co-authored-by: TJ Egan <tw15egan@gmail.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
3 people committed Aug 12, 2020
1 parent c057585 commit 3603c06
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
2 changes: 2 additions & 0 deletions packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4138,6 +4138,7 @@ Map {
},
},
"PaginationNav" => Object {
"$$typeof": Symbol(react.forward_ref),
"propTypes": Object {
"className": Object {
"type": "string",
Expand All @@ -4161,6 +4162,7 @@ Map {
"type": "func",
},
},
"render": [Function],
},
"PrimaryButton" => Object {},
"ProgressIndicator" => Object {
Expand Down
29 changes: 17 additions & 12 deletions packages/react/src/components/PaginationNav/PaginationNav.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,19 @@ function PaginationOverflow({
return null;
}

export default function PaginationNav({
className,
onChange = () => {},
totalItems,
itemsShown = 10,
page = 0,
loop = false,
translateWithId: t = translateWithId,
...rest
}) {
const PaginationNav = React.forwardRef(function PaginationNav(
{
className,
onChange = () => {},
totalItems,
itemsShown = 10,
page = 0,
loop = false,
translateWithId: t = translateWithId,
...rest
},
ref
) {
const [currentPage, setCurrentPage] = useState(page);
const [itemsThatFit, setItemsThatFit] = useState(
itemsShown >= 4 ? itemsShown : 4
Expand Down Expand Up @@ -266,7 +269,7 @@ export default function PaginationNav({
const startOffset = itemsThatFit <= 4 && currentPage > 1 ? 0 : 1;

return (
<nav className={classNames} {...rest} aria-label="pagination">
<nav className={classNames} ref={ref} {...rest} aria-label="pagination">
<ul className={`${prefix}--pagination-nav__list`}>
<DirectionButton
direction="backward"
Expand Down Expand Up @@ -353,7 +356,7 @@ export default function PaginationNav({
</div>
</nav>
);
}
});

DirectionButton.propTypes = {
/**
Expand Down Expand Up @@ -460,3 +463,5 @@ PaginationNav.propTypes = {
*/
translateWithId: PropTypes.func,
};

export default PaginationNav;

0 comments on commit 3603c06

Please sign in to comment.