# Pagination

Page navigation primitives and a stateful controls convenience component.

Page navigation primitives and a stateful controls convenience component.

```tsx
import { Pagination, Stack, Text } from "@zentara-co/zenos-ui";
import { useState } from "react";

function PaginationExample() {
  const [page, setPage] = useState(2);
  return (
    <Stack gap="3" align="center">
      <Pagination.Controls currentPage={page} totalPages={8} onPageChange={setPage} />
      <Text size="s" color="subtle">
        Page {page} of 8
      </Text>
    </Stack>
  );
}
```

## Import

```tsx
import { Pagination } from "@zentara-co/zenos-ui";
```

## Controlled pages

`Pagination.Controls` calculates a compact sequence and reports the requested page. The application remains responsible for fetching or revealing the corresponding content.

```tsx
const [page, setPage] = useState(1);

<Pagination.Controls currentPage={page} totalPages={12} onPageChange={setPage} />;
```

## Page size

Pass `pageSize` and `onPageSizeChange` when a table should let someone choose how many rows appear. The select stays hidden without those props. `pageSizeOptions` defaults to 10, 20, 50, and 100. `pageSizeSide` places the select at `start` or `end` of the page buttons, and defaults to `start`. The older `left` and `right` values remain compatible aliases. Recompute `totalPages` from the new size in `onPageSizeChange`, and return to page 1 when the previous page would no longer exist.

```tsx
import { Pagination, Stack } from "@zentara-co/zenos-ui";
import { useState } from "react";

function PaginationPageSizeExample() {
  const [page, setPage] = useState(1);
  const [pageSize, setPageSize] = useState(20);
  const totalItems = 480;
  const totalPages = Math.max(1, Math.ceil(totalItems / pageSize));

  return (
    <Stack className="w-full" gap="6">
      <Pagination.Controls
        aria-label="Rows per page at the start"
        className="w-full"
        currentPage={Math.min(page, totalPages)}
        pageSize={pageSize}
        pageSizeOptions={[10, 20, 50, 100]}
        pageSizeSide="start"
        totalPages={totalPages}
        onPageChange={setPage}
        onPageSizeChange={(size) => {
          setPageSize(size);
          setPage(1);
        }}
      />
      <Pagination.Controls
        aria-label="Rows per page at the end"
        className="w-full"
        currentPage={Math.min(page, totalPages)}
        pageSize={pageSize}
        pageSizeOptions={[10, 20, 50, 100]}
        pageSizeSide="end"
        totalPages={totalPages}
        onPageChange={setPage}
        onPageSizeChange={(size) => {
          setPageSize(size);
          setPage(1);
        }}
      />
    </Stack>
  );
}
```

## Boundaries and direction labels

Previous and Next disable automatically at the first and last page. Set `showDirectionText` when the surrounding width can accommodate explicit labels.

The built-in chevrons mirror in RTL. Keep custom previous and next icons direction-aware when replacing them.

```tsx
import { Pagination, Stack, Text } from "@zentara-co/zenos-ui";

function PaginationBoundaryExample() {
  return (
    <Stack gap="6" className="w-full">
      <Stack gap="2" align="center">
        <Text size="s" weight="medium">
          First page
        </Text>
        <Pagination.Controls
          currentPage={1}
          totalPages={12}
          onPageChange={() => undefined}
          showDirectionText
          aria-label="First-page example"
        />
      </Stack>
      <Stack gap="2" align="center">
        <Text size="s" weight="medium">
          Last page
        </Text>
        <Pagination.Controls
          currentPage={12}
          totalPages={12}
          onPageChange={() => undefined}
          showDirectionText
          aria-label="Last-page example"
        />
      </Stack>
    </Stack>
  );
}
```

## Compound composition

Use the compound parts when routing, custom page ranges, or custom direction controls make the convenience component unsuitable.

```tsx
import { Pagination } from "@zentara-co/zenos-ui";

function PaginationCompoundExample() {
  return (
    <Pagination.Root aria-label="Search result pages">
      <Pagination.Content>
        <Pagination.Item>
          <Pagination.Previous showText={false} />
        </Pagination.Item>
        <Pagination.Item>
          <Pagination.Page>1</Pagination.Page>
        </Pagination.Item>
        <Pagination.Item>
          <Pagination.Ellipsis />
        </Pagination.Item>
        <Pagination.Item>
          <Pagination.Page isActive>8</Pagination.Page>
        </Pagination.Item>
        <Pagination.Item>
          <Pagination.Page>9</Pagination.Page>
        </Pagination.Item>
        <Pagination.Item>
          <Pagination.Next showText={false} />
        </Pagination.Item>
      </Pagination.Content>
    </Pagination.Root>
  );
}
```

## Custom styling

Use `className` on `Pagination.Controls` to style the navigation surface. Its stable `data-slot` attributes can target page and direction buttons, while `data-active` identifies the current page. Keep the existing `aria-current`, disabled, hover, and focus-visible behavior intact when changing the visual treatment.

```tsx
import { Pagination, Stack, Text } from "@zentara-co/zenos-ui";
import { useState } from "react";

function PaginationCustomStylingExample() {
  const [page, setPage] = useState(3);

  return (
    <Stack gap="3" align="center" className="w-full">
      <Pagination.Controls
        currentPage={page}
        totalPages={8}
        onPageChange={setPage}
        aria-label="Branded results pagination"
        className="max-w-xl rounded-full border border-border-accent-teal-default bg-background-accent-teal-subtlest-default p-2 shadow-raised [&_[data-slot=pagination-content]]:gap-1.5 [&_[data-slot=pagination-next]]:rounded-full [&_[data-slot=pagination-next]]:text-text-accent-teal-bolder [&_[data-slot=pagination-next]]:hover:bg-background-accent-teal-subtlest-hover [&_[data-slot=pagination-page]]:rounded-full [&_[data-slot=pagination-page]]:text-text-accent-teal-bolder [&_[data-slot=pagination-page]]:hover:bg-background-accent-teal-subtlest-hover [&_[data-slot=pagination-page][data-active]]:bg-background-accent-teal-bolder-default [&_[data-slot=pagination-page][data-active]]:text-text-contrary [&_[data-slot=pagination-page][data-active]]:hover:bg-background-accent-teal-bolder-hover [&_[data-slot=pagination-previous]]:rounded-full [&_[data-slot=pagination-previous]]:text-text-accent-teal-bolder [&_[data-slot=pagination-previous]]:hover:bg-background-accent-teal-subtlest-hover"
      />
      <Text size="s" color="subtle" aria-live="polite">
        Page {page} of 8
      </Text>
    </Stack>
  );
}
```

## Anatomy

```text
Pagination.Root
Pagination.Content
Pagination.Item
Pagination.Page
Pagination.Previous
Pagination.Next
Pagination.Ellipsis
Pagination.Controls
```

## API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| currentPage | number | — | Controlled 1-based current page on Controls. |
| totalPages | number | — | Available page count. |
| onPageChange | (page: number) => void | — | Runs after navigation. |
| showDirectionText | boolean | false | Shows Previous and Next labels on Controls. |
| pageSize | number | — | Selected rows per page. Omit with onPageSizeChange to hide the select. |
| pageSizeOptions | number[] | [10, 20, 50, 100] | Options in the page-size select. |
| onPageSizeChange | (pageSize: number) => void | — | Runs when a page size is chosen. Presence of this callback shows the select. |
| pageSizeLabel | ReactNode | Rows per page | Visible label for the page-size select. |
| pageSizeSide | start \| end \| left \| right | start | Places the page-size select at a logical edge. Left and right remain compatible aliases. |
| isActive | boolean | false | Marks Pagination.Page as the current page. |
| showText | boolean | true | Shows text on Previous and Next compound controls. |
| icon | ReactNode | — | Replaces a Previous or Next chevron. |
| getPaginationPages | (currentPage, totalPages) => PaginationPageEntry[] | — | Returns the compact page and ellipsis sequence used by Controls. |

Unless narrowed above, each DOM-rendering part also accepts its underlying native or Base UI props, including className, style, aria-*, and data-*.

## Accessibility

Pagination renders a labelled navigation landmark containing native buttons. The current page uses `aria-current="page"`, and direction controls retain accessible names when their visible text is hidden. Give multiple paginations distinct `aria-label` values. After a page change, move focus or announce updated results when the content replacement would otherwise be unclear.

Source: https://zenos-ui.pages.dev/components/pagination/