No results found

Pagination

Navigate through large sets of data with numbered pages and controls.

Features

  • Page number selection with keyboard navigation (arrows, home, end)
  • Dynamic pagination with customizable sibling count
  • First/Last page quick navigation
  • Ellipsis support for large page sets
  • WAI-ARIA compliant pagination controls
  • Controlled and uncontrolled page selection modes
  • Customizable ellipsis element
  • Disabled state handling
  • Page change event handlers
  • Automatic page range calculation
  • Focus management between page numbers
  • Boundary page number validation

Anatomy

PartDescription
<Pagination.Root>Root pagination container component that provides context and handles page management
<Pagination.Page>Individual page number button component
<Pagination.Next>Next page navigation button component
<Pagination.Previous>Previous page navigation button component
<Pagination.Ellipsis>Renders an ellipsis item in the pagination

Examples

Basic Usage

The most basic pagination setup requires totalPages and pages props to define the range of pages available.

The totalPages prop determines the total number of pages, while the pages array provides the actual page numbers to display. The currentPage prop sets which page is initially active.

Visual Features

Disabled State

Pages can be disabled to prevent interaction when at boundaries or based on conditions.

First Page (Previous disabled)

Last Page (Next disabled)

The isDisabled prop on Pagination.Page disables individual pages, while the disabled prop on Pagination.Root disables the entire pagination component.

Ellipsis Display

Customize how page gaps are displayed using ellipsis.

......
••••••

The ellipsis prop on Pagination.Root allows customization of the gap indicator between page numbers.

First and Last Navigation

Add quick navigation to the start and end of the pagination range.

The isFirst and isLast props on Pagination.Previous and Pagination.Next respectively enable first/last page navigation.

Advanced Usage

Keyboard Navigation

Enable full keyboard control for accessibility.

Keyboard Navigation: Previous page| Next pageHome First page|End Last page

Arrow keys navigate between pages, while Home/End keys jump to first/last pages. The component handles focus management automatically.

Custom Page Length

Control how many pages are displayed at once.

...

The totalPages prop determines the overall number of pages, while siblingCount controls how many adjacent pages are shown.

Sibling Count

Adjust how many pages appear on either side of the current page.

1 Sibling Count

......

2 Sibling Count

......

The siblingCount prop determines how many page numbers are visible before and after the current page.

Component State

Using Component State

The Pagination component offers several ways to control its state through props and events:

  1. Current Page Control As shown in the page example above, you can set the initial page using the currentPage prop on Pagination.Root. For reactive control, use the bind:page prop which accepts a signal.
  2. Total Pages The totalPages prop determines the total number of pages available for navigation, as demonstrated in the length example above.
  3. Disabled State As shown in the disabled example above, the entire pagination can be disabled by setting the disabled prop on Pagination.Root. This will prevent all user interactions with the component.

State Interactions

  1. Page Change Events The component provides an onPageChange$ prop to handle page navigation events:
<Pagination.Root
  totalPages={10}
  onPageChange$={(page: number) => {
    // Handle page change
    console.log(`Navigated to page ${page}`);
  }}
>
  {/* ... */}
</Pagination.Root>
  1. Navigation Controls As demonstrated in the first-last example above, you can control navigation behavior using the isFirst and isLast props on the Previous and Next components respectively.
  2. Sibling Pages The siblingCount prop controls how many page numbers are shown on either side of the current page, as shown in the siblings example above. This helps manage the pagination's visual state when dealing with large numbers of pages.
  3. Custom Ellipsis As shown in the ellipsis example above, you can customize the appearance of truncated pages using the ellipsis prop on Pagination.Root. The pagination state is automatically managed to ensure:

Based on the provided implementation and examples, I'll document the configuration options for the Pagination component.

Core Configuration

Page Management

The Pagination component requires essential configuration for managing page counts and navigation:

The currentPage will automatically be constrained between 1 and totalPages

Sibling Pages

The component supports configurable sibling pages through the siblingCount prop:

Ellipsis Display

The ellipsis configuration determines how page gaps are displayed:

Advanced Configuration

Controlled State

The component supports controlled state management through:

Additional navigation options can be configured:

Disabled State

The pagination supports complete disabling:

When disabled, all interactive elements receive the disabled attribute and appropriate ARIA states

API Reference

Pagination Root

Inherits from: <div />

Props

PropTypeDefaultDescription
totalPagesnumber-
currentPagenumber-
"bind:page"Signal<number | 1>-
onPageChange$QRL<(page: number) => void>-
disabledboolean-
pagesnumber[]-
ellipsisJSXChildren-
siblingCountnumber-

Data Attributes

AttributeDescription
data-disabledIndicates whether the pagination component is disabled

Pagination Page

Data Attributes

AttributeDescription
data-indexSpecifies the index of the pagination page
data-currentIndicates if this is the currently selected page

Pagination Ellipsis

Inherits from: <div />

Pagination Next

Inherits from: <button />

Pagination Previous

Inherits from: <button />

Accessibility

Keyboard Interactions

KeyDescription
ArrowRightWhen focus is on a page number button, moves focus to the next page number
ArrowLeftWhen focus is on a page number button, moves focus to the previous page number
HomeWhen focus is on a page number button, moves focus to the first page number
EndWhen focus is on a page number button, moves focus to the last page number
EnterWhen focus is on a page number button, selects that page number
SpaceWhen focus is on the previous or next button, navigates to the previous or next page respectively