Pagination
Let users move through pages of results with a row of page numbers between previous and next arrows.
Installation
This also adds Icon, whose theme colors draw the arrows.
Usage
[(page)]two-way binds the current page. Pages count from1.- Tapping a number goes to that page. The arrows step one page back or forward, and dim at the first and last page.
- The first and last pages always show. Around the current page,
siblingCountpages show on each side, and...fills the gaps. - With
5 + 2 × siblingCountpages or fewer, every page shows and there are no gaps. - The arrows draw in the theme's foreground, like the numbers. For dark mode, see Icon.
Show the current page's items
Derive the visible slice from the page signal with computed(). It updates whenever the user changes page.
More neighbors
siblingCount sets how many pages show on each side of the current one. Fewer fit a narrow screen better.
Screen readers
Every arrow and number is a button with a label: "Previous page", "Next page", "Page 3", and "Page 4, current page" for the current one. The ... gaps are skipped. Change the labels, for example to translate them, with previousLabel, nextLabel and pageLabel:
React to a change
Listen to pageChange to run code when the user changes page. It fires inside the tap, so it can change signals or navigate, as any tap handler can.
API
UiPagination
The component doesn't clamp page. If you set it yourself, keep it between 1 and totalPages.
Related
- List: infinite scroll instead of pages
- Empty State: what to show when there are no results
