oakoss/ui
Components

Pagination

Links between the pages of a long list.

SourceReact Aria

Installation

npx shadcn@latest add @oakoss/pagination

Usage

import {
  Pagination,
  PaginationContent,
  PaginationItem,
  PaginationLink,
  PaginationNext,
  PaginationPrevious,
} from '#/components/ui/navigation/pagination';

<Pagination>
  <PaginationContent>
    <PaginationItem>
      <PaginationPrevious href="?page=1" />
    </PaginationItem>
    <PaginationItem>
      <PaginationLink href="?page=2" isActive>
        2
      </PaginationLink>
    </PaginationItem>
    <PaginationItem>
      <PaginationNext href="?page=3" />
    </PaginationItem>
  </PaginationContent>
</Pagination>;

The parts are presentational: work out which pages to show in your app. Links take an href, and follow your router when the app sets up React Aria's RouterProvider.

Examples

Disabled ends

isDisabled on PaginationPrevious or PaginationNext turns it off at the first or last page.

Accessibility

React Aria renders each link with an href as an <a>. Without one, or when disabled, it's a span with the link role, and a disabled link leaves the Tab order.

This component adds:

  • Landmark: a nav named "Pagination". Set label to rename it.
  • Page names: a page link whose text is its number is named "Page 2", through pageLabel. A link's own aria-label wins.
  • Current page: isActive sets aria-current="page". It's semibold with a border, so the cue isn't color alone, and in Windows High Contrast it takes the system's selection colors.
  • Previous and Next: rel="prev" and rel="next". On small screens their text is hidden visually but stays their name.
  • Ellipsis: screen readers announce "More pages". Set label on PaginationEllipsis to reword it.
  • Target size: links are 44px targets, spaced so they don't overlap.
KeyAction
TabMoves to the next link
EnterFollows the focused link

React Aria adds no keys.

API

Pagination

A nav element, and accepts all its props except aria-label, which label sets.

Props

Prop

Type

Data attributes

AttributePresent when
data-slotAlways pagination

PaginationContent and PaginationItem

A ul and an li, accepting all their props.

Data attributes

AttributePresent when
data-slotAlways pagination-content or pagination-item

Extends React Aria's Link, styled as a button.

Props

Prop

Type

Also accepts all React Aria Link props.

Data attributes

AttributePresent when
data-slotAlways pagination-link
data-currentisActive is set
data-disabledisDisabled is set
data-hoveredA pointer hovers it
data-pressedIt's being pressed
data-focusedIt has focus
data-focus-visibleIt has keyboard focus

PaginationPrevious and PaginationNext

PaginationLinks with a chevron, and accept its props except children, isActive and pageLabel.

Props

Prop

Type

Data attributes

The same as PaginationLink's, data-slot included, as upstream's are.

PaginationEllipsis

A span, and accepts all its props.

Props

Prop

Type

Data attributes

AttributePresent when
data-slotAlways pagination-ellipsis