forty-cdk
llms.txt

Primitives

Pagination

A navigation landmark that derives a visible page list with ellipsis gaps from page, count, siblingCount and boundaryCount, with previous / next buttons and aria-current='page' on the active page.

forty-cdk/pagination WAI-ARIA APG

Walk the pages with the pointer or the keyboard. The current page is aria-current="page", and the ends reflect data-disabled on the arrow that has nowhere to go.

Anatomy

<nav forPagination [(page)]="page" [count]="20" ariaLabel="Pagination" #pg="forPagination">
  <button forPaginationPrevious ariaLabel="Previous page">
    <svg viewBox="0 0 24 24" width="16" height="16" aria-hidden="true">
      <path
        d="m15.75 19.5-7.5-7.5 7.5-7.5"
        fill="none"
        stroke="currentColor"
        stroke-width="1.75"
        stroke-linecap="round"
        stroke-linejoin="round"
      />
    </svg>
  </button>

  <!-- one item per entry in pg.items() — a page button per 'page' entry -->
  <button forPaginationItem [page]="item.value!">{{ item.value }}</button>
  <!-- an aria-hidden gap per 'ellipsis' entry -->
  <span aria-hidden="true">…</span>

  <button forPaginationNext ariaLabel="Next page">
    <svg viewBox="0 0 24 24" width="16" height="16" aria-hidden="true">
      <path
        d="m8.25 4.5 7.5 7.5-7.5 7.5"
        fill="none"
        stroke="currentColor"
        stroke-width="1.75"
        stroke-linecap="round"
        stroke-linejoin="round"
      />
    </svg>
  </button>
</nav>

Examples

Driving a data list

Pagination is headless state: derive count from your data, then slice the visible rows from page(). Changing the page re-slices the list; the page model is the single source of truth shared by the rows and the controls.

  • INV-1001Acme$120.00
  • INV-1002Globex$157.00
  • INV-1003Initech$194.00
  • INV-1004Umbrella$231.00
  • INV-1005Soylent$268.00

1–5 of 23 invoices

API

ForPagination

PropertyTypeDescription
page
model
Two-way bindable. The currently active page number, 1-based.
Default: 1
count
input.required
Total number of pages. Required.
Default: —
siblingCount
input
Number of page buttons to show on each side of the current page.
Default: 1, or the scope's provideForPaginationDefaults
boundaryCount
input
Number of page buttons to always show at the start and end of the list.
Default: 1, or the scope's provideForPaginationDefaults
disabled
input
When true, disables every page item and the previous / next buttons.
Default: false
dir
input
Writing direction, reflected to the host dir attribute when set or declared. It changes the visual layout only: previous / next keep their meaning. null inherits the nearest [dir] / <html dir>, else 'ltr'.
Default: null
ariaLabel
input
Accessible label for the navigation landmark.
Default: null (and empty string) emits no attribute
Data attributeValues
data-disabledpresent (no value) when disabled is set

ForPaginationItem

PropertyTypeDescription
page
input.required
The 1-based page number this button represents. Required.
Default: —
disabled
input
Disables this page button on its own; the root's disabled disables it too.
Default: false

ForPaginationPrevious

PropertyTypeDescription
ariaLabel
input
Accessible label for the previous-page button.
Default: null (and empty string) emits no attribute

ForPaginationNext

PropertyTypeDescription
ariaLabel
input
Accessible label for the next-page button.
Default: null (and empty string) emits no attribute

Scoped defaults

provideForPaginationDefaults configures pagination defaults for an injector subtree, either at the application root or in any component's providers array. Partial overrides inherit unspecified keys from the parent scope (or the library fallbacks at the root).

KeyLibrary fallbackMeaning
siblingCount1Pages shown on each side of the current page before the range collapses to an ellipsis, for paginations that don't set siblingCount themselves.
boundaryCount1Pages always shown at each end of the list, for paginations that don't set boundaryCount themselves.

Per-instance inputs always win over the scope defaults.

import { type ApplicationConfig } from '@angular/core';
import { provideForPaginationDefaults } from 'forty-cdk/defaults';

export const appConfig: ApplicationConfig = {
  providers: [provideForPaginationDefaults({ siblingCount: 2 })],
};

Accessibility

Implements the WAI-ARIA navigation landmark pattern.

  • Navigation landmark. [forPagination] applies role="navigation". Set ariaLabel (e.g. "Pagination") so the landmark is distinguishable from other navigation regions on the page.
  • Current page. [forPaginationItem] reflects aria-current="page" on the active page button so screen-reader users know which page they are on.
  • Focus stays on the activated page. Track pg.items() by item.key, never by $index. Activating a page near the edge of the window shifts the list, and a key keeps that button's element, so focus stays on the page the user chose and it becomes aria-current. Tracked by $index, the focused button is handed to a different page.
  • Disabled prev/next. [forPaginationPrevious] and [forPaginationNext] reflect aria-disabled="true" + data-disabled at the boundaries (and when the root is disabled), never the native disabled attribute. Activation is a no-op while disabled, and the button stays focusable, so a keyboard user who presses Next on the second-to-last page keeps focus on it instead of being sent to <body>.

Styling

forty-cdk ships no styles. Style the current page via [aria-current="page"] and disabled pieces via [data-disabled], which previous / next and page items all reflect.

[forPaginationItem][aria-current='page'] {
  font-weight: bold;
}

[forPaginationPrevious][data-disabled],
[forPaginationNext][data-disabled] {
  opacity: 0.4;
}

Wrapping in a design system

Subclass the root and re-provide FOR_PAGINATION_CONTEXT with useExisting pointing at the subclass, since Angular does not inherit a directive's providers; Wrapping non-form roots walks the pattern.