Skip to content

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.

Pagination
├── Pagination.PageSize (optional)
└── Page label and navigation

The 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.

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.

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.

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.

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.

  • 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.

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.

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.

See Layout and Colors for the light-theme tokens.