Ir al contenido
Español

Cómo funciona

A pager that handles page numbers only; fetch or slice your data in onPageChange. The first and last page stay visible, with siblingCount pages on each side of the current one and ellipses in the gaps. The current page is an ink pill that slides from the old cell to the new one; its position is computed in CSS from the cell index, so nothing is measured. The number of cells is constant and each cell is sized by the digit count of the last page, so the pager keeps its width as you page through. Page and page size work controlled or uncontrolled. On touch screens the controls grow to 44px and the numbers collapse to “3 / 12”.

Úsalo para

  • Lists, card walls and search results that need a visible total and direct access to a page.
  • Under a table that has no pager of its own.
  • Narrow places such as sidebars and dialog footers: use simple mode.

Busca otra opción cuando

  • Feeds that people only scroll down: use “load more” or infinite loading.
  • Cursor-based APIs without a total: offer previous and next only.
  • A dozen items in total: show them all.

Uso

import { useState } from 'react'
import { Pagination } from './Pagination.jsx'

// Controlled: fetch or slice the data in onPageChange.
export function RouteList({ total }) {
  const [page, setPage] = useState(1)
  const [pageSize, setPageSize] = useState(20)
  return (
    <Pagination
      label="Routes pagination"
      total={total}
      page={page}
      onPageChange={setPage}
      pageSize={pageSize}
      onPageSizeChange={setPageSize}
      pageSizeOptions={[20, 50, 100]}
      showTotal
      showJumper
    />
  )
}

// Narrow space: compact and uncontrolled.
<Pagination simple size="sm" total={128} onPageChange={(page) => load(page)} />

Propiedades

PropiedadTipoPor defectoQué hace
totalnumber—Total number of items. Required. The page count is total ÷ page size rounded up, at least 1.
pagenumber—Controlled current page, starting at 1. Out-of-range values are clamped.
defaultPagenumber1Initial page when uncontrolled.
onPageChange(page, pageSize) => void—Called when the page changes, including when a new page size moves the page.
pageSizenumber—Controlled page size.
defaultPageSizenumber10Initial page size when uncontrolled.
onPageSizeChange(pageSize) => void—Called when the page size changes.
pageSizeOptionsnumber[]—Page sizes to offer, such as [10, 20, 50]. The menu appears only when this is set.
siblingCountnumber1Page numbers shown on each side of the current page. Use 0 in narrow spaces.
showTotalboolean | ((total, [from, to]) => ReactNode)falseShows the total. Pass a function to write your own text; it receives the range of the current page.
showJumperbooleanfalseShows a digits-only jump field that commits on Enter or blur, then clears.
simplebooleanfalseCompact mode: previous, “2 / 12”, next.
size'sm' | 'md' | 'lg''md'Button height 28 / 36 / 44px. Use sm under a dense table.
disabledbooleanfalseDisables every control, for example while loading.
labelstring'Pagination'Accessible name of the navigation region. Give each pager on a page its own name.
labelsobject—Replaces built-in text (previous, next, page, pageOf, total, pageSize, perPage, jumpBefore, jumpAfter, jump). Shallow-merged over the English defaults.
...restHTMLAttributes—Other attributes, such as className and style, go to the root <nav>.

Accesibilidad

  • The root is a <nav> with a label; each page is a button named “Page 3”, and the current one carries aria-current="page".
  • Inside the pager, Left and Right move one page, Home and End go to the first and last; focus lands on the new current page.
  • When a step button becomes disabled, focus moves to the current page instead of getting stuck.
  • Each page change is announced through a polite live region.
  • Reduced motion: the pill moves without gliding, the number does not scale and colours switch without a transition.

Movimiento

The ink pill glides to the new page in 340ms with ease-out and the new number settles from 82% scale as it arrives. Hover colours and focus rings: 160ms standard; a pressed cell or arrow scales to 0.92 for 100ms. The width never changes.

Añádelo a tu proyecto

Copia la instrucción en Codex o Claude Code. El agente lee el código publicado, te muestra lo que va a escribir y añade el componente junto a los tuyos.

Pagination.jsxpagination.csstokens.cssREADME.md

Los dos archivos se instalan juntos. La hoja de estilos lee las variables de tokens.css y lleva valores de reserva, así que también funciona sola.

Navegación