Skip to content
Slotted

Pagination

Moves between pages of a collection the application owns, as numbered pages, as previous and next only, or as links.

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.

bash
pnpm add @slotted/react @slotted/theme @slotted/themes
tsx
import { 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.

One page on each side of the current page and at each endTwo pages on each side of the current page and at each end

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.

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.

The range is announced after each page changeThe range is displayed and never announced

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.

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.

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

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.

At the last pageLoading the next pageDisabled

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.

482 invoices, page 25. Last change: none yet.

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.

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.

Inherits two siblings and 50 rowsStates no siblings and keeps the rest

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.

Accessibility

KeyEffectFocus
Tabmoves to each trigger, each page and the page size in reading orderthe next control
Enteractivates the focused control, or follows it when itemHref made it a linkstays, unless the control became unavailable
Spaceactivates the focused control while it is a buttonstays, 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.
defaultPagenumberDefault 1
The page an uncontrolled paginator starts from, read once.
pageSizenumber
Present means controlled, like page.
defaultPageSizenumberDefault 20
The page size it starts from, read once.
pageSizeOptionsreadonly number[]Default [10, 20, 50, 100]
What the page-size control offers.
siblingCountnumberDefault 1
Pages drawn either side of the current one.
boundaryCountnumberDefault 1
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'Default polite
Whether the range announces a page change.
disabledbooleanDefault false
Takes every control away without taking the row out of the page.
loadingbooleanDefault false
A page change in flight: every move is refused, the row keeps its size, and the root says aria-busy.

Events

NamePayloadWhen
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

PartElementRequiredPurpose
rootnavYesThe 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.
listulNoThe 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.
itemliNoOne cell of that row: either a page or an ellipsis, never both.
pagebutton or aNoOne page. Carries aria-current="page" when it is the one being read, and becomes an anchor the moment itemHref is given.
ellipsisspanNoThe pages the row does not draw. It is announced to nobody, and it is the character U+2026 as text rather than artwork.
summaryspanNo"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.
firstbutton or aNoJump to page one. Unavailable on the first page.
previousbutton or aNoOne page back, and the whole of a cursor paginator together with next.
nextbutton or aNoOne page forward. The only trigger a collection with no known total can enable.
lastbutton or aNoJump to the last page. It needs a total, so it is disabled when count is unset.
statuspNo"21–40 of 482", and the polite live region that announces a page change. Give it children to say something else.
page-sizeselectNoHow many items a page holds. A native select, so its popup follows the color scheme the theme already emits.
page-size-labellabelNoThe 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

TokenDefault
--slotted-pagination-colorvar(--slotted-text, CanvasText)
--slotted-pagination-color-disabledvar(--slotted-disabled-foreground, GrayText)
--slotted-pagination-color-mutedvar(--slotted-text-muted, GrayText)
--slotted-pagination-current-colorvar(--slotted-tone-accent-on-solid, HighlightText)
--slotted-pagination-current-surfacevar(--slotted-tone-accent-solid, Highlight)
--slotted-pagination-ellipsis-lift0.5cap
--slotted-pagination-ellipsis-tracking0.05em
--slotted-pagination-font-familyvar(--slotted-font-family-sans, inherit)
--slotted-pagination-font-sizevar(--slotted-control-font-size-md, 13px)
--slotted-pagination-gapvar(--slotted-space-1, 0.125rem)
--slotted-pagination-glyph-sizevar(--slotted-control-icon-size-md, 16px)
--slotted-pagination-item-gapvar(--slotted-space-1, 0.125rem)
--slotted-pagination-item-paddingvar(--slotted-space-2, 0.25rem)
--slotted-pagination-item-weightvar(--slotted-font-weight-medium, 500)
--slotted-pagination-page-size-gapvar(--slotted-space-3, 0.375rem)
--slotted-pagination-page-size-insetvar(--slotted-space-3, 0.375rem)
--slotted-pagination-page-size-surfacevar(--slotted-control-surface, Field)
--slotted-pagination-radiusvar(--slotted-control-radius, 4px)
--slotted-pagination-row-gapvar(--slotted-space-4, 0.5rem)
--slotted-pagination-surface-activevar(--slotted-tone-accent-subtle-active, ButtonFace)
--slotted-pagination-surface-hovervar(--slotted-tone-accent-subtle-hover, ButtonFace)
--slotted-pagination-targetvar(--slotted-control-height-md, 34px)
--slotted-pagination-text-gapvar(--slotted-space-4, 0.5rem)

Theme tokens it reads

TokenDefault
--slotted-border-strongSet per scheme by the theme
--slotted-control-border-colorSet per scheme by the theme
--slotted-control-border-widthvar(--slotted-border-width-thin)
--slotted-control-font-size-mdcomfortable 13px · compact 12px · dense 12px
--slotted-control-height-mdcomfortable 34px · compact 28px · dense 26px
--slotted-control-icon-size-mdcomfortable 16px · compact 14px · dense 13px
--slotted-control-padding-inline-smcomfortable 10px · compact 8px · dense 6px
--slotted-control-radiusvar(--slotted-radius-sm)
--slotted-control-shadowSet per scheme by the theme
--slotted-control-surfaceSet per scheme by the theme
--slotted-control-transition-durationvar(--slotted-duration-short)
--slotted-control-transition-easingvar(--slotted-easing-standard)
--slotted-disabled-backgroundSet per scheme by the theme
--slotted-disabled-borderSet per scheme by the theme
--slotted-disabled-foregroundSet per scheme by the theme
--slotted-focus-ring-colorSet per scheme by the theme
--slotted-focus-ring-offsetvar(--slotted-border-width-thick)
--slotted-focus-ring-widthvar(--slotted-border-width-thick)
--slotted-font-family-sans'Geist Variable', ui-sans-serif, system-ui, sans-serif
--slotted-font-weight-medium500
--slotted-space-10.125rem
--slotted-space-20.25rem
--slotted-space-30.375rem
--slotted-space-40.5rem
--slotted-space-61rem
--slotted-textSet per scheme by the theme
--slotted-text-mutedSet per scheme by the theme
--slotted-tone-accent-on-solidSet per scheme by the theme
--slotted-tone-accent-solidSet per scheme by the theme
--slotted-tone-accent-subtle-activeSet per scheme by the theme
--slotted-tone-accent-subtle-hoverSet per scheme by the theme