Skip to main content
  1. Docs
  2. Components
  3. Navigation

Pagination

Pages of a long list, for offset and limit APIs: the range on show, then First, Previous, Next and Last.

Import
@qeetrix/react/experimental
Status
ExperimentalSince 0.0.6
Renders
<nav aria-label="Pagination">Server-rendered
Tested
WCAG 2.2 AAaxe on every pull request

01

Import

pagination.tsx
// Experimental: from the package's experimental entry, until it's stable.
import { Pagination, ShowMore } from "@qeetrix/react/experimental";

02

Props

And every native attribute of the element it renders.

PropTypeDefaultWhat it does
offsetnumberrequiredThe zero-based offset of this page's first row: the API's offset.
pageSizenumberrequiredRows per page: the API's limit.
onOffsetChange(offset) => voidrequiredCalled with the new offset.
hasPrevious · hasNext · onPrevious · onNextboolean · () => void—Cursor paging instead of offset: Previous and Next alone; offset, if known, shows the range.
ShowMore: hasMore · onMore · loading · label · end…—Show more under a growing list; end once there's nothing more, announced.
totalnumber—The total, when the API returns one. Without it there's no Last, and Next stays on while a full page comes back.
itemsOnPagenumbera full pageRows this page returned, or what's left of total.
loadingbooleanfalseTurns the buttons off.
pageSizes · onPageSizeChangenumber[] · (size) => void—Offers a "Rows per page" select. Go back to the first page with a new size.
locale · messagesstring · objectthe provider'sThe numbers' locale, and this bar's strings.

03

Parts

Each part carries a data-slot, for tests and placement.

data-slotElementWhat it is
pagination<nav>The landmark, named "Pagination".
pagination-size<span>The rows-per-page label and Select.
pagination-range<span role="status">The range, each number in a <bdi>.
icon-button<button>First, Previous, Next, Last.
show-more<div>ShowMore: its button, then its end line.

04

From the address

Keep offset and limit in the URL, so a page can be shared and Back returns to it.

users.tsx
const { offset = 0, limit = 25 } = useSearch();
const { data } = useUsers({ offset, limit });

<Pagination
  offset={offset}
  pageSize={limit}
  total={data?.total}
  loading={!data}
  onOffsetChange={(next) => navigate({ search: { offset: next, limit } })}
/>
Next — PaginationAccessibility