Pagination
The pager under a list: how many results, how many rows a page, and Previous and Next around the page you are on. It holds no state, and it draws a control only when the list is long enough to use it. The Table draws it in its footer; no dashboard screen uses it yet.
<Pagination page={page} pageSize={pageSize} total={240} onPageChange={setPage} onPageSizeChange={(size) => { setPageSize(size); setPage(1); }}/>Installation
import { Pagination } from "@catalog-developer/components";Usage
<Pagination
page={page}
pageSize={pageSize}
total={240}
onPageChange={setPage}
onPageSizeChange={(size) => {
setPageSize(size);
setPage(1);
}}
/>// A list drawn with the Table passes the same facts as its `pagination`; the Table places the pager.
<DataTable
columns={columns}
data={rows}
getRowKey={(row) => row.id}
pagination={{ page, pageSize, total, onPageChange: setPage, onPageSizeChange: setPageSize }}
/>total is the list's whole count and the rows on screen are one page of it. For a list whose server pages it, both come from the server; the Table's inMemory pages a short list that arrives whole.
Anatomy
- 1 — Count. How many results in all, or the summary in its place. 12px, secondary.
- 2 — Rows. The rows-per-page select, a 24px control named “Rows per page”.
- 3 — Previous. A 24px secondary button with its word. Disabled on the first page.
- 4 — Page. “Page 3 of 10”, in tabular figures.
- 5 — Next. Disabled on the last page. Previous, the page and Next leave together when there is one page.
| Part | Size | Space |
|---|---|---|
| The row | 24px tall at least; body-3, 12px, secondary | 16px between the count and the controls |
| Rows select | 24px (xs) | 6px after the word “Rows” |
| Previous, Next | 24px (xs), secondary | 8px to the page text; 12px after the select |
Props
page, pageSize, total
The three facts it draws from. page counts from 1, and the number of pages is total over pageSize, rounded up. It holds no state: whoever renders it keeps the page.
const [page, setPage] = useState(1); <Pagination page={page} pageSize={25} total={240} onPageChange={setPage} />onPageChange
With it, Previous, the page and Next show while there is more than one page. Without it there is no pager.
<Pagination page={1} pageSize={25} total={240} onPageChange={setPage} /><Pagination page={1} pageSize={25} total={240} />onPageSizeChange and pageSizes
With onPageSizeChange, the rows-per-page select shows while some size on offer gives the list a second page; it does not leave with the pager. pageSizes is what it offers: 25, 50 and 100 unless set. The component does not change the page when the size changes: the caller does (the Table goes back to page 1).
<Pagination page={page} pageSize={pageSize} total={240} pageSizes={[10, 20, 50]} onPageChange={setPage} onPageSizeChange={(size) => { setPageSize(size); setPage(1); }}/>count
The count at the left, “240 total results”. On by default; count={false} leaves it out.
<Pagination page={page} pageSize={25} total={240} count={false} onPageChange={setPage} />summary
What stands in the count's place while a list has something more pressing to say there. It is a polite live region, so a change is announced. The Table does not use it: its selection reads in the bar's place, and “Select all 240” follows the total as the note.
<Pagination page={page} pageSize={25} total={240} onPageChange={setPage} summary={ <> 25 of 240 selected <Button color="primary" emphasis="link" size="xs">Select all 240</Button> </> }/>note
What follows the count, after a dot: a line about the list as a whole. The Table puts “Select all 240” there once the whole page is checked, then the list's own note. Short of room it goes under the count.
<Pagination page={page} pageSize={25} total={240} onPageChange={setPage} note={<FilterHiddenNote hidden={20} onClear={clearFilters} />}/>States
First and last page
Previous is disabled on the first page and Next on the last. Both stay where they are.
<Pagination page={1} pageSize={25} total={240} onPageChange={setPage} /><Pagination page={10} pageSize={25} total={240} onPageChange={setPage} />One page
With one page, the page and its two buttons are not drawn. The count stays, and so does the rows select: 25 a page would bring a second page back. Pick 50 here: the pager eases out over 200ms, and back in at 25. It cuts under reduced motion.
<Pagination page={page} pageSize={pageSize} total={40} onPageChange={setPage} onPageSizeChange={setPageSize} />A short list
5 results fit one page at 25, 50 and 100: no size on offer gives a second page, so the rows select and the pager are not drawn. The count stays, and a note with it. The page size the reader chose is kept, only not shown.
<Pagination page={1} pageSize={50} total={5} onPageChange={setPage} onPageSizeChange={setPageSize} />No results
Alone it reads “0 total results”. A Table with no rows draws no footer at all.
<Pagination page={1} pageSize={25} total={0} onPageChange={setPage} />In a card's footer
Where the Table puts it: the CardFooter of the card that holds the rows, across its width.
<Card> {rows} <CardFooter> <Pagination page={page} pageSize={pageSize} total={240} onPageChange={setPage} onPageSizeChange={setPageSize} className="w-full" /> </CardFooter></Card>API Reference
Besides these, every prop of a <div> except children.
| Prop | Type | Default | Description |
|---|---|---|---|
page | number | — | The page shown, from 1. |
pageSize | number | — | How many rows a page holds. |
total | number | — | How many rows there are in all. Left out for a list paged by cursor, which knows no total: then there is no count and no page of pages. |
hasNext | boolean | false | With no total: whether there is a page after this one. Previous and Next show, at the right, while there is another page either way; Previous is on from page 2, Next while this is true. The rows-per-page select shows with onPageSizeChange. |
onPageChange | (page: number) => void | — | With it, Previous, the page and Next show, while there is more than one page. |
onPageSizeChange | (size: number) => void | — | With it, the rows-per-page select shows, while some size on offer gives the list a second page. |
pageSizes | readonly number[] | [25, 50, 100] | The sizes the select offers. |
count | boolean | true | The count at the left, “240 total results”. |
summary | ReactNode | — | What stands in the count’s place. Announced politely when it changes. |
note | ReactNode | — | What follows the count, after a dot: a line about the list as a whole (“20 hidden by filters — Clear filters”). Short of room it goes under the count. |
Accessibility
| Key | Does |
|---|---|
Tab | Moves through what is there, in reading order: a link in the summary, the rows select, Previous, Next. A disabled button is skipped. |
Enter, Space | On Previous or Next, goes to that page. On the select, opens it. |
↑ ↓ | In the open select, moves through the sizes; Enter picks one, Esc closes it. |
The count is a polite live region: a new total, or a new summary, is announced. The select is named “Rows per page”. With one page the pager is inert, so Tab skips it and a screen reader does not find it.
A page change itself is not announced, and the pager is not a named landmark: both are open questions below. Not checked: a screen reader, touch, Safari and Firefox.
Rules
Open questions
The total, or the range you are looking at?
Open“240 total results” at the left, “Page 3 of 10” at the right.
Carbon shows the range of items on screen beside its rows-per-page select. Atlassian and Primer show page numbers and no total.
Should a page change be announced?
OpenThe count is announced when it changes. “Page 3 of 10” is not.
Polaris puts its label in a polite live region. Primer and Atlassian put the pager in a named navigation landmark and mark the current page (aria-current); Primer also moves focus to the start of the new content when it is swapped in place.
Buttons, or links with an address?
OpenPrevious and Next are buttons. Whether a list keeps its page in the address is the list's: the audit log does, today.
shadcn and Primer draw each page as a link, and Primer says every page should have a URL. Carbon and shadcn's data table use buttons. Polaris takes either a URL or a handler.
Who goes back to page 1?
OpenThe pager holds no state. The Table goes back to page 1 when the page size changes; on a new sort or filter, the page does it.
Shopify's guidance: reset to the first page whenever search, filters or sorting change, and keep the page in the address.
Where the pager sits
OpenThe Table puts it in its card's footer.
Carbon: directly under its table, not stacked above it. Primer: at the end of the page content. Atlassian: at the bottom of the page.
Decided
The count always; a paging control only when it can do something
The component does both by itself: it leaves the pager out for one page, and the rows select out when no size on offer gives a second page. The count and the select are props (count, onPageSizeChange), so a list that follows the rule keeps the first on and passes the second.
Short of room it gives way in steps, and nothing overlaps or is cut
Decided with the designer on the Table's footer. First Previous and Next drop their words and become icon buttons, named “Previous page” and “Next page”. Then the left text takes two lines, the count over the note. Last it takes a row of its own over the controls, both starting at the left. The steps are measured, not set at fixed widths.
What others expose
What shadcn, Atlassian, Primer, Carbon and Polaris have that ours does not. Polaris's rows are from its public repository (its site redirects elsewhere). Base UI has no pagination. Nothing here is decided for us, and nothing was added: “Ours differs” says what ours does instead, “Ask” is a question for the designer.
| They have | Who | Ours | Why |
|---|---|---|---|
| Numbered page links, with an ellipsis for the gap | shadcn, Atlassian, Primer, Carbon | Ours differs | Ours writes “Page 3 of 10” between Previous and Next. |
| First and last buttons | shadcn’s data table | Ask | Ours has Previous and Next only. |
| The range of items on screen | Carbon | Ask | Ours shows the total at the left and the page at the right. See the open question. |
| Pick the page from a select | Carbon | Ask | Ours has no way to jump to a page. |
| Next and Previous with no known total | Polaris (hasNext, hasPrevious) | Ask | Ours needs a total to know the last page, so a list paged by cursor with no count cannot use it as built. |
| Each page as a link, with an address | shadcn, Primer (hrefBuilder), Polaris (nextURL) | Ask | Ours are buttons. See the open question. |
| A navigation landmark around the pager, with a name | Atlassian, Primer, Polaris | Ask | Ours is a plain row. See the open question. |
| The whole pager disabled at once | Atlassian (isDisabled) | Ask | Ours disables Previous and Next only at the ends. |
| Arrows instead of the words | Carbon, Polaris | Ours differs | Ours writes Previous and Next, and short of room draws each as its small chevron alone, named “Previous page” and “Next page”. shadcn shows an arrow and the word, and hides the word on a narrow screen. |
| Parts that hide on a narrow screen | Primer (showPages per breakpoint), shadcn, Carbon | Ours differs | Ours keeps every part and gives way in steps, measured: Previous and Next become icon buttons, then the left text takes two lines, then a row of its own over the controls. |
| Keyboard shortcuts for next and previous | Polaris (nextKeys, previousKeys) | Ours differs | Ours has none. Shopify’s newer guidance says to remove them in most apps. |
| Words that can be replaced | Atlassian, shadcn, Polaris | Ask | “Previous”, “Next”, “Rows” and “total results” are written in the component. |
| Sizes, to match a table’s row height | Carbon | Ours differs | Ours is one size: 24px controls, 12px text. |
| Keeping its own page; custom page items | Atlassian (defaultSelectedIndex, components), Primer (renderPage) | Ours differs | Ours holds no state and has no page items. |