pagination

import { lucide, pagination } from '@markless/ui';export default function PaginationBasic() @{	<pagination.root class="pages" aria-label="Results pages" count={5} page={3}>		<pagination.backtrigger class="page-box" aria-label="Previous page">			<lucide.chevronleft aria-hidden="true" />		</pagination.backtrigger>		<pagination.item value={1}>			<pagination.itemtrigger class="page-box">1</pagination.itemtrigger>		</pagination.item>		<pagination.item value={2}>			<pagination.itemtrigger class="page-box">2</pagination.itemtrigger>		</pagination.item>		<pagination.item value={3}>			<pagination.itemtrigger class="page-box">3</pagination.itemtrigger>		</pagination.item>		<pagination.item value={4}>			<pagination.itemtrigger class="page-box">4</pagination.itemtrigger>		</pagination.item>		<pagination.item value={5}>			<pagination.itemtrigger class="page-box">5</pagination.itemtrigger>		</pagination.item>		<pagination.forwardtrigger class="page-box" aria-label="Next page">			<lucide.chevronright aria-hidden="true" />		</pagination.forwardtrigger>	</pagination.root>;}

pagination is a row of page numbers with back and next controls. Use it when a list or a table splits its rows across pages.

import { pagination } from '@markless/ui';

export default function Pages() @{
	<pagination.root count={5} page={1} aria-label="Results pages">
		<pagination.backtrigger>Previous</pagination.backtrigger>
		<pagination.item value={1}>
			<pagination.itemtrigger>1</pagination.itemtrigger>
		</pagination.item>
		<pagination.item value={2}>
			<pagination.itemtrigger>2</pagination.itemtrigger>
		</pagination.item>
		<pagination.forwardtrigger>Next</pagination.forwardtrigger>
	</pagination.root>
}

You write the page number once, on pagination.item. The control inside it reads that number back. So a button cannot say page 2 and go to page 3.

count is the number of pages, not rows. How many rows fit on a page is your data's job.

Anatomy

pagination anatomy
Anatomy perspectiveFlat
Layers
Previous123Next
pagination.root

The <nav> landmark that holds the page controls.

  • pagination.root is a <nav> landmark. It holds the current page and the page count.
  • pagination.item is the box for one page. Its value is that page's number.
  • pagination.itemtrigger is a <button> that goes to its item's page.
  • pagination.itemlink is the same control as an <a>, for pages that have real URLs.
  • pagination.backtrigger and pagination.forwardtrigger are <button>s that step one page.

The current page's item and control write ui-active. Its control also writes aria-current="page". The root writes ui-disabled when you set disabled.

The back control is disabled on page 1, and the forward control is disabled on the last page. They read "Previous page" and "Next page" to a screen reader unless you write your own aria-label.

Keyboard

Every control is a native button or link, so the browser's own keys work.

Key What it does
Tab Moves through the controls in page order. It skips a disabled step control.
Enter or Space Goes to the focused page, or steps one page.

Long runs of pages

Twenty buttons do not fit in a row. pagination.entries(page, count, siblingCount) returns the pages to draw, with gaps where pages are left out. You loop over that list and draw each entry yourself:

const entries = computed(() => pagination.entries(nav.page, 20, 1));

@for (const entry of entries; key entry.key) {
	<li>
		@if (entry.type === 'page') {
			<pagination.item value={entry.value}>
				<pagination.itemtrigger>{entry.value}</pagination.itemtrigger>
			</pagination.item>
		} @else {
			<span aria-hidden="true">…</span>
		}
	</li>
}

The third argument is the number of pages on each side of the current one. An entry is either { type: 'page', value, key } or { type: 'ellipsis', key }. Loop on entry.key, not on the index. A page keeps its key as the range slides. A gap never stands for one page. The family shows that page instead.

Name the landmark

pagination.root writes no aria-label. A page with a site nav and a pagination has two <nav> landmarks. A screen reader lists them by name, so give this one a name of its own.

Props on pagination.root

Prop Type What it does
count number How many pages there are. Required.
page number The page that shows. The first page is 1, and it is the default.
siblingCount number How many pages to show on each side of the current one. The default is 1.
disabled boolean Stops all page changes. Every control says it is unavailable.
onChange (page) => void Gets the new page number when a person moves to another page.

The root passes anything a <nav> accepts to its element. pagination.item takes value, which is required. A click on the page that already shows does not call onChange.