Pagination
⋯
Pagination matches the Karyawan footer: page-size selection on the left and a page-count label, previous/next actions, and numbered pages on the right. It uses Nesra Button and Select controls.
import { Pagination } from "@nesra/ui/pagination";import { useState } from "react";
export function ResultPages() { const [pageIndex, setPageIndex] = useState(0); return ( <Pagination page={pageIndex + 1} totalPages={2} onPageChange={(nextPage) => setPageIndex(nextPage - 1)} /> );}Pagination and its types are also exported from @nesra/ui. Page numbers are one-based.
Convert a zero-based API index when passing page and handling onPageChange.
Composition
Section titled “Composition”Pagination├── Pagination.PageSize (optional)└── Page label and navigationThe root renders a <nav> and places its optional child on the left. Pagination.PageSize is a
controlled Select and can be omitted. The page label and navigation remain visible either way.
Examples
Section titled “Examples”Known page count and page size
Section titled “Known page count and page size”The example keeps the API’s zero-based pageIndex and row limit in one filter object. A page
change updates only pageIndex; a limit change updates limit and resets pageIndex to 0. A
consuming route can use those filters as its query inputs.
import { Pagination } from "@nesra/ui/pagination";import { useState } from "react";
export function ControlledPaginationExample() { const [filters, setFilters] = useState({ pageIndex: 0, limit: 10 }); const totalPages = Math.ceil(80 / filters.limit);
return ( <Pagination page={filters.pageIndex + 1} totalPages={totalPages} onPageChange={(nextPage) => setFilters((current) => ({ ...current, pageIndex: nextPage - 1 })) } className="w-full" > <Pagination.PageSize value={filters.limit} options={[10, 25, 50]} onValueChange={(nextLimit) => setFilters((current) => ({ ...current, limit: nextLimit, pageIndex: 0 })) } /> </Pagination> );}Unknown page count
Section titled “Unknown page count”Provide hasNextPage from the API response when the final page is unknown. Pagination then shows
only the current numbered page and a Page N label.
import { Pagination } from "@nesra/ui/pagination";import { useState } from "react";
export function UnknownTotalPaginationExample() { const [page, setPage] = useState(3); const hasNextPage = page < 6;
return <Pagination page={page} hasNextPage={hasNextPage} onPageChange={setPage} />;}With a known totalPages, Pagination displays at most five consecutive page buttons and uses
noninteractive ellipses for skipped ranges. The current page stays in the window. Pass 1 for an
empty result so the footer reads Page 1 of 1 and both arrows are disabled.
Light and Dark
Section titled “Light and Dark”Pagination has no colors of its own. Page and arrow controls render Nesra Button (ghost and
outline for the current page) and the page size renders Nesra Select, so they follow those
components in Light and Dark, including their focus rings. Disabled arrows keep an
alpha-transparent fill. There is no Pagination component in the Figma file to compare against.
Accessibility
Section titled “Accessibility”- The root is a named navigation landmark. Override its default
aria-label="Pagination"when a page contains multiple paginations. - Every button has an accessible page or direction name. The active page has
aria-current="page". Unavailable arrows are disabled. Buttons and the Select have visible focus styling. - Page and page-size changes only call the supplied callbacks. The application owns state, data fetching, filter resets, and clamping the page after the total or page size changes.
API reference
Section titled “API reference”Pagination
Section titled “Pagination”Forwards native <nav> attributes and a ref to the navigation element.
| Prop | Type | Default | Effect |
|---|---|---|---|
page |
number |
Required | Current positive, one-based integer. |
onPageChange |
(page: number) => void |
Required | Reports a requested one-based page. |
totalPages |
number |
— | Known positive integer page count. |
hasNextPage |
boolean |
page < totalPages when known |
Sets next availability within the known page count. Required when the total is unknown. |
hasPreviousPage |
boolean |
page > 1 |
Sets previous availability above page 1. |
children |
ReactNode |
— | Optional left-side content. |
aria-label |
string |
"Pagination" |
Names the navigation landmark. |
The application must pass a page within the known count and keep availability flags consistent with its data source.
Pagination.PageSize
Section titled “Pagination.PageSize”| Prop | Type | Default | Effect |
|---|---|---|---|
value |
number |
Required | Selected positive integer row count. |
options |
readonly number[] |
Required | Positive integer row-count choices. |
onValueChange |
(value: number) => void |
Required | Reports a selected row count. |
label |
string |
"Rows per page" |
Visible text and Select accessible name. |
className |
string |
— | Classes for the selector group. |