Skip to content

Commit

Permalink
Merge e67fd5d into 9711de9
Browse files Browse the repository at this point in the history
  • Loading branch information
HalvorHaugan authored Oct 23, 2024
2 parents 9711de9 + e67fd5d commit 22f5051
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/plenty-teachers-admire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@navikt/ds-react": patch
---

Pagination: More precise type for renderItem
22 changes: 16 additions & 6 deletions @navikt/core/react/src/pagination/Pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ import PaginationItem, {
PaginationItemType,
} from "./PaginationItem";

interface RenderItemProps
extends Pick<
PaginationItemProps,
"className" | "disabled" | "selected" | "icon" | "iconPosition"
> {
children: React.ReactNode;
onClick: React.MouseEventHandler<HTMLButtonElement>;
page: number;
size: Exclude<PaginationProps["size"], undefined>;
}

export interface PaginationProps extends React.HTMLAttributes<HTMLElement> {
/**
* Current page.
Expand Down Expand Up @@ -45,9 +56,9 @@ export interface PaginationProps extends React.HTMLAttributes<HTMLElement> {
prevNextTexts?: boolean;
/**
* Override pagination item rendering.
* @default (item: PaginationItemProps) => <PaginationItem {...item} />
* @default PaginationItem
*/
renderItem?: (item: PaginationItemProps) => ReturnType<React.FC>;
renderItem?: (item: RenderItemProps) => ReturnType<React.FC>;
/**
* Pagination heading. We recommend adding heading instead of `aria-label` to help assistive technologies with an extra navigation-stop.
*/
Expand Down Expand Up @@ -110,7 +121,7 @@ export const getSteps = ({
* ```jsx
* <Pagination
* page={pageState}
* onPageChange={(x) => setPageState(x)}
* onPageChange={setPageState}
* count={9}
* boundaryCount={1}
* siblingCount={1}
Expand All @@ -130,9 +141,7 @@ export const Pagination = forwardRef<HTMLElement, PaginationProps>(
prevNextTexts = false,
srHeading,
"aria-labelledby": ariaLabelledBy,
renderItem: Item = (item: PaginationItemProps) => (
<PaginationItem {...item} />
),
renderItem: Item = PaginationItem,
...rest
},
ref,
Expand Down Expand Up @@ -216,6 +225,7 @@ export const Pagination = forwardRef<HTMLElement, PaginationProps>(
) : (
<li key={step}>
<Item
/* Remember to update RenderItemProps if you make changes to props sent into Item */
onClick={() => onPageChange?.(n)}
selected={page === n}
page={n}
Expand Down

0 comments on commit 22f5051

Please sign in to comment.