Pagination
Moves between pages of a collection the application owns, as numbered pages, as previous and next only, or as links.
import { Pagination, PaginationItems, PaginationNext, PaginationPrevious,} from '@slotted/react/pagination';export default function PaginationBasic() { return ( <Pagination aria-label="Invoices" count={482} defaultPage={12}> <PaginationPrevious /> <PaginationItems /> <PaginationNext /> </Pagination> );}Installation
The packages are a 0.x beta on npm, and their public API changes between beta releases without deprecation. One line installs the binding and the default theme.
pnpm add @slotted/react @slotted/theme @slotted/themesimport { Pagination, PaginationDefaultsProvider, PaginationFirst, PaginationItems, PaginationLast, PaginationNext, PaginationPageSize, PaginationPrevious, PaginationStatus, usePagination } from '@slotted/react';First, last and the width of the row
PaginationFirst and PaginationLast jump to the ends. siblingCount sets how many pages are drawn on each side of the current page, and boundaryCount how many are drawn at each end. The row keeps one length at every page, so the controls beside it do not move while a reader steps through the collection. Both counts default to 1. The first paginator here uses the defaults, the second widens both to 2.
import { Pagination, PaginationFirst, PaginationItems, PaginationLast, PaginationNext, PaginationPrevious,} from '@slotted/react/pagination';import { Stack } from '@slotted/react/stack';import { Text } from '@slotted/react/typography';export default function PaginationRow() { return ( <Stack gap={4}> <Text size="sm" tone="muted"> One page on each side of the current page and at each end </Text> <Pagination aria-label="Invoices, default row" count={482} defaultPage={12}> <PaginationFirst /> <PaginationPrevious /> <PaginationItems /> <PaginationNext /> <PaginationLast /> </Pagination> <Text size="sm" tone="muted"> Two pages on each side of the current page and at each end </Text> <Pagination aria-label="Invoices, wide row" boundaryCount={2} count={482} defaultPage={12} siblingCount={2} > <PaginationFirst /> <PaginationPrevious /> <PaginationItems /> <PaginationNext /> <PaginationLast /> </Pagination> </Stack> );}A total the server does not know
count has no default. Without it PaginationItems draws nothing, because no page numbers can be drawn for a total that is unknown, and Next stays available at every page. Pass page with onPageChange to hold the position, and give PaginationStatus its own children for the sentence, because the default range needs a count. Here the next page is always one press away. PaginationLast stays disabled without a count, because no last page exists, so this paginator leaves it out.
import { useState } from 'react';import { Pagination, PaginationNext, PaginationPrevious, PaginationStatus,} from '@slotted/react/pagination';export default function PaginationCursor() { const [page, setPage] = useState(1); return ( <Pagination aria-label="Shipments" page={page} onPageChange={setPage}> <PaginationPrevious /> <PaginationStatus>Shipments, page {page}</PaginationStatus> <PaginationNext /> </Pagination> );}The range sentence
PaginationStatus writes the items the page holds, such as 41–60 of 482, in a polite live region. A page change is announced once. live="off" removes the announcement and keeps the sentence displayed, for an application that announces the new page itself. The default is polite.
import { Pagination, PaginationNext, PaginationPrevious, PaginationStatus,} from '@slotted/react/pagination';import { Stack } from '@slotted/react/stack';import { Text } from '@slotted/react/typography';export default function PaginationRange() { return ( <Stack gap={4}> <Text size="sm" tone="muted"> The range is announced after each page change </Text> <Pagination aria-label="Invoices, announced" count={482} defaultPage={2}> <PaginationPrevious /> <PaginationStatus /> <PaginationNext /> </Pagination> <Text size="sm" tone="muted"> The range is displayed and never announced </Text> <Pagination aria-label="Invoices, silent" count={482} defaultPage={2} live="off"> <PaginationPrevious /> <PaginationStatus /> <PaginationNext /> </Pagination> </Stack> );}Page size
PaginationPageSize is a native select wrapped by its own label, so the platform names the control. pageSizeOptions sets the sizes offered and defaultPageSize the one it starts from; the label text is the label prop in React and the projected content in Angular. Changing the size keeps the first item of the current page visible: from page 5 at 25 rows, choosing 50 lands on page 3, which starts at the same item. The page that follows is reported as a second page change with the reason programmatic.
import { Pagination, PaginationNext, PaginationPageSize, PaginationPrevious, PaginationStatus,} from '@slotted/react/pagination';export default function PaginationRows() { return ( <Pagination aria-label="Orders" count={482} defaultPage={5} defaultPageSize={25} pageSizeOptions={[25, 50, 100]} > <PaginationPageSize label="Orders per page" /> <PaginationStatus /> <PaginationPrevious /> <PaginationNext /> </Pagination> );}Links
itemHref receives a page number and returns its address. Every page and every trigger then renders as an anchor, so a middle click opens the page in a tab and a crawler can follow the row. Without itemHref they render as buttons. A trigger that cannot move, such as Previous on page 1, renders without href and with aria-disabled. In Angular the trigger element is written as a to match.
import { Pagination, PaginationItems, PaginationNext, PaginationPrevious,} from '@slotted/react/pagination';export default function PaginationLinks() { return ( <Pagination aria-label="Invoices" count={482} itemHref={(page) => `#invoices-page-${page}`}> <PaginationPrevious /> <PaginationItems /> <PaginationNext /> </Pagination> );}Narrow containers
Below 22rem of its own inline size, the paginator replaces the numbered row with the summary, such as Page 12 of 25, and keeps the triggers. The rule is a container query on the paginator, not on the viewport, so the same paginator compacts in a narrow card and stays numbered on a wide page. Both the row and the summary are in the DOM, and exactly one is displayed. Nothing needs configuring.
Receiving
Picking
Packing
import { Card, CardBody, CardHeader } from '@slotted/react/card';import { Grid } from '@slotted/react/grid';import { Pagination, PaginationItems, PaginationNext, PaginationPrevious,} from '@slotted/react/pagination';import { Heading } from '@slotted/react/typography';export default function PaginationCompact() { return ( <Grid columns={3} gap={4} minItemWidth="xs"> <Card> <CardHeader> <Heading level={2} size="md"> Receiving </Heading> </CardHeader> <CardBody> <Pagination aria-label="Receiving queue" count={140} defaultPage={3}> <PaginationPrevious /> <PaginationItems /> <PaginationNext /> </Pagination> </CardBody> </Card> <Card> <CardHeader> <Heading level={2} size="md"> Picking </Heading> </CardHeader> <CardBody> <Pagination aria-label="Picking queue" count={482} defaultPage={12}> <PaginationPrevious /> <PaginationItems /> <PaginationNext /> </Pagination> </CardBody> </Card> <Card> <CardHeader> <Heading level={2} size="md"> Packing </Heading> </CardHeader> <CardBody> <Pagination aria-label="Packing queue" count={96} defaultPage={2}> <PaginationPrevious /> <PaginationItems /> <PaginationNext /> </Pagination> </CardBody> </Card> </Grid> );}States
A trigger at a bound is unavailable and stays in place, so nothing reflows. loading marks a page change in flight: every control refuses a press, the row keeps its size, and the root carries aria-busy. disabled takes every control away without taking the row out of the page, and the current page stays visible in the disabled palette.
import { Pagination, PaginationItems, PaginationNext, PaginationPrevious,} from '@slotted/react/pagination';import { Stack } from '@slotted/react/stack';import { Text } from '@slotted/react/typography';export default function PaginationStates() { return ( <Stack gap={4}> <Text size="sm" tone="muted"> At the last page </Text> <Pagination aria-label="Invoices, last page" count={482} defaultPage={25}> <PaginationPrevious /> <PaginationItems /> <PaginationNext /> </Pagination> <Text size="sm" tone="muted"> Loading the next page </Text> <Pagination aria-label="Invoices, loading" count={482} defaultPage={3} loading> <PaginationPrevious /> <PaginationItems /> <PaginationNext /> </Pagination> <Text size="sm" tone="muted"> Disabled </Text> <Pagination aria-label="Invoices, disabled" count={482} defaultPage={3} disabled> <PaginationPrevious /> <PaginationItems /> <PaginationNext /> </Pagination> </Stack> );}Controlled
Pass page to own the position. A press calls onPageChange in React and emits pageChange in Angular, before the page moves, with a request that carries the new value, the previous one, the reason and a cancel() method. The reason is pointer for a press, because Enter and Space on a button produce the same click. When the collection shrinks under a reader who is past its new end, the paginator asks for the last page itself, with the reason programmatic. The example starts on page 25. Press Show open invoices.
import { useState } from 'react';import { Button } from '@slotted/react/button';import { Inline } from '@slotted/react/inline';import { Pagination, PaginationItems, PaginationNext, PaginationPrevious, type PaginationPageRequest,} from '@slotted/react/pagination';import { Stack } from '@slotted/react/stack';import { Text } from '@slotted/react/typography';export default function PaginationControlled() { const [count, setCount] = useState(482); const [page, setPage] = useState(25); const [reason, setReason] = useState('none yet'); const handlePageChange = (next: number, request: PaginationPageRequest) => { setPage(next); setReason(request.reason); }; return ( <Stack gap={4}> <Pagination aria-label="Invoices" count={count} page={page} onPageChange={handlePageChange}> <PaginationPrevious /> <PaginationItems /> <PaginationNext /> </Pagination> <Text size="sm" tone="muted"> {count} invoices, page {page}. Last change: {reason}. </Text> <Inline> <Button onClick={() => setCount(96)}>Show open invoices</Button> <Button onClick={() => setCount(482)}>Show all invoices</Button> </Inline> </Stack> );}Wording
messages replaces any of the words Pagination writes, key by key: label, first, previous, next, last, page, pageSize, range and summary. The page, range and summary messages take placeholders. A static aria-label on the paginator wins over messages.label. Keys left out keep the language in force.
import { Pagination, PaginationItems, PaginationNext, PaginationPrevious, PaginationStatus,} from '@slotted/react/pagination';const messages = { label: 'Shipments', next: 'Later shipments', page: 'Shipments page {page}', previous: 'Earlier shipments', range: '{start} to {end} of {count} shipments',};export default function PaginationMessages() { return ( <Pagination count={482} defaultPage={12} messages={messages}> <PaginationPrevious /> <PaginationItems /> <PaginationNext /> <PaginationStatus /> </Pagination> );}Application defaults
siblingCount, boundaryCount, defaultPageSize, pageSizeOptions and live can be set once for everything below a provider: PaginationDefaultsProvider in React, providePaginationDefaults in Angular. A paginator that states a value of its own keeps it, as the second paginator does with siblingCount.
import { Pagination, PaginationDefaultsProvider, PaginationItems, PaginationPageSize, PaginationStatus,} from '@slotted/react/pagination';import { Stack } from '@slotted/react/stack';import { Text } from '@slotted/react/typography';export default function PaginationApplicationDefaults() { return ( <PaginationDefaultsProvider defaultPageSize={50} pageSizeOptions={[25, 50, 100]} siblingCount={2} > <Stack gap={4}> <Text size="sm" tone="muted"> Inherits two siblings and 50 rows </Text> <Pagination aria-label="Orders, inherited" count={1200} defaultPage={10}> <PaginationPageSize /> <PaginationStatus /> <PaginationItems /> </Pagination> <Text size="sm" tone="muted"> States no siblings and keeps the rest </Text> <Pagination aria-label="Orders, own row" count={1200} defaultPage={10} siblingCount={0}> <PaginationPageSize /> <PaginationStatus /> <PaginationItems /> </Pagination> </Stack> </PaginationDefaultsProvider> );}Reaching the paginator from inside
usePagination() in React, called by any component rendered inside Pagination, returns goToPage, next, previous, setPageSize and the arithmetic they use. In Angular, #pager="slPagination" gives the template the same operations, plus reset(). Both go through the same request as a press, so onPageChange and pageChange report them. The button here returns to page 1.
import { Button } from '@slotted/react/button';import { Pagination, PaginationItems, PaginationNext, PaginationPrevious, usePagination,} from '@slotted/react/pagination';function BackToStart() { const { goToPage } = usePagination(); return <Button onClick={() => goToPage(1)}>Back to page 1</Button>;}export default function PaginationWiring() { return ( <Pagination aria-label="Invoices" count={482} defaultPage={12}> <PaginationPrevious /> <PaginationItems /> <PaginationNext /> <BackToStart /> </Pagination> );}Accessibility
| Key | Effect | Focus |
|---|---|---|
| Tab | moves to each trigger, each page and the page size in reading order | the next control |
| Enter | activates the focused control, or follows it when itemHref made it a link | stays, unless the control became unavailable |
| Space | activates the focused control while it is a button | stays, unless the control became unavailable |
- The current page carries aria-current="page", which is the value the ARIA specification names for a link within a set of pagination links — and it is the attribute that paints the fill, so what a reader hears and what the eye sees are one fact rather than two.
- The range is a polite live region, and it is the only one: one region announcing one sentence is the whole of the announcement, so a page change is not read out twice.
- In link mode a trigger at a bound renders an anchor with no destination and aria-disabled, rather than a disabled anchor — there is no such thing, and one that kept its href would still navigate on a middle click.
- The page size is a native select wrapped by its own label, which gives the control its accessible name from the platform and needs no generated id; its popup follows the color scheme the theme already emits.
- Below 22rem of its own inline size the numbered row gives way to the summary. Both are always in the DOM and exactly one is displayed, so nothing is announced twice — and the range is only hidden where a summary exists to replace it.
- Focus stays on the control that was pressed. When pressing it makes it unavailable — Next on the second-to-last page — focus moves to the nearest control that survives, because focus that falls to the body after a press discards the reader’s position.
- The figures are tabular and every cell is at least as wide as it is tall, so page 9 and page 8 942 are the same target and the row does not move under the pointer.
API
Pagination
Props
countnumber- How many items the collection holds. It has no default: left out entirely, the total is unknown, no page numbers are drawn, and no total is invented.
pagenumber- Present means controlled, for the life of the component.
defaultPagenumberDefault1- The page an uncontrolled paginator starts from, read once.
pageSizenumber- Present means controlled, like page.
defaultPageSizenumberDefault20- The page size it starts from, read once.
pageSizeOptionsreadonly number[]Default [10, 20, 50, 100]- What the page-size control offers.
siblingCountnumberDefault1- Pages drawn either side of the current one.
boundaryCountnumberDefault1- Pages drawn at each end of the row.
itemHref(page: number) => string- Turns every page and every trigger into an anchor with a real destination.
messagesPartial<PaginationMessages>- Words laid over the language in force, key by key: the landmark's name (label), every control and both sentences.
live'polite' | 'off'Defaultpolite- Whether the range announces a page change.
disabledbooleanDefaultfalse- Takes every control away without taking the row out of the page.
loadingbooleanDefaultfalse- A page change in flight: every move is refused, the row keeps its size, and the root says aria-busy.
Events
| Name | Payload | When |
|---|---|---|
onPageChange | (page: number, request: ChangeRequest<number>) | Before the page moves. The request carries the page it replaces, the reason — pointer, keyboard or programmatic — and the originating event, and cancelling it commits nothing. programmatic arrives unasked twice: when the collection shrinks under a reader who was past its new end, and after a page-size change that moved the window they are looking through. |
onPageSizeChange | (pageSize: number, request: ChangeRequest<number>) | Before the page size moves, with the reason select. It is followed by a programmatic onPageChange whenever keeping the first item of the current page visible means landing on a different page. |
Composition
render(props) => ReactNode- On every partSubstitutes the rendered element. Every data attribute is handed to it, so a router link keeps them.
refRef<HTMLElement>- On every partReaches the element, and focus() with it.
onClickMouseEventHandler- On every triggerComposed rather than replaced. Call preventDefault to keep the page where it is.
usePagination()() => PaginationContextValue- On inside a PaginationgoToPage, next, previous, setPageSize, and the arithmetic they came from: page, pages, range, items.
PaginationDefaultsProvidersiblingCount | boundaryCount | defaultPageSize | pageSizeOptions | live- On ApplicationSets those five once for everything below it; a prop on the paginator still wins.
Parts
| Part | Element | Required | Purpose |
|---|---|---|---|
root | nav | Yes | The navigation landmark and its name. Carries data-ui="pagination", holds the page and the page size, runs the arithmetic, and is the container the compaction measures. |
list | ul | No | The row of page numbers, rendered by PaginationItems. It is not drawn at all when the total is unknown, because there are no numbers to draw. |
item | li | No | One cell of that row: either a page or an ellipsis, never both. |
page | button or a | No | One page. Carries aria-current="page" when it is the one being read, and becomes an anchor the moment itemHref is given. |
ellipsis | span | No | The pages the row does not draw. It is announced to nobody, and it is the character U+2026 as text rather than artwork. |
summary | span | No | "Page 3 of 25", rendered beside the row and displayed instead of it below its own breakpoint, 22rem of inline size. In the DOM whenever the total is known, so the swap announces nothing twice. |
first | button or a | No | Jump to page one. Unavailable on the first page. |
previous | button or a | No | One page back, and the whole of a cursor paginator together with next. |
next | button or a | No | One page forward. The only trigger a collection with no known total can enable. |
last | button or a | No | Jump to the last page. It needs a total, so it is disabled when count is unset. |
status | p | No | "21–40 of 482", and the polite live region that announces a page change. Give it children to say something else. |
page-size | select | No | How many items a page holds. A native select, so its popup follows the color scheme the theme already emits. |
page-size-label | label | No | The visible name, wrapping the select rather than pointing at it — which is what gives the control its accessible name from the platform, with no generated id. |
Theming
Each token is a CSS custom property: set it in a theme, or on any element to retune every pagination inside it.
Pagination tokens
| Token | Default |
|---|---|
--slotted-pagination-color | var(--slotted-text, CanvasText) |
--slotted-pagination-color-disabled | var(--slotted-disabled-foreground, GrayText) |
--slotted-pagination-color-muted | var(--slotted-text-muted, GrayText) |
--slotted-pagination-current-color | var(--slotted-tone-accent-on-solid, HighlightText) |
--slotted-pagination-current-surface | var(--slotted-tone-accent-solid, Highlight) |
--slotted-pagination-ellipsis-lift | 0.5cap |
--slotted-pagination-ellipsis-tracking | 0.05em |
--slotted-pagination-font-family | var(--slotted-font-family-sans, inherit) |
--slotted-pagination-font-size | var(--slotted-control-font-size-md, 13px) |
--slotted-pagination-gap | var(--slotted-space-1, 0.125rem) |
--slotted-pagination-glyph-size | var(--slotted-control-icon-size-md, 16px) |
--slotted-pagination-item-gap | var(--slotted-space-1, 0.125rem) |
--slotted-pagination-item-padding | var(--slotted-space-2, 0.25rem) |
--slotted-pagination-item-weight | var(--slotted-font-weight-medium, 500) |
--slotted-pagination-page-size-gap | var(--slotted-space-3, 0.375rem) |
--slotted-pagination-page-size-inset | var(--slotted-space-3, 0.375rem) |
--slotted-pagination-page-size-surface | var(--slotted-control-surface, Field) |
--slotted-pagination-radius | var(--slotted-control-radius, 4px) |
--slotted-pagination-row-gap | var(--slotted-space-4, 0.5rem) |
--slotted-pagination-surface-active | var(--slotted-tone-accent-subtle-active, ButtonFace) |
--slotted-pagination-surface-hover | var(--slotted-tone-accent-subtle-hover, ButtonFace) |
--slotted-pagination-target | var(--slotted-control-height-md, 34px) |
--slotted-pagination-text-gap | var(--slotted-space-4, 0.5rem) |
Theme tokens it reads
| Token | Default |
|---|---|
--slotted-border-strong | Set per scheme by the theme |
--slotted-control-border-color | Set per scheme by the theme |
--slotted-control-border-width | var(--slotted-border-width-thin) |
--slotted-control-font-size-md | comfortable 13px · compact 12px · dense 12px |
--slotted-control-height-md | comfortable 34px · compact 28px · dense 26px |
--slotted-control-icon-size-md | comfortable 16px · compact 14px · dense 13px |
--slotted-control-padding-inline-sm | comfortable 10px · compact 8px · dense 6px |
--slotted-control-radius | var(--slotted-radius-sm) |
--slotted-control-shadow | Set per scheme by the theme |
--slotted-control-surface | Set per scheme by the theme |
--slotted-control-transition-duration | var(--slotted-duration-short) |
--slotted-control-transition-easing | var(--slotted-easing-standard) |
--slotted-disabled-background | Set per scheme by the theme |
--slotted-disabled-border | Set per scheme by the theme |
--slotted-disabled-foreground | Set per scheme by the theme |
--slotted-focus-ring-color | Set per scheme by the theme |
--slotted-focus-ring-offset | var(--slotted-border-width-thick) |
--slotted-focus-ring-width | var(--slotted-border-width-thick) |
--slotted-font-family-sans | 'Geist Variable', ui-sans-serif, system-ui, sans-serif |
--slotted-font-weight-medium | 500 |
--slotted-space-1 | 0.125rem |
--slotted-space-2 | 0.25rem |
--slotted-space-3 | 0.375rem |
--slotted-space-4 | 0.5rem |
--slotted-space-6 | 1rem |
--slotted-text | Set per scheme by the theme |
--slotted-text-muted | Set per scheme by the theme |
--slotted-tone-accent-on-solid | Set per scheme by the theme |
--slotted-tone-accent-solid | Set per scheme by the theme |
--slotted-tone-accent-subtle-active | Set per scheme by the theme |
--slotted-tone-accent-subtle-hover | Set per scheme by the theme |