Holo Pagination
<holo-pagination> renders a nav landmark labelled “Pagination” with Previous/Next controls and
a truncated list of page number buttons (collapsed with an ellipsis for large page counts). The
current page is marked with aria-current="page", and the Previous/Next controls are disabled at
the bounds.
When to use
Section titled “When to use”Use it for:
- Moving between pages of a long, ordered set of results where the user knows the page count.
- Search results, tables and article lists split over several pages.
Don’t use it for:
- Showing the user’s position in a site hierarchy. Use Breadcrumb.
- Moving through the steps of a form. Show step state in your own wizard UI.
- Infinite lists loaded on scroll. Provide a “Load more” Button.
Live Previews
Section titled “Live Previews”Default
Section titled “Default”<holo-pagination page="1" total-pages="5"></holo-pagination>Many pages (ellipsis)
Section titled “Many pages (ellipsis)”<holo-pagination page="10" total-pages="20" sibling-count="1"></holo-pagination>Set href-template to render every control as a real link. {page} is replaced with each page number.
<holo-pagination page="2" total-pages="5" href-template="?page={page}"></holo-pagination>Button mode and link mode
Section titled “Button mode and link mode”- Button mode (default): controls are
<button>s. Use it for client-side paging.holoPageChangeis emitted andpreventDefault()has no effect. - Link mode (
href-templateset): controls are<a href>. Use it when each page is its own URL, so users can open pages in a new tab and copy the address. The current page keeps itshref, Previous/Next carryrel="prev"andrel="next", and at the bounds they render as disabled links with nohref.
In link mode a plain click emits holoPageChange and then follows the link. Ctrl, Cmd, Shift or Alt clicks and middle-clicks are left to the browser and emit nothing. Clicking the current page does nothing. The template is passed through unchanged, so it must be author-controlled and never built from untrusted input. URL-encoding is up to you. Page 1 cannot be given a different canonical URL (for example /blog instead of /blog/page/1); use a server redirect or rel="canonical".
Client-side routing
Section titled “Client-side routing”Call preventDefault() on holoPageChange to cancel the link navigation and route yourself. The links sit in shadow DOM, so global link interceptors that look for event.target.closest('a') will not see them.
pagination.addEventListener('holoPageChange', event => { event.preventDefault(); router.push(`/results?page=${event.detail}`);});The component has already set page to event.detail when holoPageChange fires, even if you cancel it. If your router rejects or aborts the navigation, set page back to the page you actually show.
pagination.addEventListener('holoPageChange', async event => { event.preventDefault(); const previous = pagination.page; try { await router.push(`/results?page=${event.detail}`); } catch { pagination.page = previous; }});Without JavaScript
Section titled “Without JavaScript”The links only exist once the component has loaded. For crawlers and users without JavaScript, put plain links inside the element. The component has no <slot>, so after upgrade they are not rendered.
<holo-pagination page="2" total-pages="3" href-template="?page={page}"> <a href="?page=1">1</a> <a href="?page=2">2</a> <a href="?page=3">3</a></holo-pagination>Accessibility
Section titled “Accessibility”The component renders a <nav> named by label (default “Pagination”) containing a <ul>. In button mode every control is a native <button type="button">; in link mode every control is a native <a href>. Page controls are named from pageLabel (default Page {page}, where {page} is replaced with the number) and the current one has aria-current="page". The previous and next buttons are named by previousLabel and nextLabel (default “Previous page” and “Next page”). At the first or last page the bound control is disabled. In button mode it is natively disabled (and sets aria-disabled="true"). In link mode it renders as <a role="link" aria-disabled="true"> with no href, so it is not focusable. Link-mode controls intentionally look the same as button-mode controls. Ellipses are aria-hidden.
| Key | Action |
|---|---|
Tab |
Moves between the previous, page and next controls |
Enter, Space |
Goes to the focused page. In link mode only Enter works; Space scrolls. |
- There is no roving tabindex. Each control is a tab stop, except disabled bounds in link mode, which have no
hrefand are skipped. - The focus ring is shown with
:focus-visible. - The component emits
holoPageChangebut does not announce the new page. That is your job. It only keeps focus from being lost: if the focused control is removed or disabled (for example Next on the last page), focus moves to the current-page control. On narrow containers the controls wrap onto more rows rather than scrolling sideways.
You provide:
- A change that is perceivable after navigation: update the heading or a live region, or move focus to the start of the new content.
- A distinct
labelif there are several pagination controls on one page, and translatedlabel,previous-label,next-labelandpage-labelfor other languages.
API Reference
Section titled “API Reference”Importing
import '@philbob/hololink-ui/holo-pagination';Properties
| Property | Attribute | Type | Default | Description |
|---|---|---|---|---|
hrefTemplate | href-template | string | undefined | — | Turns the controls into links. {page} is replaced with each page number, for example
?page={page}. The template is passed through unchanged, so it must come from the author, not
from untrusted input. Leave unset for button mode. |
label | label | string | 'Pagination' | The accessible name of the navigation landmark. Give each pagination on a page a distinct label. |
nextLabel | next-label | string | 'Next page' | The accessible name of the next-page button. |
page | page | number | 1 | The current page (1-indexed). Updated when the user navigates. |
pageLabel | page-label | string | 'Page {page}' | The accessible name of each page button. {page} is replaced with the page number. |
previousLabel | previous-label | string | 'Previous page' | The accessible name of the previous-page button. |
siblingCount | sibling-count | number | 1 | How many page numbers to show on either side of the current page. |
totalPages | total-pages | number | 1 | The total number of pages. |
Events
| Event | Detail | Description |
|---|---|---|
holoPageChange | number | Emitted when the user navigates to a different page. detail is the new page number. In link
mode it fires only for a plain click, and calling preventDefault() on it cancels the link
navigation so you can route client-side. In button mode preventDefault() has no effect. |
CSS custom properties
| Property | Description |
|---|---|
--holo-pagination-current-bg | Background color of the current page button. |
--holo-pagination-current-text-color | Text color of the current page button. |
--holo-pagination-gap | Space between pagination buttons. |
--holo-pagination-text-color | Text color of page buttons. |