<!-- index: /slotted/llms.txt -->
# pagination

`data-ui="pagination"` · Moves between pages of results.

## Import

```tsx
import {
  Pagination,
  PaginationDefaultsProvider,
  PaginationFirst,
  PaginationItems,
  PaginationLast,
  PaginationNext,
  PaginationPageSize,
  PaginationPrevious,
  PaginationStatus,
  usePagination,
} from '@slotted/react';
```

## Minimal example

Example

```tsx
import {
  Pagination,
  PaginationItems,
  PaginationNext,
  PaginationPrevious,
} from '@slotted/react/pagination';

export default function PaginationBasic() {
  return (
    <Pagination aria-label="Invoices" count={482} defaultPage={12}>
      <PaginationPrevious />
      <PaginationItems />
      <PaginationNext />
    </Pagination>
  );
}
```

## Anatomy

| Part | Element | Required |
| --- | --- | --- |
| `root` | nav | yes |
| `list` | ul | no |
| `item` | li | no |
| `page` | button or a | no |
| `ellipsis` | span | no |
| `summary` | span | no |
| `first` | button or a | no |
| `previous` | button or a | no |
| `next` | button or a | no |
| `last` | button or a | no |
| `status` | p | no |
| `page-size` | select | no |
| `page-size-label` | label | no |

## Props

| Name | Type | Default | Applies to | Description |
| --- | --- | --- | --- | --- |
| `count` | `number` | — | Pagination | How many items the collection holds. It has no default: left out entirely, the total is unknown, no page numbers are drawn, and no total is invented. |
| `page` | `number` | — | Pagination | Present means controlled, for the life of the component. |
| `defaultPage` | `number` | 1 | Pagination | The page an uncontrolled paginator starts from, read once. |
| `pageSize` | `number` | — | Pagination | Present means controlled, like page. |
| `defaultPageSize` | `number` | 20 | Pagination | The page size it starts from, read once. |
| `pageSizeOptions` | `readonly number[]` | [10, 20, 50, 100] | Pagination | What the page-size control offers. |
| `siblingCount` | `number` | 1 | Pagination | Pages drawn either side of the current one. |
| `boundaryCount` | `number` | 1 | Pagination | Pages drawn at each end of the row. |
| `itemHref` | `(page: number) => string` | — | Pagination | Turns every page and every trigger into an anchor with a real destination. |
| `messages` | `Partial<PaginationMessages>` | — | Pagination | Words laid over the language in force, key by key: the landmark's name (label), every control and both sentences. |
| `live` | `'polite' \| 'off'` | polite | Pagination | Whether the range announces a page change. |
| `disabled` | `boolean` | false | Pagination | Takes every control away without taking the row out of the page. |
| `loading` | `boolean` | false | Pagination | A page change in flight: every move is refused, the row keeps its size, and the root says aria-busy. |
| `render` | `(props) => ReactNode` | — | every part | Substitutes the rendered element. Every data attribute is handed to it, so a router link keeps them. |
| `ref` | `Ref<HTMLElement>` | — | every part | Reaches the element, and focus() with it. |
| `onClick` | `MouseEventHandler` | — | every trigger | Composed rather than replaced. Call preventDefault to keep the page where it is. |
| `usePagination()` | `() => PaginationContextValue` | — | inside a Pagination | goToPage, next, previous, setPageSize, and the arithmetic they came from: page, pages, range, items. |
| `PaginationDefaultsProvider` | `siblingCount \| boundaryCount \| defaultPageSize \| pageSizeOptions \| live` | — | Application | Sets those five once for everything below it; a prop on the paginator still wins. |

## Events

| Name | Payload | When |
| --- | --- | --- |
| `onPageChange` | `(page: number, request: ChangeRequest<number>)` | Before the page moves. The request carries the page it replaces, the reason — pointer, keyboard or programmatic — and the originating event, and cancelling it commits nothing. programmatic arrives unasked twice: when the collection shrinks under a reader who was past its new end, and after a page-size change that moved the window they are looking through. |
| `onPageSizeChange` | `(pageSize: number, request: ChangeRequest<number>)` | Before the page size moves, with the reason select. It is followed by a programmatic onPageChange whenever keeping the first item of the current page visible means landing on a different page. |

## Rules

- The current page carries aria-current="page", which is the value the ARIA specification names for a link within a set of pagination links — and it is the attribute that paints the fill, so what a reader hears and what the eye sees are one fact rather than two.
- The range is a polite live region, and it is the only one: one region announcing one sentence is the whole of the announcement, so a page change is not read out twice.
- In link mode a trigger at a bound renders an anchor with no destination and aria-disabled, rather than a disabled anchor — there is no such thing, and one that kept its href would still navigate on a middle click.
- The page size is a native select wrapped by its own label, which gives the control its accessible name from the platform and needs no generated id; its popup follows the color scheme the theme already emits.
- Below 22rem of its own inline size the numbered row gives way to the summary. Both are always in the DOM and exactly one is displayed, so nothing is announced twice — and the range is only hidden where a summary exists to replace it.
- Focus stays on the control that was pressed. When pressing it makes it unavailable — Next on the second-to-last page — focus moves to the nearest control that survives, because focus that falls to the body after a press discards the reader’s position.
- The figures are tabular and every cell is at least as wide as it is tall, so page 9 and page 8 942 are the same target and the row does not move under the pointer.

## Tokens

`--slotted-border-strong`, `--slotted-control-border-color`, `--slotted-control-border-width`, `--slotted-control-font-size-md`, `--slotted-control-height-md`, `--slotted-control-icon-size-md`, `--slotted-control-padding-inline-sm`, `--slotted-control-radius`, `--slotted-control-shadow`, `--slotted-control-surface`, `--slotted-control-transition-duration`, `--slotted-control-transition-easing`, `--slotted-disabled-background`, `--slotted-disabled-border`, `--slotted-disabled-foreground`, `--slotted-focus-ring-color`, `--slotted-focus-ring-offset`, `--slotted-focus-ring-width`, `--slotted-font-family-sans`, `--slotted-font-weight-medium`, `--slotted-pagination-color`, `--slotted-pagination-color-disabled`, `--slotted-pagination-color-muted`, `--slotted-pagination-current-color`, `--slotted-pagination-current-surface`, `--slotted-pagination-ellipsis-lift`, `--slotted-pagination-ellipsis-tracking`, `--slotted-pagination-font-family`, `--slotted-pagination-font-size`, `--slotted-pagination-gap`, `--slotted-pagination-glyph-size`, `--slotted-pagination-item-gap`, `--slotted-pagination-item-padding`, `--slotted-pagination-item-weight`, `--slotted-pagination-page-size-gap`, `--slotted-pagination-page-size-inset`, `--slotted-pagination-page-size-surface`, `--slotted-pagination-radius`, `--slotted-pagination-row-gap`, `--slotted-pagination-surface-active`, `--slotted-pagination-surface-hover`, `--slotted-pagination-target`, `--slotted-pagination-text-gap`, `--slotted-space-1`, `--slotted-space-2`, `--slotted-space-3`, `--slotted-space-4`, `--slotted-space-6`, `--slotted-text`, `--slotted-text-muted`, `--slotted-tone-accent-on-solid`, `--slotted-tone-accent-solid`, `--slotted-tone-accent-subtle-active`, `--slotted-tone-accent-subtle-hover`

## Examples

### Playground

Every input on one paginator, driven by the controls below the canvas. Change count and watch the row keep its length while the numbers inside it move.

Excerpt — not a complete module

```tsx
<Pagination count={482} page={page} onPageChange={setPage}>
  <PaginationPrevious />
  <PaginationItems />
  <PaginationNext />
</Pagination>;
```

### The row of page numbers

siblingCount widens the run around the current page and boundaryCount the runs at each end. The row holds one length at every page, so nothing beside it shifts as the reader walks.

Excerpt — not a complete module

```tsx
<Pagination boundaryCount={2} count={482} defaultPage={12} siblingCount={2}>
  <PaginationItems />
</Pagination>;
```

### A total the server does not know

Leave count out and there are no page numbers to draw, so none are drawn. Two triggers and a sentence are the whole paginator, and no total is invented.

Example

```tsx
import { useState } from 'react';

import {
  Pagination,
  PaginationNext,
  PaginationPrevious,
  PaginationStatus,
} from '@slotted/react/pagination';

export default function PaginationCursor() {
  const [page, setPage] = useState(1);

  return (
    <Pagination aria-label="Shipments" page={page} onPageChange={setPage}>
      <PaginationPrevious />
      <PaginationStatus>Shipments, page {page}</PaginationStatus>
      <PaginationNext />
    </Pagination>
  );
}
```

### Which items this page holds

The sentence the numbers do not say, in a polite live region so a page change is announced once. Replace the wording through messages, or the whole sentence with children.

Example

```tsx
import {
  Pagination,
  PaginationNext,
  PaginationPrevious,
  PaginationStatus,
} from '@slotted/react/pagination';
import { Stack } from '@slotted/react/stack';
import { Text } from '@slotted/react/typography';

export default function PaginationRange() {
  return (
    <Stack gap={4}>
      <Text size="sm" tone="muted">
        The range is announced after each page change
      </Text>
      <Pagination aria-label="Invoices, announced" count={482} defaultPage={2}>
        <PaginationPrevious />
        <PaginationStatus />
        <PaginationNext />
      </Pagination>
      <Text size="sm" tone="muted">
        The range is displayed and never announced
      </Text>
      <Pagination aria-label="Invoices, silent" count={482} defaultPage={2} live="off">
        <PaginationPrevious />
        <PaginationStatus />
        <PaginationNext />
      </Pagination>
    </Stack>
  );
}
```

### How many rows a page holds

A native select wrapped by its own label. Changing it keeps the first item of the current page visible, so the reader is looking at the same rows through a different window.

Excerpt — not a complete module

```tsx
<Pagination count={482} pageSizeOptions={[25, 50, 100]}>
  <PaginationPageSize label="Rows per page" />
</Pagination>;
```

### Pages with real destinations

itemHref turns every page and every trigger into an anchor, so a middle click opens page four in a tab and a crawler can follow the row. Without it they are buttons.

Example

```tsx
import {
  Pagination,
  PaginationItems,
  PaginationNext,
  PaginationPrevious,
} from '@slotted/react/pagination';

export default function PaginationLinks() {
  return (
    <Pagination aria-label="Invoices" count={482} itemHref={(page) => `#invoices-page-${page}`}>
      <PaginationPrevious />
      <PaginationItems />
      <PaginationNext />
    </Pagination>
  );
}
```

### Narrow enough that the row will not fit

Below 22rem of its own inline size the numbered row gives way to the summary and the triggers stay. It is a container query, so the same paginator on a wide page never compacts.

Example

```tsx
import { Card, CardBody, CardHeader } from '@slotted/react/card';
import { Grid } from '@slotted/react/grid';
import {
  Pagination,
  PaginationItems,
  PaginationNext,
  PaginationPrevious,
} from '@slotted/react/pagination';
import { Heading } from '@slotted/react/typography';

export default function PaginationCompact() {
  return (
    <Grid columns={3} gap={4} minItemWidth="xs">
      <Card>
        <CardHeader>
          <Heading level={2} size="md">
            Receiving
          </Heading>
        </CardHeader>
        <CardBody>
          <Pagination aria-label="Receiving queue" count={140} defaultPage={3}>
            <PaginationPrevious />
            <PaginationItems />
            <PaginationNext />
          </Pagination>
        </CardBody>
      </Card>

      <Card>
        <CardHeader>
          <Heading level={2} size="md">
            Picking
          </Heading>
        </CardHeader>
        <CardBody>
          <Pagination aria-label="Picking queue" count={482} defaultPage={12}>
            <PaginationPrevious />
            <PaginationItems />
            <PaginationNext />
          </Pagination>
        </CardBody>
      </Card>

      <Card>
        <CardHeader>
          <Heading level={2} size="md">
            Packing
          </Heading>
        </CardHeader>
        <CardBody>
          <Pagination aria-label="Packing queue" count={96} defaultPage={2}>
            <PaginationPrevious />
            <PaginationItems />
            <PaginationNext />
          </Pagination>
        </CardBody>
      </Card>
    </Grid>
  );
}
```

### States

A trigger at a bound is unavailable, a page change in flight refuses every move and keeps the row width, and a disabled paginator mutes the current chip without losing its shape.

Example

```tsx
import {
  Pagination,
  PaginationItems,
  PaginationNext,
  PaginationPrevious,
} from '@slotted/react/pagination';
import { Stack } from '@slotted/react/stack';
import { Text } from '@slotted/react/typography';

export default function PaginationStates() {
  return (
    <Stack gap={4}>
      <Text size="sm" tone="muted">
        At the last page
      </Text>
      <Pagination aria-label="Invoices, last page" count={482} defaultPage={25}>
        <PaginationPrevious />
        <PaginationItems />
        <PaginationNext />
      </Pagination>
      <Text size="sm" tone="muted">
        Loading the next page
      </Text>
      <Pagination aria-label="Invoices, loading" count={482} defaultPage={3} loading>
        <PaginationPrevious />
        <PaginationItems />
        <PaginationNext />
      </Pagination>
      <Text size="sm" tone="muted">
        Disabled
      </Text>
      <Pagination aria-label="Invoices, disabled" count={482} defaultPage={3} disabled>
        <PaginationPrevious />
        <PaginationItems />
        <PaginationNext />
      </Pagination>
    </Stack>
  );
}
```

### Ten thousand pages

The figures are tabular and every cell is at least as wide as it is tall, so page 9 and page 8 942 are the same target and the row does not move as the digits grow.

Excerpt — not a complete module

```tsx
<Pagination count={200000} defaultPage={8942} pageSize={20}>
  <PaginationItems />
</Pagination>;
```

### Composition

The same parts in two arrangements — a numbered row, and the bar a table carries — plus the provider that sets the wording once and the hook that hands the application the arithmetic.

Excerpt — not a complete module

```tsx
<Pagination count={482}>
  <PaginationPageSize />
  <PaginationStatus />
  <PaginationPrevious />
  <PaginationNext />
</Pagination>;

<PaginationDefaultsProvider siblingCount={2}>
  <App />
</PaginationDefaultsProvider>;
```

### Keyboard and focus

Every control is a tab stop in reading order — no roving tab index, because a list of links inside a landmark is a list of tab stops. Enter and Space activate whichever element itemHref chose.

Excerpt — not a complete module

```tsx
// Focus stays on the control that was pressed. When pressing it makes it
// unavailable, it moves to the nearest control that survived.
<PaginationNext />;
```

### controlled.tsx

Example

```tsx
import { useState } from 'react';

import { Button } from '@slotted/react/button';
import { Inline } from '@slotted/react/inline';
import {
  Pagination,
  PaginationItems,
  PaginationNext,
  PaginationPrevious,
  type PaginationPageRequest,
} from '@slotted/react/pagination';
import { Stack } from '@slotted/react/stack';
import { Text } from '@slotted/react/typography';

export default function PaginationControlled() {
  const [count, setCount] = useState(482);
  const [page, setPage] = useState(25);
  const [reason, setReason] = useState('none yet');

  const handlePageChange = (next: number, request: PaginationPageRequest) => {
    setPage(next);
    setReason(request.reason);
  };

  return (
    <Stack gap={4}>
      <Pagination aria-label="Invoices" count={count} page={page} onPageChange={handlePageChange}>
        <PaginationPrevious />
        <PaginationItems />
        <PaginationNext />
      </Pagination>
      <Text size="sm" tone="muted">
        {count} invoices, page {page}. Last change: {reason}.
      </Text>
      <Inline>
        <Button onClick={() => setCount(96)}>Show open invoices</Button>
        <Button onClick={() => setCount(482)}>Show all invoices</Button>
      </Inline>
    </Stack>
  );
}
```

### defaults.tsx

Example

```tsx
import {
  Pagination,
  PaginationDefaultsProvider,
  PaginationItems,
  PaginationPageSize,
  PaginationStatus,
} from '@slotted/react/pagination';
import { Stack } from '@slotted/react/stack';
import { Text } from '@slotted/react/typography';

export default function PaginationApplicationDefaults() {
  return (
    <PaginationDefaultsProvider
      defaultPageSize={50}
      pageSizeOptions={[25, 50, 100]}
      siblingCount={2}
    >
      <Stack gap={4}>
        <Text size="sm" tone="muted">
          Inherits two siblings and 50 rows
        </Text>
        <Pagination aria-label="Orders, inherited" count={1200} defaultPage={10}>
          <PaginationPageSize />
          <PaginationStatus />
          <PaginationItems />
        </Pagination>
        <Text size="sm" tone="muted">
          States no siblings and keeps the rest
        </Text>
        <Pagination aria-label="Orders, own row" count={1200} defaultPage={10} siblingCount={0}>
          <PaginationPageSize />
          <PaginationStatus />
          <PaginationItems />
        </Pagination>
      </Stack>
    </PaginationDefaultsProvider>
  );
}
```

### messages.tsx

Example

```tsx
import {
  Pagination,
  PaginationItems,
  PaginationNext,
  PaginationPrevious,
  PaginationStatus,
} from '@slotted/react/pagination';

const messages = {
  label: 'Shipments',
  next: 'Later shipments',
  page: 'Shipments page {page}',
  previous: 'Earlier shipments',
  range: '{start} to {end} of {count} shipments',
};

export default function PaginationMessages() {
  return (
    <Pagination count={482} defaultPage={12} messages={messages}>
      <PaginationPrevious />
      <PaginationItems />
      <PaginationNext />
      <PaginationStatus />
    </Pagination>
  );
}
```

### row.tsx

Example

```tsx
import {
  Pagination,
  PaginationFirst,
  PaginationItems,
  PaginationLast,
  PaginationNext,
  PaginationPrevious,
} from '@slotted/react/pagination';
import { Stack } from '@slotted/react/stack';
import { Text } from '@slotted/react/typography';

export default function PaginationRow() {
  return (
    <Stack gap={4}>
      <Text size="sm" tone="muted">
        One page on each side of the current page and at each end
      </Text>
      <Pagination aria-label="Invoices, default row" count={482} defaultPage={12}>
        <PaginationFirst />
        <PaginationPrevious />
        <PaginationItems />
        <PaginationNext />
        <PaginationLast />
      </Pagination>
      <Text size="sm" tone="muted">
        Two pages on each side of the current page and at each end
      </Text>
      <Pagination
        aria-label="Invoices, wide row"
        boundaryCount={2}
        count={482}
        defaultPage={12}
        siblingCount={2}
      >
        <PaginationFirst />
        <PaginationPrevious />
        <PaginationItems />
        <PaginationNext />
        <PaginationLast />
      </Pagination>
    </Stack>
  );
}
```

### rows.tsx

Example

```tsx
import {
  Pagination,
  PaginationNext,
  PaginationPageSize,
  PaginationPrevious,
  PaginationStatus,
} from '@slotted/react/pagination';

export default function PaginationRows() {
  return (
    <Pagination
      aria-label="Orders"
      count={482}
      defaultPage={5}
      defaultPageSize={25}
      pageSizeOptions={[25, 50, 100]}
    >
      <PaginationPageSize label="Orders per page" />
      <PaginationStatus />
      <PaginationPrevious />
      <PaginationNext />
    </Pagination>
  );
}
```

### wiring.tsx

Example

```tsx
import { Button } from '@slotted/react/button';
import {
  Pagination,
  PaginationItems,
  PaginationNext,
  PaginationPrevious,
  usePagination,
} from '@slotted/react/pagination';

function BackToStart() {
  const { goToPage } = usePagination();

  return <Button onClick={() => goToPage(1)}>Back to page 1</Button>;
}

export default function PaginationWiring() {
  return (
    <Pagination aria-label="Invoices" count={482} defaultPage={12}>
      <PaginationPrevious />
      <PaginationItems />
      <PaginationNext />
      <BackToStart />
    </Pagination>
  );
}
```
