Olddevs UI4.14.0
Navigation

Pagination

Page 7 of 24

Two siblings on each side

A single page renders nothing below:

When to use

  • Server-side or local results with a known number of pages.
  • You need to move to the adjacent, first or last page and to have a compact range of numbers around the current one.

When not to use

  • For an infinite feed or "Load more".
  • For navigating the steps of a form, use Stepper.
  • Do not show pagination when pageCount is unknown or is always 1.

Minimal example

<Pagination page={page} pageCount={result.pageCount} onChange={setPage} />

Public API

page, pageCount and onChange are required. siblings sets the number of neighbors to the left and right of the current page and defaults to 1. className and aria-label are available; the default nav name is "Pages". If an invalid page is passed in, the component clamps the current number to the range from 1 to pageCount, and onChange receives the number of the neighboring page, computed from the clamped page. pageRange(page, pageCount, siblings) returns an array (number | "gap")[]; it always keeps the first and last pages and never hides exactly one page behind an ellipsis.

Accessibility and keyboard

This is a nav with ordinary buttons: Tab moves through every available action. The current page has aria-current="page"; prev/next have accessible names and are disabled at the bounds. The ellipsis is hidden from screen readers and not clickable. See the Pagination source.

Good examples

  • Reset page to 1 when the application changes a filter.
  • Pass siblings={2} for a long list that should show more neighboring pages.
  • Use pageRange only for a custom presentation with the same rules.

Anti-patterns

  • A 0-based page or onChange.
  • Clickable ellipses that reveal nothing.
  • Rendering pagination for a single page.
  • src/components/navigation/Pagination.tsx
  • src/components/navigation/Pagination.stories.tsx

TypeScript types

PaginationProps

Prop

Type

On this page