Pagination
A nav landmark around an ordered list of pages. paginationRange decides which pages to show, and your own links or buttons go inside the items, so a router's link works as it is.
On this page
import { Pagination, paginationRange } from '@tounsoo/todae';
import { useState } from 'react';
export default function PaginationButtons() {
const [page, setPage] = useState(10);
const count = 20;
// aria-disabled, not disabled, so a step keeps focus when it reaches an end.
const step = (to: number, label: string) => (
<Pagination.Item>
<button
type="button"
aria-disabled={to < 1 || to > count ? true : undefined}
onClick={() => to >= 1 && to <= count && setPage(to)}
>
{label}
</button>
</Pagination.Item>
);
return (
<Pagination.Root aria-label="Invoice pages">
{step(page - 1, 'Previous')}
{paginationRange({ page, count }).map((item) =>
typeof item === 'number' ? (
<Pagination.Item key={item}>
<button type="button" aria-current={item === page ? 'page' : undefined} onClick={() => setPage(item)}>
{item}
</button>
</Pagination.Item>
) : (
<Pagination.Ellipsis key={item} />
),
)}
{step(page + 1, 'Next')}
</Pagination.Root>
);
}
The page range
paginationRange({ page, count }) returns page numbers, with "start-ellipsis" and "end-ellipsis" for the gaps. It shows the current page, siblings pages on each side of it and boundaries pages at each end; both default to 1. While there are more pages than that, the list keeps one length, so the number of controls does not change as the page does, and a gap always stands for two or more pages. paginationRange shows the list it returns.
Current page and steps
Give the control for the page you are on aria-current="page", and it is drawn as the current page. Give a previous or next step with nowhere to go aria-disabled="true", and it is drawn muted. With buttons, use aria-disabled, not disabled, so the button keeps focus when it reaches an end, as in the example above. A link with nowhere to go is <a role="link" aria-disabled="true"> without href.
Pagination.Root is named "Pagination" unless you pass a non-empty aria-label or aria-labelledby; that default is the pagination string of StringsProvider, English unless you set it, and always English from the @tounsoo/todae/pagination server entry. Name it after what it pages through when a page has more than one. Restyle it through the pagination tokens.
Server Components can import it from @tounsoo/todae/pagination.
Icons
Pagination.Ellipsis with no content shows the ellipsis glyph from a GlyphsProvider, else …; the @tounsoo/todae/pagination server entry always shows …. Previous and next are your own links or buttons, so an icon in them is yours too: hide it and name the control.
import { ChevronLeft, Ellipsis } from 'lucide-react';
<GlyphsProvider glyphs={{ ellipsis: <Ellipsis /> }}>
<Pagination.Root>
<Pagination.Item>
<Link.Root href={`?page=${page - 1}`} aria-label="Previous page">
<ChevronLeft aria-hidden />
</Link.Root>
</Pagination.Item>
…
</Pagination.Root>
</GlyphsProvider>
Accessible composition
Todae handles: The landmark and the list: a named nav around an ol role="list", with each Pagination.Item as a list item. Pagination.Ellipsis is aria-hidden, so screen readers skip the gap. Styles follow the ARIA state on your controls: aria-current="page" is drawn as the current page, and aria-disabled="true" is drawn muted.
You supply: The links or buttons, with their state: aria-current="page" on the current page's control and aria-disabled="true" on a step with nowhere to go. Todae sets neither. Text or aria-label on previous and next controls that show only an arrow. When buttons swap the results in place, Todae announces nothing; move focus to the results or announce the change with useAnnouncer.
Watch for: An element between Pagination.Item and your control: the current and muted styles match the item's direct child, so they stop applying. A current page marked by a class alone, which is neither announced nor drawn as current. A plain button with aria-disabled still fires its click, so its handler must do nothing; a Button.Root ignores the click itself.
When to use
When: A long list or table split into numbered pages that people jump between.
When not: A feed people read in order → a "Load more" button. Steps of one task → a stepper, with its own state.
Props
| Name | Type | Description |
|---|---|---|
children | React.ReactNode | Pagination.Item and Pagination.Ellipsis parts, often from paginationRange. |
| Name | Type | Description |
|---|---|---|
children | React.ReactNode | A link or button. |
| Name | Type | Description |
|---|---|---|
children | React.ReactNode | What the gap shows. Default: "…" |