Pagination controls
The pagination bar for tables and lists, with page size, page indicator and navigation, that keeps the page and size in the URL.
Use the buttons to change page and the selector to change the page size. The page and size live in the URL (page_number and page_size), so the preview provides a URL of its own.
When to use
- Under a table or list that the backend returns in pages.
- When the page and page size must survive a reload and be shareable in a link.
- When the user needs to pick how many rows they see (25, 50 or 100 by default).
When not to use
- Numbered links that go to separate pages. Compose the parts of Pagination.
- A short list that fits on the page. Show it all.
- Switching between views. Use Tabs.
- Lists that load more as the user scrolls. Use a “Carregar mais” button.
Examples
Default
Shows page size, a “Página 3 de 12” indicator, and first, previous, next and last buttons. First and previous are disabled on page 1.
First page
With the total of records
Set showTotalRecords to say how many records exist next to the page size.
Page numbers
pageNumberLayout="leadingOne" adds a strip of page numbers that always starts at 1: 1 … 5 6 7 … 50. It replaces the first-page button.
Unknown total
When the backend does not return the total, set hideLastPage. The last-page button and the indicator disappear and next stays on while has_next_page is true.
The page-number strip
The strip is built by getFixedPageNumberStrip(currentPage, { totalPages, windowSize }) in @repo/ui/pagination-page-numbers. It has a fixed number of slots (5 by default, minimum 3), so the bar does not change width while the user pages. The first page is always shown, and the last page too when the total is known.
| Current page | Total | Strip (5 slots) |
|---|---|---|
| 1 | 50 | 1 2 3 … 50 |
| 6 | 50 | 1 … 5 6 7 … 50 |
| 49 | 50 | 1 … 47 48 49 50 |
| 4 | 3 | 1 2 3 (page clamped) |
PaginationLeadingOnePages renders the strip as buttons from @repo/ui/pagination-leading-one-pages. Use it on its own when you manage the page yourself.
Página atual: 6
Content
- Pass every string through
labels. The package has no translations: the app passes them, asapps/appdoes inusePaginationLabels. perPagefollows the selector: “por página”. WithshowTotalRecords,perPageWithTotal(total)replaces it: “por página, de 287”.pageIndicator(current, total)returns the whole sentence: “Página 3 de 12”. Use next-intl plural rules in the app when the copy needs them.- Tooltips are short and name the action: “Próxima página”, “Última página”.
Accessibility
- The buttons are
Buttonelements inside anavnamed bylabels.navAriaLabel.Tabmoves between them,EnterorSpaceactivates them, and disabled buttons leave the tab order. - Tooltips come from Radix Tooltip: they show on hover and keyboard focus, and
Escapehides them. The buttons keep their ownaria-label, so tooltips are not the only name. - The page-size selector is a Base UI Select. The arrow keys,
Home,Endand typing move through options,Enterpicks andEscapecloses. It is named bylabels.perPageand connected to its visible label. - While
isPlaceholderDatais true, the navigation buttons are disabled so the user cannot queue page changes. - The current page in the strip has
aria-current="page". Page-number buttons are not named: their text is only the number (see Known issues). - Below the
mdbreakpoint (768px) the page-size selector and the indicator are hidden; only the navigation stays.
Code
import { Pagination } from "@repo/ui/pagination-controls";
import type { PaginationLabels } from "@repo/ui/pagination-controls";
const labels: PaginationLabels = {
firstPage: "Primeira página",
lastPage: "Última página",
navAriaLabel: "Paginação dos processos",
next: "Próxima página",
pageIndicator: (current, total) => `Página ${current} de ${total}`,
perPage: "por página",
perPageWithTotal: (total) => `por página, de ${total}`,
previous: "Página anterior",
};
<Pagination
dataPagination={data?.pagination}
isPlaceholderData={isPlaceholderData}
labels={labels}
pageNumberLayout="leadingOne"
/>;
The component reads and writes page_number, page_size and q through nuqs. The app must be wrapped in a nuqs adapter.
Props
Pagination| Prop | Type | Default | Description |
|---|---|---|---|
clearSelection | () => void | — | Called when the page size shrinks, so the list can clear selected rows that left the page |
dataPagination | PaginationType | undefined | — | Pagination block returned by the backend. Not read while it is `undefined` |
defaultPageSize | number | 25 | Page size used when the URL has none |
hideLastPage | boolean | false | Hides the last-page jump and the page indicator. Use when the total is unknown |
isPlaceholderData | boolean | — | True while the next page loads. Disables the navigation controls |
labels | PaginationLabels | — | Every visible and accessible string, translated by the app |
pageNumberLayout | "default" | "leadingOne" | default | `leadingOne` adds a strip of page numbers (`1 … 9 10 11 … 50`) and drops the first-page button |
pageNumberWindowSize | number | 5 | Slots in the page-number strip for `leadingOne` |
pageSizeOptions | number[] | [25, 50, 100] | Page sizes offered in the selector |
showTotalRecords | boolean | false | Shows the total of records next to the page size |
PaginationType| Prop | Type | Default | Description |
|---|---|---|---|
current_page | number | — | Current page, starting at 1. |
total_pages | number | null | — | Total of pages. `null` when unknown. |
total_records | number | null | — | Total of records. `null` when unknown. |
has_next_page | boolean | — | Enables next and last. |
next_page, prev_page | number | null | — | Neighbour pages. Part of the type; the component navigates by URL. |
page_size, search_string | number, string | — | Echo of the request. Part of the type. |
PaginationLabels| Prop | Type | Default | Description |
|---|---|---|---|
perPage | string | — | Label after the page-size selector. |
perPageWithTotal | (total: number) => string | — | Label with the total, used with `showTotalRecords`. |
navAriaLabel | string | — | Accessible name of the navigation landmark. |
firstPage, previous, next, lastPage | string | — | Tooltip of each navigation button. |
pageIndicator | (current: number, total: number) => string | — | The sentence for the current page, such as "Página 3 de 12". |
Known issues
| Issue | Effect |
|---|---|
The page state comes from nuqs (page_number, page_size, q) with no fallback. |
Without a nuqs adapter above it the control does not work. It cannot be used with state outside the URL. |
After a page change the hook scrolls the element with id table-container. |
The table must use that exact id to scroll back to the top. The coupling is hidden from the props. |
The page-size selector and the page indicator have hidden ... md:flex. |
On small viewports users cannot change the page size or see the total of pages. |
PaginationPageButton shows only the number and has no aria-label or labels prop. |
Screen readers announce “6, button” with no mention of a page, and the name cannot be translated. |