Pagination
Page links for long lists, built on a labelled nav landmark.
Use pagination to split a long list into pages people can link to, such as an admin table. Every page is a real URL, so it works without JavaScript and pages render on the server from searchParams.
Showing 31 to 40 of 118 invoices
Installation
Pro components install from the Aloxe registry with the shadcn CLI. Once per project, add the registry to components.json and put a registry token in the ALOXE_TOKEN environment variable. Registry has the details.
{
"registries": {
"@aloxe": {
"url": "https://<aloxe-site>/r/{name}.json",
"headers": { "Authorization": "Bearer ${ALOXE_TOKEN}" }
}
}
}Then add the component:
npx shadcn@latest add @aloxe/paginationThe CLI copies the source into components/ui/aloxe/, so it never overwrites your own ui components. It also installs @aloxe/react, @aloxe/tokens and @base-ui/react.
Import the tokens once in your global stylesheet, after Tailwind, and add an @source for the copied files and one for @aloxe/react, so Tailwind generates their classes. @source paths are relative to the stylesheet; these assume src/app/globals.css and src/components/ui/aloxe/.
@import "tailwindcss";
@import "@aloxe/tokens/aloxe.css";
@import "@aloxe/tokens/tailwind.css";
@source "../components/ui/aloxe";
@source "../../node_modules/@aloxe/react/dist";Installation covers the theme and brand attributes.
Usage
import Link from "next/link";
import { Pagination } from "@/components/ui/aloxe/pagination";
export default async function InvoicesPage({ searchParams }: PageProps<"/invoices">) {
const page = Number((await searchParams).page ?? 1);
return (
<Pagination
page={page}
pageCount={12}
href={(p) => `/invoices?page=${p}`}
linkComponent={Link}
/>
);
}Pass page, pageCount and href, and Pagination builds the list: previous, the first and last pages, the current page with one page on each side, gaps, and next. linkComponent swaps the plain <a> for your router's link.
With the default siblingCount of 1 the list takes up to nine 32 px items, which wraps under about 330 px. On narrow layouts pass siblingCount={0}: the list keeps the first, current and last pages and fits a 375 px phone. The previews on this page use it.
Examples
First, last and short lists
On the first page, previous is dimmed and isn't a link; the same goes for next on the last page. When every page fits in the slots, there are no gaps.
Custom items
Pass PaginationItem children to build the list yourself, such as a compact pager for a log that only moves one page at a time.
Accessibility
| Key | Action |
|---|---|
| Tab and Shift+Tab | Move between the page links. |
| Enter | Follows the focused link. |
- A
navlandmark named "Pagination" around a list of links. If a page has two, give each its ownaria-label. - The current page has
aria-current="page"and differs by its background and text colour. - Previous and next are named "Previous page" and "Next page"; page links are named "Page 3". Change them with
previousLabel,nextLabelandpageLabelfor other languages. - Gaps and dimmed edge links are hidden from screen readers, so the list reads as the pages you can actually go to.
- Items are 32 px square. On touch layouts, keep at least 8 px around the control so taps don't land on the wrong page.
API reference
Every part accepts className and renders a data-aloxe attribute you can target in CSS, such as [data-aloxe="pagination-item"]. The page range helper paginationRange(page, pageCount, siblings) is exported too.
Pagination
Extends <nav>.
| Prop | Type | Default | Description |
|---|---|---|---|
| page | number | 1 | The current page, 1-based. With pageCount and href, Pagination builds its own items. |
| pageCount | number | Total number of pages. | |
| href | (page: number) => string | Builds each page's URL, such as (page) => `/invoices?page=${page}`. | |
| siblingCount | number | 1 | Pages shown on each side of the current one before a gap. 1 gives 7 slots at most. |
| linkComponent | ElementType | "a" | The element for links, such as Next.js Link. |
| previousLabel | string | "Previous page" | Accessible name of the previous link. |
| nextLabel | string | "Next page" | Accessible name of the next link. |
| pageLabel | (page: number) => string | (page) => `Page ${page}` | Accessible name of each page link. |
| children | ReactNode | PaginationItem elements, to build the list yourself instead of from page, pageCount and href. | |
| aria-label | string | "Pagination" | Names the nav landmark. Change it when a page has more than one pagination. |
| className | string | Classes for the nav element. |
PaginationItem
Extends <li> + <a>.
| Prop | Type | Default | Description |
|---|---|---|---|
| kind | "page" | "previous" | "next" | "ellipsis" | "page" | page shows its children; previous and next show a chevron; ellipsis marks skipped pages. |
| href | string | The page's URL. Without it, the item renders dimmed and isn't a link. | |
| current | boolean | false | The page being shown. Sets aria-current="page". |
| disabled | boolean | false | For previous or next at the first or last page: dimmed, not a link, hidden from screen readers. |
| linkComponent | ElementType | "a" | The element for the link, such as Next.js Link. |
| aria-label | string | Required for previous and next ("Previous page"). Optional for page numbers. | |
| className | string | Merged with the link's default classes. |
Figma
Matches the Pagination and Pagination item components in the Pro Figma file. Pagination item State=Current maps to current; the chevron and ellipsis items map to kind.
See Figma for where to get the file and how its names map to code.
Pro
Pagination is part of Aloxe Pro. The previews on this page are open to everyone; the Code tab shows the example source once you sign in with a Pro license. See Access and licenses and Pricing.