Pagination

From Legal-and-General/canopy · View interactive version

Pagination is an AI agent skill from the GitHub repository Legal-and-General/canopy. Best practices for the Canopy Pagination component. Trigger when paginating lists, controlling paged datasets, or adding page navigation controls in an Angular project using Canopy.

How to use this skill

Skill file

Canopy Pagination — Best Practices

This skill provides usage guidance and input reference for the Canopy lg-pagination component from @legal-and-general/canopy.

Apply this skill whenever you use LgPaginationComponent or lg-pagination.


Import

import { LgPaginationComponent, PageData } from '@legal-and-general/canopy';

Basic Usage

Template:

<lg-pagination
  [totalItems]="allItems.length"
  [itemsPerPage]="itemsPerPage"
  [currentPage]="currentPage"
  (pageChanged)="onPageChanged($event)"
/>

Component:

import { PageData } from '@legal-and-general/canopy';

export class MyListComponent implements OnInit {
  allItems: Item[] = [];
  pagedItems: Item[] = [];
  itemsPerPage = 10;
  currentPage = 1;

  ngOnInit(): void {
    this.allItems = this.dataService.getData();
    this.pagedItems = this.getPagedData(0, this.itemsPerPage - 1);
  }

  onPageChanged(pageData: PageData): void {
    this.currentPage = pageData.pageNumber;
    this.pagedItems = this.getPagedData(pageData.startIndex, pageData.endIndex);
  }

  private getPagedData(startIndex: number, endIndex: number): Item[] {
    return this.allItems.slice(startIndex, endIndex + 1);
  }
}

Use Array.prototype.slice, not splice. slice(startIndex, endIndex + 1) returns items up to and including endIndex.

If you previously used pageData.page, update handlers to use pageData.pageNumber.


Inputs

| Input | Type | Default | Required | Description |

|-------|------|---------|----------|-------------|

| totalItems | number | 0 | No | Total number of items in the paged collection. |

| itemsPerPage | number | 10 | No | Maximum number of items shown per page. Values lower than 1 are clamped to 1. |

| currentPage | number | 1 | No | Current page number. Values are clamped to the valid page range. |

| id | string | auto-generated | No | HTML id attribute, auto generated if not provided. |

Outputs

| Output | Type | Description |

|--------|------|-------------|

| pageChanged | EventEmitter<PageData> | Emitted when the page changes. Use to update displayed data. |

PageData interface

interface PageData {
  pageNumber: number; // Requested page number (1-based)
  startIndex: number; // Zero-based start index
  endIndex: number;   // Inclusive end index
}

Dos and Don'ts

Do

  1. Do retain the current-page label, state and keyboard focus indicator so users can identify the page they are viewing.
  2. Do use the component's pageChanged output to update displayed results, rather than adding navigation handlers to its internal buttons.

Don't

  1. Don't trigger navigation or reload results when the current page is activated; it represents the page already being viewed.
  2. Don't override the current-page label with Go to page N, remove its aria-current or aria-disabled state, or remove it from the keyboard tab order.

Accessibility


Design Constraints

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.