Getting started

Actions

Forms

Layout

Navigation

Overlays

Feedback

Data display

Controllers

Helpers

Recipes

Pagination

Pagination provides accessible page navigation for controlled collections.

Try it

Usage

RuiPagination renders previous, numbered, and next controls by default. Listen for rui-page-change and update the controlled page prop from your data layer.

import { RuiPagination } from '@ecopages/radiant-ui/pagination';

<RuiPagination
  label="Search result pages"
  page={page}
  pageCount={pageCount}
  on:rui-page-change={(event) => setPage(event.detail.page)}
/>

Pass children to replace the default navigation chrome while keeping the rui-pagination event contract.

Below 40rem, or with class="rui-pagination--compact", the default chrome collapses to icon-only previous / next controls around a Page n of m position.

The default chrome copy is English. Pass the label view props to localize it:

<RuiPagination
  label="Seiten"
  page={page}
  pageCount={pageCount}
  previousText="Zurück"
  previousLabel="Vorherige Seite"
  nextText="Weiter"
  nextLabel="Nächste Seite"
  pageLabel={(page) => `Seite ${page}`}
  statusLabel={(page, pageCount) => `Seite ${page} von ${pageCount}`}
/>

A listing that pages by URL needs links: they work without JavaScript, a router can prefetch them, and each page has an address to share. Pass getHref and each page control becomes an <a> to getHref(page), with aria-current="page" on the current page.

<RuiPagination
  label="Search result pages"
  page={page}
  pageCount={pageCount}
  getHref={(target) => `/list/page/${target}`}
/>

The browser, or your router, handles a click on a link: rui-page-change is not emitted for it. A previous or next control with no page to go to, and every control while disabled, stays a disabled button, because a link cannot be disabled.

Custom markup

<rui-pagination> coordinates any light-DOM tree that matches its query contract. The Rui* helpers stamp these targets; they are not required.

import '@ecopages/radiant-ui/pagination';

<rui-pagination page={2} page-count={5} label="Search result pages">
  <nav class="rui-pagination__nav" aria-label="Search result pages">
    <button type="button" class="rui-pagination__link" data-pagination-page={1}>
      Previous
    </button>
    <button type="button" class="rui-pagination__link" data-pagination-page={2} aria-current="page">
      2
    </button>
    <button type="button" class="rui-pagination__link" data-pagination-page={3}>
      Next
    </button>
  </nav>
</rui-pagination>

BEM classes are presentation-only. Each navigable control needs data-pagination-page with a one-based page number.

Theming

PartCSS roles
LinksReuses RuiButton ghost and filled variants
Ellipsison-surface

API

RuiPagination wraps <rui-pagination> and supplies default navigation controls.

Attributes (<rui-pagination>)

AttributeTypeDefaultDescription
labelstringPaginationAccessible name for the navigation landmark.
pagenumber1Current one-based page.
page-countnumber1Total number of pages.
disabledbooleanfalseDisable page navigation.
sibling-countnumber1Pages shown on each side of the current page.

JSX view props

These props configure the default RuiPaginationNav chrome rendered by RuiPagination (and accepted by RuiPaginationNav directly). They are not custom-element attributes.

PropTypeDefaultDescription
previousTextstringPreviousVisible previous-control text; visually hidden in compact chrome.
previousLabelstringGo to previous pageAccessible name of the previous control.
nextTextstringNextVisible next-control text; visually hidden in compact chrome.
nextLabelstringGo to next pageAccessible name of the next control.
pageLabel(page: number) => stringGo to page nAccessible name of each page-number control.
statusLabel(page: number, pageCount: number) => stringPage n of mPage position announced (aria-live="polite") in compact chrome.
getHref(page: number) => stringRenders each available page control as a link to getHref(page) instead of a button. Ignored when children replace the chrome.

Light-DOM contract

TargetRequiredHost writesAuthor owns
[data-pagination-page]yes (per control)—data-pagination-page (one-based page number); an <a href> control navigates on its own and emits no rui-page-change

Nested hosts: none.

Events

EventDetailDescription
rui-page-change{ page: number }Emitted when a button page control is activated. A link control, an <a href> such as the ones getHref renders, navigates on its own and emits nothing.

View helpers

ComponentTarget stampedNotes
RuiPagination<rui-pagination>Renders RuiPaginationNav by default.
RuiPaginationNav[data-pagination-page] on each linkPrevious, numbered, and next controls.

CSS classes

ClassDescription
.rui-paginationNavigation root.
.rui-pagination__listPage controls list.
.rui-pagination__linkPrevious, next, and page control.
.rui-pagination__pagePage-number item; __page--current marks the active page.
.rui-pagination--compactForce the chrome used below 40rem: icon-only previous / next around the page position.
.rui-pagination__statusWrapper for the compact page-position label.
.rui-pagination__status-labelMuted compact label (statusLabel, default Page n of m); hidden when numbered pages are shown.
.rui-pagination__ellipsisHidden range marker between page numbers.