The Pagination component enables the user to select a specific page from a range of pages with previous/next controls, collapsing long ranges with ellipses.
import { useState } from "react";
import { Pagination } from "@kesko/components";
export default () => {
const [page, setPage] = useState(1);
return <Pagination count={10} page={page} onChange={setPage} />;
};<nav class="k-pagination" aria-label="Pagination">
<div class="k-pagination-content">
<div class="k-pagination-prev">
<button class="k-button" variant="plain" disabled>
<svg viewBox="0 0 24 24" aria-hidden="true" xmlns="http://www.w3.org/2000/svg"><path d="M14.748 17.688a.401.401 0 0 1 0 .565l-.495.495a.401.401 0 0 1-.565 0l-6.465-6.465a.401.401 0 0 1 0-.565l6.465-6.465a.401.401 0 0 1 .565 0l.495.495a.401.401 0 0 1 0 .565L9.06 12z" fill="currentColor" /></svg>
Previous
</button>
</div>
<div class="k-pagination-pages">
<button class="k-button" variant="primary" aria-current="page">1</button>
<button class="k-button" variant="plain">2</button>
<button class="k-button" variant="plain">3</button>
<button class="k-button" variant="plain">4</button>
<button class="k-button" variant="plain">5</button>
<span class="k-pagination-ellipsis" aria-hidden="true">…</span>
<button class="k-button" variant="plain">10</button>
</div>
<div class="k-pagination-next">
<button class="k-button" variant="plain">
Next
<svg viewBox="0 0 24 24" aria-hidden="true" xmlns="http://www.w3.org/2000/svg"><path d="M16.777 12.283l-6.465 6.465a.401.401 0 0 1-.564 0l-.495-.495a.401.401 0 0 1 0-.565L14.94 12 9.253 6.312a.401.401 0 0 1 0-.565l.495-.494a.401.401 0 0 1 .565 0l6.464 6.465a.401.401 0 0 1 0 .565z" fill="currentColor" /></svg>
</button>
</div>
</div>
</nav>import { useState } from "react";
import { Pagination } from "@kesko/components";
export default () => {
const [page, setPage] = useState(10);
return <Pagination count={20} page={page} siblingCount={2} boundaryCount={2} onChange={setPage} />;
};<nav class="k-pagination" aria-label="Pagination">
<div class="k-pagination-content">
<div class="k-pagination-prev">
<button class="k-button" variant="plain">
<svg viewBox="0 0 24 24" aria-hidden="true" xmlns="http://www.w3.org/2000/svg"><path d="M14.748 17.688a.401.401 0 0 1 0 .565l-.495.495a.401.401 0 0 1-.565 0l-6.465-6.465a.401.401 0 0 1 0-.565l6.465-6.465a.401.401 0 0 1 .565 0l.495.495a.401.401 0 0 1 0 .565L9.06 12z" fill="currentColor" /></svg>
Previous
</button>
</div>
<div class="k-pagination-pages">
<button class="k-button" variant="plain">1</button>
<button class="k-button" variant="plain">2</button>
<span class="k-pagination-ellipsis" aria-hidden="true">…</span>
<button class="k-button" variant="plain">8</button>
<button class="k-button" variant="plain">9</button>
<button class="k-button" variant="primary" aria-current="page">10</button>
<button class="k-button" variant="plain">11</button>
<button class="k-button" variant="plain">12</button>
<span class="k-pagination-ellipsis" aria-hidden="true">…</span>
<button class="k-button" variant="plain">19</button>
<button class="k-button" variant="plain">20</button>
</div>
<div class="k-pagination-next">
<button class="k-button" variant="plain">
Next
<svg viewBox="0 0 24 24" aria-hidden="true" xmlns="http://www.w3.org/2000/svg"><path d="M16.777 12.283l-6.465 6.465a.401.401 0 0 1-.564 0l-.495-.495a.401.401 0 0 1 0-.565L14.94 12 9.253 6.312a.401.401 0 0 1 0-.565l.495-.494a.401.401 0 0 1 .565 0l6.464 6.465a.401.401 0 0 1 0 .565z" fill="currentColor" /></svg>
</button>
</div>
</div>
</nav>Props
| Name | Description | Type | Default |
|---|---|---|---|
count | Total number of pages. | number | — |
siblingCount | Number of always-visible page buttons on each side of the active page. | number | 1 |
boundaryCount | Number of always-visible page buttons at the start and end of the range. | number | 1 |
itemLabel | Returns the accessible label for a numbered page button as well as next and prev buttons. | (paginationItem: PaginationItem) => string | — |
prevLabel | Visible label for the previous-page button. | string | "Previous" |
nextLabel | Visible label for the next-page button. | string | "Next" |
hidePrev | Hides the previous-page button. | boolean | false |
hideNext | Hides the next-page button. | boolean | false |
page | The currently active page (1-based). | number | — |
aria-label | Accessible label for the navigation landmark. | string | — |
href | Returns the href for a page item as well as next and prev buttons, rendering the items as links. | (paginationItem: PaginationItem) => string | — |
Events
| Name | Description | Type |
|---|---|---|
onChange | Called with the newly selected page and the originating click event. | (page: number, e: MouseEvent<ButtonTarget>) => void |
CSS custom properties
CSS custom properties provide finer-grained control than props. Prefer the props API when it suits your need.
| Name | Description | Default |
|---|---|---|
--k-pagination-column-gap | Overrides the horizontal gap between items. | var(--k-space-4xs) |
--k-pagination-row-gap | Overrides the vertical gap between the page list and the controls. | var(--k-space-2xs) |
--k-pagination-color-ellipsis | Overrides the ellipsis color. | var(--k-color-text-link) |