Pagination
Page links with previous and next.
Pages
import {
Pagination,
PaginationContent,
PaginationEllipsis,
PaginationItem,
PaginationLink,
PaginationNext,
PaginationPrevious,
} from "@/components/ui/pagination"
export default function PaginationPages() {
return (
<Pagination aria-label="Invoice pages">
<PaginationContent>
<PaginationItem>
<PaginationPrevious href="#page-1" />
</PaginationItem>
<PaginationItem>
<PaginationLink href="#page-1">1</PaginationLink>
</PaginationItem>
<PaginationItem>
<PaginationLink href="#page-2" isActive>
2
</PaginationLink>
</PaginationItem>
<PaginationItem>
<PaginationLink href="#page-3">3</PaginationLink>
</PaginationItem>
<PaginationItem>
<PaginationEllipsis />
</PaginationItem>
<PaginationItem>
<PaginationLink href="#page-12">12</PaginationLink>
</PaginationItem>
<PaginationItem>
<PaginationNext href="#page-3" />
</PaginationItem>
</PaginationContent>
</Pagination>
)
}
Previous and next only
import { Pagination, PaginationContent, PaginationItem, PaginationNext, PaginationPrevious } from "@/components/ui/pagination"
export default function PaginationPreviousAndNextOnly() {
return (
<Pagination aria-label="Release notes">
<PaginationContent className="w-full max-w-sm justify-between">
<PaginationItem>
<PaginationPrevious href="#release-4-1" text="Release 4.1" aria-label="Previous: Release 4.1" />
</PaginationItem>
<PaginationItem>
<PaginationNext href="#release-4-3" text="Release 4.3" aria-label="Next: Release 4.3" />
</PaginationItem>
</PaginationContent>
</Pagination>
)
}
Link sizes
import { Pagination, PaginationContent, PaginationItem, PaginationLink } from "@/components/ui/pagination"
const sizes = [
{ size: "icon-sm", name: "Small task pages" },
{ size: "icon", name: "Default task pages" },
{ size: "icon-lg", name: "Large task pages" },
] as const
export default function PaginationLinkSizes() {
return (
<div className="flex flex-col gap-4">
{sizes.map(({ size, name }) => (
<Pagination key={size} aria-label={name}>
<PaginationContent>
{[1, 2, 3, 4].map((page) => (
<PaginationItem key={page}>
<PaginationLink href={`#page-${page}`} size={size} isActive={page === 1}>
{page}
</PaginationLink>
</PaginationItem>
))}
</PaginationContent>
</Pagination>
))}
</div>
)
}
Installation
npx shadcn@latest add @khaeli/paginationbunx --bun shadcn@latest add @khaeli/paginationInstall @khaeli/foundation first: this item's styling lives in its tokens and [data-slot] rules.
Installs with
- Registry items
- npm packages
- @keyline-icons/react ^2.2.0
Keyboard
Tab- Moves through previous, the page links and next, in order.
EnterSpace- Follow the focused link. The links are rendered through @khaeli/button, so both keys work.
Accessible name
Paginationis anavlandmark named "pagination". When a page has more than one, give each its ownaria-label.PaginationPreviousandPaginationNextare named "Go to previous page" and "Go to next page"; their visible text is hidden below 640px and the name stays. If you changetext, changearia-labelto match.- The current page link has
aria-current="page".PaginationEllipsisis hidden from assistive technology. - There is no disabled state: on the first or last page, leave the previous or next link out.
Registry JSON
The item as the shadcn CLI reads it, with every file it ships: https://ui.khaeli.com/r/pagination.json