Pagination
Moves through pages of results: the pages, previous and next, in the look of the app's style. It counts the pages from the number of items and the page size, and works out which to show.
Usage
import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScPagination, ScPaginationItem, ScPaginationLink, ScPaginationList, ScPaginationNext, ScPaginationPrevious,} from '@semantic-components/ui';import { SiChevronLeftIcon, SiChevronRightIcon,} from '@semantic-icons/lucide-icons';
@Component({ selector: 'app-pagination-usage-demo', imports: [ ScPagination, ScPaginationItem, ScPaginationLink, ScPaginationList, ScPaginationNext, ScPaginationPrevious, SiChevronLeftIcon, SiChevronRightIcon, ], template: ` <nav scPagination aria-label="Results" #pagination="scPagination" [totalItems]="30" [pageSize]="10" [(currentPage)]="page" > <ul scPaginationList> <li scPaginationItem> <button scPaginationPrevious> <svg siChevronLeftIcon data-icon="inline-start"></svg> <span class="sr-only sm:not-sr-only">Previous</span> </button> </li> @for (item of pagination.pages(); track item.value) { <li scPaginationItem> <button scPaginationLink [page]="+item.value"> {{ item.value }} </button> </li> } <li scPaginationItem> <button scPaginationNext> <span class="sr-only sm:not-sr-only">Next</span> <svg siChevronRightIcon data-icon="inline-end"></svg> </button> </li> </ul> </nav> `, host: { class: 'flex w-full justify-center' }, encapsulation: ViewEncapsulation.None,})export class PaginationUsageDemo { private readonly page = signal(1);}Anatomy
A navigation round a list; every part is a directive on your element, the icons and the text are yours. Name the navigation with aria-label and an icon-only button with an sr-only span. The pages come from pages() (the first and the last, the current one with a page either side, ellipses between; as many items wherever the current page is); the current one is marked aria-current="page".
import { ScPagination, ScPaginationList, ScPaginationItem, ScPaginationFirst, ScPaginationPrevious, ScPaginationLink, ScPaginationEllipsis, ScPaginationNext, ScPaginationLast, ScPaginationStatus,} from '@semantic-components/ui';<nav scPagination aria-label="…" #pagination="scPagination" [totalItems]="…" [pageSize]="…"> <ul scPaginationList> <li scPaginationItem><button scPaginationFirst>…</button></li> <li scPaginationItem><button scPaginationPrevious>…</button></li> @for (item of pagination.pages(); track item.value) { <li scPaginationItem> @if (item.type === 'ellipsis') { <span scPaginationEllipsis><svg></svg></span> } @else { <button scPaginationLink [page]="item.value">…</button> } </li> } <li scPaginationItem><button scPaginationNext>…</button></li> <li scPaginationItem><button scPaginationLast>…</button></li> </ul> <p scPaginationStatus>…</p></nav>Notes
Use buttons when the page changes in place, links when each page has its own URL: the href is yours (?page=2, a routerLink) and the link follows it; read the page from the URL into currentPage. A disabled link goes nowhere on a click, but keeps its href: leave it off for a link that should not open in a new tab either. Previous and First turn disabled on the first page, Next and Last on the last: they leave the tab order and say aria-disabled. For rows per page, put a Select beside it and call changePageSize(); to say which page is shown, a Status.
Examples
Simple
import { Component, ViewEncapsulation } from '@angular/core';import { ScPagination, ScPaginationItem, ScPaginationLink, ScPaginationList,} from '@semantic-components/ui';
@Component({ selector: 'app-simple-pagination-demo',Icons Only
import { Component, ViewEncapsulation } from '@angular/core';import { ScField, ScLabel, ScPagination, ScPaginationItem, ScPaginationList, ScPaginationNext, ScPaginationPrevious, ScPaginationStatus,Ellipsis
import { Component, ViewEncapsulation } from '@angular/core';import { ScPagination, ScPaginationEllipsis, ScPaginationItem, ScPaginationLink, ScPaginationList, ScPaginationNext, ScPaginationPrevious,} from '@semantic-components/ui';Siblings
import { Component, ViewEncapsulation } from '@angular/core';import { ScPagination, ScPaginationEllipsis, ScPaginationItem, ScPaginationLink, ScPaginationList, type ScPaginationPage,} from '@semantic-components/ui';import { SiEllipsisIcon } from '@semantic-icons/lucide-icons';First and Last
import { Component, ViewEncapsulation } from '@angular/core';import { ScPagination, ScPaginationEllipsis, ScPaginationFirst, ScPaginationItem, ScPaginationLast, ScPaginationLink, ScPaginationList, ScPaginationNext,Links
import { Component, ViewEncapsulation, computed, inject } from '@angular/core';import { toSignal } from '@angular/core/rxjs-interop';import { ActivatedRoute, RouterLink } from '@angular/router';import { ScPagination, ScPaginationEllipsis, ScPaginationItem, ScPaginationLink, ScPaginationList, ScPaginationNext,Disabled
import { Component, ViewEncapsulation } from '@angular/core';import { ScPagination, ScPaginationItem, ScPaginationLink, ScPaginationList, ScPaginationNext, ScPaginationPrevious,} from '@semantic-components/ui';import {RTL
import { Dir } from '@angular/cdk/bidi';import { Component, LOCALE_ID, ViewEncapsulation } from '@angular/core';import { ScPagination, ScPaginationEllipsis, ScPaginationItem, ScPaginationLink, ScPaginationList, ScPaginationNext, ScPaginationPrevious,API reference
ScPagination — nav[scPagination], div[scPagination]
The navigation; exported as scPagination. It reads currentPage() (kept between 1 and the last page, even as items go), pageSize(), totalPages() (at least 1), previousPage() and nextPage() (null at the ends), range() (the items shown: { start, end }) and pages(). Methods: goToPage(page), changePageSize(size), which goes back to page 1. Output change ({ page, pageSize }): the user changed one, to load that page.
| Input | Type | Default | Description |
|---|---|---|---|
totalItems | number | 0 | How many items there are; the pages are counted from it. |
pageSize | number | 10 | Items per page; [(pageSize)] two-way. |
currentPage | number | 1 | The page; [(currentPage)] two-way. |
siblings | number | 1 | Pages shown on each side of the current one. |
boundaries | number | 1 | Pages always shown at the start and at the end. |
class | string | '' | Classes merged over the style (cn: a later class wins). |
ScPaginationList, ScPaginationItem — ul[scPaginationList], li[scPaginationItem]
The list of buttons, in a row; a place in it.
| Input | Type | Default | Description |
|---|---|---|---|
class | string | '' | Classes merged over the style (cn: a later class wins). |
ScPaginationLink — a[scPaginationLink], button[scPaginationLink]
A page. Outlined and aria-current="page" while it is the current one.
| Input | Type | Default | Description |
|---|---|---|---|
page | number | — | The page it goes to. |
size | ScButtonVariants["size"] | 'icon' | The button size. |
disabled | boolean | false | Not followed; aria-disabled and out of the tab order. |
type | 'button' | 'submit' | 'reset' | 'button' | On a button: its type, so by default it never submits a form round it. Not set on a link. |
class | string | '' | Classes merged over the style (cn: a later class wins). |
ScPaginationPrevious, ScPaginationNext — a[scPaginationPrevious], button[scPaginationPrevious], a[scPaginationNext], button[scPaginationNext]
One page back or on. Their chevrons flip right to left.
| Input | Type | Default | Description |
|---|---|---|---|
variant | ScButtonVariants["variant"] | 'ghost' | The button look. |
size | ScButtonVariants["size"] | 'default' | The button size; 'icon' for an icon-only button. |
disabled | boolean | false | Disabled whatever the page (it is disabled by itself at the end it leads to). |
type | 'button' | 'submit' | 'reset' | 'button' | On a button: its type, so by default it never submits a form round it. Not set on a link. |
class | string | '' | Classes merged over the style (cn: a later class wins). |
ScPaginationFirst, ScPaginationLast — a[scPaginationFirst], button[scPaginationFirst], a[scPaginationLast], button[scPaginationLast]
The first or the last page.
| Input | Type | Default | Description |
|---|---|---|---|
variant | ScButtonVariants["variant"] | 'ghost' | The button look. |
size | ScButtonVariants["size"] | 'default' | The button size; 'icon' for an icon-only button. |
disabled | boolean | false | Disabled whatever the page (it is disabled by itself at the end it leads to). |
type | 'button' | 'submit' | 'reset' | 'button' | On a button: its type, so by default it never submits a form round it. Not set on a link. |
class | string | '' | Classes merged over the style (cn: a later class wins). |
ScPaginationEllipsis — span[scPaginationEllipsis]
Pages left out; hidden from screen readers.
| Input | Type | Default | Description |
|---|---|---|---|
class | string | '' | Classes merged over the style (cn: a later class wins). |
ScPaginationStatus — [scPaginationStatus]
Says which page is shown, and announces it when it changes (a polite live region). Its text is yours: Page {{ pagination.currentPage() }} of {{ pagination.totalPages() }}, visible or sr-only.
| Input | Type | Default | Description |
|---|---|---|---|
class | string | '' | Classes merged over the style (cn: a later class wins). |