Pagination
A toolbar for navigating a paged dataset: current page and total, prev/next, a go-to-page field and a rows-per-page select. Each addon is toggled by a show* boolean, from a bare bar to a full footer.
Installation#
Usage#
import { Pagination } from "@/components/ui/pagination"
export function Example() {
const [page, setPage] = useState(1)
return (
<Pagination
page={page}
pageCount={10}
onPageChange={setPage}
/>
)
}Anatomy#
import {
PaginationRoot,
PaginationRowsPerPage,
PaginationInfo,
PaginationGoTo,
PaginationControls,
PaginationPrevButton,
PaginationNextButton,
} from "@/components/ui/pagination"
<PaginationRoot page={…} pageCount={…}>
<PaginationRowsPerPage />
<PaginationInfo />
<PaginationGoTo />
<PaginationControls />
{/* or the buttons one by one */}
<PaginationPrevButton />
<PaginationNextButton />
</PaginationRoot>Default#
Out of the box you get the page readout and prev/next controls. The component is fully controlled: drive it with page and onPageChange. The buttons disable themselves at the first and last page.
Go to page#
Set showGoTo to add a numeric field for jumping to an arbitrary page. The value commits on Enter or blur and is clamped into range, so an out-of-bounds entry snaps back to the nearest valid page.
Rows per page#
Set showRowsPerPage and wire rowsPerPage / onRowsPerPageChange to let users choose how many rows to load. Customize the choices with rowsPerPageOptions.
Density#
Like the rest of Koala, Pagination honors the density axis (prop or DensityProvider). The whole toolbar lands on one matched control height: a 40px row when comfortable, a 32px row when compact.
Custom layout#
For a bespoke arrangement, drop the show* toggles and compose the parts yourself inside PaginationRoot. Every part: PaginationInfo, PaginationControls, PaginationGoTo, PaginationRowsPerPage, reads the shared state from context.
API reference#
Pagination
The ready toolbar: PaginationRoot with a default layout gated by show* toggles. Pass children to replace the layout. Every part accepts className, merged last.
| Prop | Type | Default | Description |
|---|---|---|---|
| page* | number | - | The current page, 1-based. Fully controlled. |
| pageCount* | number | - | Total pages, clamped to at least 1. |
| onPageChange | (page: number) => void | - | Called with the next page, already clamped into range. |
| rowsPerPage | number | - | The current rows-per-page value, needed by the rows select. |
| onRowsPerPageChange | (rows: number) => void | - | Called with the next rows-per-page value. |
| rowsPerPageOptions | number[] | [10, 20, 30, 50] | The choices the rows select offers. |
| disabled | boolean | false | Disables every control at once. |
| density | "comfortable" | "compact" | - | One matched control height: 40px comfortable, 32px compact. Inherits the nearest DensityProvider (compact with none). |
| showInfo | boolean | true | The Page X of Y readout. |
| showControls | boolean | true | The previous and next buttons. |
| showGoTo | boolean | false | The go-to-page field. |
| showRowsPerPage | boolean | false | The rows-per-page select. |
PaginationRoot
The state provider and <nav aria-label="Pagination">, for a custom layout of the parts. Forwards native <nav> props.
| Prop | Type | Default | Description |
|---|---|---|---|
| page* | number | - | The current page, 1-based. Fully controlled. |
| pageCount* | number | - | Total pages, clamped to at least 1. |
| onPageChange | (page: number) => void | - | Called with the next page, already clamped into range. |
| rowsPerPage | number | - | The current rows-per-page value, needed by the rows select. |
| onRowsPerPageChange | (rows: number) => void | - | Called with the next rows-per-page value. |
| rowsPerPageOptions | number[] | [10, 20, 30, 50] | The choices the rows select offers. |
| disabled | boolean | false | Disables every control at once. |
| density | "comfortable" | "compact" | - | One matched control height: 40px comfortable, 32px compact. Inherits the nearest DensityProvider (compact with none). |
PaginationInfo
The Page X of Y readout, aria-live="polite", numbers in tabular-nums. children replace the copy, e.g. to localize. Forwards native <p> props.
PaginationControls
The previous and next buttons with the cluster's spacing. Forwards native <div> props.
PaginationPrevButton
The outline icon button to the previous page, disabled on the first. Forwards Button props but size, variant and iconOnly; children replace the caret.
PaginationNextButton
The same button to the next page, disabled on the last.
PaginationGoTo
A numeric field that jumps to a page on Enter or blur, clamped into range. Forwards native <div> props.
| Prop | Type | Default | Description |
|---|---|---|---|
| label | React.ReactNode | "Go to" | The label before the field. null hides it. |
PaginationRowsPerPage
The rows-per-page select, fed by the root's rowsPerPage and rowsPerPageOptions. Forwards native <div> props.
| Prop | Type | Default | Description |
|---|---|---|---|
| label | React.ReactNode | "Rows per page" | The label before the select. null hides it. |