Playground

Pagination

Move between pages of results.

  • Built on native elements
  • 2 parts, named exports
  • A nav landmark; each page is a button named "Page N" and the current one has aria-current=page.
  • Prev and Next are disabled at the ends.
  • The gap marker is hidden from assistive tech.
  • Styles in one file: 18-navigation.css

Import

import '@monoline/css';
import {Pagination} from '@monoline/react';

Not installed yet? Pick a route.

Copies the source and its styles into your project.

npx monoline add pagination

Usage

import {useState} from 'react';
import {Pagination} from '@monoline/react';

function Demo1() {
  const [page, setPage] = useState(5);
  return <Pagination page={page} pageCount={20} onPageChange={setPage} />;
}

<Demo1 />

Anatomy

Import the parts you need and nest them like this.

import {Pagination, pageWindow} from '@monoline/react';

<Pagination>
  <pageWindow />
</Pagination>

Examples

With gaps

Props

PaginationProps

PropTypeDefaultDescription
pagenumber–Current page, 1-based, when controlled. Pair with `onPageChange`.
defaultPagenumber1The starting page when uncontrolled. Default 1.
pageCount requirednumber–Total number of pages.
onPageChange((page: number) => void)–Called with the new 1-based page number when the user picks a page or presses Prev or Next.
siblingsnumber1How many numbers to show on each side of the current page.

Data Attributes

State is exposed through attributes. Style it with these selectors, not with class toggles.

AttributeStylesheet
[aria-current="page"]18-navigation.css
[aria-current="step"]18-navigation.css
[aria-selected="true"]18-navigation.css
[data-state="done"]18-navigation.css

CSS classes

ClassStylesheet
.brand18-navigation.css
.crumbs18-navigation.css
.pager18-navigation.css
.step18-navigation.css
.steps18-navigation.css
.tab18-navigation.css
.tabpanel18-navigation.css
.topbar18-navigation.css
.topbar-nav18-navigation.css

Customization

Style it with the kit's tokens in your own CSS, loaded after @monoline/css. Prefer the attributes above over extra classes. See Theming for every token.

app.css
.brand {
  border-color: var(--accent);
}
.brand[aria-current="page"] {
  background: var(--wash);
}

Accessibility

  • A nav landmark; each page is a button named "Page N" and the current one has aria-current=page.
  • Prev and Next are disabled at the ends.
  • The gap marker is hidden from assistive tech.