- Docs
- Components
- 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
// 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.
| Prop | Type | Default | What it does |
|---|---|---|---|
offset | number | required | The zero-based offset of this page's first row: the API's offset. |
pageSize | number | required | Rows per page: the API's limit. |
onOffsetChange | (offset) => void | required | Called with the new offset. |
hasPrevious · hasNext · onPrevious · onNext | boolean · () => 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. |
total | number | — | The total, when the API returns one. Without it there's no Last, and Next stays on while a full page comes back. |
itemsOnPage | number | a full page | Rows this page returned, or what's left of total. |
loading | boolean | false | Turns the buttons off. |
pageSizes · onPageSizeChange | number[] · (size) => void | — | Offers a "Rows per page" select. Go back to the first page with a new size. |
locale · messages | string · object | the provider's | The numbers' locale, and this bar's strings. |
03
Parts
Each part carries a data-slot, for tests and placement.
| data-slot | Element | What 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.
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 } })}
/>