Pagination
A set of components for navigating through paginated content.
npx vayu-ui init #one time only
npx vayu-ui add pagination
npx vayu-ui add -t pagination #with test case needs
<Pagination.Root>
<Pagination.Info
totalItems={100}
pageSize={10}
currentPage={1}
/>
<Pagination.Buttons
currentPage={1}
totalPages={10}
hrefBuilder={(page) => `?page=${page}`}
/>
</Pagination.Root>
<Pagination.Compact
currentPage={1}
totalPages={10}
hrefBuilder={(page) => `?page=${page}`}
/>
import Pagination from "@/components/ui/Pagination";
<Pagination.Root>
<Pagination.Info />
<Pagination.Buttons />
</Pagination.Root>
<Pagination.Compact />
- Must include:
- Keyboard support (Tab, Space, Enter navigation for links and buttons)
- ARIA attributes (
aria-label, aria-current="page")
- Focus behavior (Focus styles visible, correct semantic HTML elements structure)
- A
<nav> element with aria-label="pagination" lets assistive technologies know the region's purpose.
- The active page is indicated using
aria-current="page" on the current page link.
- Pagination Info announces visually "Showing X to Y of Z" properly to indicate list size context.
src/components/ui/Pagination
├── CompactPagination.tsx
├── Pagination.tsx
├── PaginationButtons.tsx
├── PaginationInfo.tsx
├── PaginationRoot.tsx
├── index.ts
├── types.ts
└── utils.ts
| Prop | Type | Description |
|---|
| children | ReactNode | Content for the pagination |
| aria-label | string | Accessible label for the nav |
| Prop | Type | Description |
|---|
| totalItems | number | Total number of items |
| pageSize | number | Items per page |
| currentPage | number | The current active page |
| Prop | Type | Description |
|---|
| currentPage | number | The current active page |
| totalPages | number | Total number of pages |
| hrefBuilder | (page: number) => string | Function returning href |
| pageRange | "compact" | "extended" | "full" | Strategy for rendering page links |
| siblingCount | number | Pages to show around current page |
| Prop | Type | Description |
|---|
| currentPage | number | The current active page |
| totalPages | number | Total number of pages |
| hrefBuilder | (page: number) => string | Function returning href given a page |