GooseUI

Components

Pagination

New

Page navigation made of real links. The current page gets aria-current="page", long ranges collapse into an ellipsis, Previous and Next are disabled at the ends. Server component, no JavaScript: it works without hydration and every page opens in a new tab.

Installation

npx shadcn@latest add @gooseui/pagination
pnpm dlx shadcn@latest add @gooseui/pagination
yarn dlx shadcn@latest add @gooseui/pagination
bunx --bun shadcn@latest add @gooseui/pagination

Usage

import { Pagination } from "@/components/ui/pagination"

export default function Example() {
  return <Pagination page={5} pageCount={20} href="/blog?page={page}" />
}

Examples

URL template

href accepts a string with {page} or a function (page) => string. In this demo the links only change the hash.

<Pagination
  page={1}
  pageCount={12}
  siblings={2}
  href={(p) => `/items/${p}`}
/>

Icon only and few pages

iconOnly keeps the chevrons; with a small pageCount there is no ellipsis.

<Pagination page={3} pageCount={5} iconOnly href="?page={page}" />

Custom texts

Texts are English by default; pass your own for any language.

<Pagination
  page={20}
  pageCount={20}
  href="?page={page}"
  previousLabel="Back"
  nextLabel="Forward"
  label="Navigation"
  pageLabel={(n) => `Page ${n}`}
/>

Props

PropTypeDefaultDescription
pagenumber-Current page, 1-based
pageCountnumber-Total number of pages
hrefstring | ((page: number) => string)-URL template with {page}, or a function that returns the URL of a page
siblingsnumber1Pages shown on each side of the current one
boundarynumber1Pages always shown at both ends
previousLabelstring"Previous"Text of the previous link
nextLabelstring"Next"Text of the next link
labelstring"Pagination"Accessible name of the nav landmark
pageLabel(page: number) => string(n) => `Page ${n}`Builds the accessible name of a page link
iconOnlybooleanfalseHide the Previous/Next text and keep only the chevrons