ba-pagination
This component for navigating large sets of content
Airframe
Web Components
React
React Native
Anatomy
Previous button
Navigates to the previous page in the set. Hidden when there is no previous page
Ellipsis
Indicates a truncated range of pages between the first page and the pages shown around the current page
Current page
Highlights the page the user is currently viewing
Ellipsis
Indicates a truncated range of pages between the pages shown around the current page and the last page
Next button
Navigates to the next page in the set. Hidden when there is no next page
Design Documentation
Use when content is split across multiple pages and the user benefits from knowing their position within the full set. For example, search results, data tables, or content listings.Do not use when all items are visible on a single page.
Different variants are shown depending on how many total pages are needed and what page the user is currently on.
Full range
The full range of pages is shown when the total number is 7 pages or less
Start overflow
Used when there are more than 7 pages and the user is near the beginning of the set. The first four pages are shown, followed by an ellipsis, then the last page. The previous arrow is hidden.
Middle overflow
Used when the user is far enough from both ends that truncation is needed on both sides. The first and last pages are always anchored. The current page and one page either side are shown in the centre.
End overflow
The mirror of Overflow start. Used when the user is near the end of the set. The first page is shown, followed by an ellipsis, then the last four pages. The next arrow is hidden.
Compact
This version is used on mobile. All pages are contained in the dropdown.
Live Demo
<ba-pagination
total="20"
current="1"
show-items-per-page
></ba-pagination>
Properties and attributes
| Property | Attribute | Description | Type | Default |
|---|---|---|---|---|
baseUrl |
base-url |
The base url to use for each page link. The page number will be appended to this url as a query parameter, e.g. ?page=2 |
string | undefined |
window.location.href |
current(required) |
current |
The current page number | number |
undefined |
currentItemsPerPage |
current-items-per-page |
The current number of items per page | string | undefined |
undefined |
showItemsPerPage |
show-items-per-page |
Whether to show the items per page dropdown | boolean | undefined |
false |
total(required) |
total |
The total number of pages | number |
undefined |
Permitted ARIA roles
- None
Slots
No slotted content available for this component.
Parent components
ba-pagination can be slotted into:
Events
| Event | Description | Type |
|---|---|---|
baPaginationLinkClick |
Emitted when the internal link is clicked. For use with single-page app (SPA) routing so that link clicks can be handled to avoid a full page load. | CustomEvent<PaginationLinkClickEventDetail> |
baPaginationItemsPerPageChange |
Emitted when the items per page value has changed. | CustomEvent<any> |
Usage
Basic usage
<ba-pagination total="20" current="1"></ba-pagination>
Showing items per page dropdown
<ba-pagination total="20" current="1" show-items-per-page></ba-pagination>
Usage in a single page application
<ba-pagination total="20" current="1" show-items-per-page></ba-pagination>
<script>
pagination.addEventListener("baPaginationLinkClick", (event) => {
event.detail.preventDefault();
// Before custom SPA routing
});
pagination.addEventListener("baPaginationItemsPerPageChange", (event) => {
event.detail.preventDefault();
// Before custom SPA routing
});
</script>
Keyboard navigation
State: Previous element in DOM has focus
The previous page button gets focus, or the first page link if there is no previous page
State: Previous page button has focus
Navigates to the previous page
First visible page link gets focus
State: A page link has focus
Navigates to that page, emits baPaginationLinkClick, and updates the current page indicator
Next visible page link, or the next page button, gets focus
State: Next page button has focus
Navigates to the next page
If show-items-per-page is set, the items per page dropdown gets focus, otherwise the next tabbable element outside of the component gets focus
State: Items per page dropdown has focus
Opens the dropdown
Moves to the next option in the dropdown
Moves to the previous option in the dropdown
Selects the option, closes the dropdown, and emits baPaginationItemsPerPageChange
Next tabbable element outside of the component gets focus
Usage and accessibility checklist
Use this checklist to confirm the component has been configured and used correctly.
UX checklist
- Use ba-pagination when content is split across multiple pages and users benefit from knowing their position within the full set, for example search results, data tables, or content listings
- Do not use ba-pagination when all items are visible on a single page
- The full range of pages is shown when the total number is 7 pages or less
- Start, middle, and end overflow variants are used to truncate page numbers with an ellipsis once there are more than 7 pages, with the first and last page always anchored
- The compact variant, which shows all pages within a dropdown, is used on mobile
Accessibility checklist
- The previous button is hidden when there is no previous page, and the next button is hidden when there is no next page
- The current page is clearly indicated, both visually and to assistive technology
- Pagination links and controls are operable with keyboard using tab to move focus and enter to activate
- When used in a single page application, baPaginationLinkClick is handled so that custom routing remains operable without a full page reload
These checks are handled by the component and do not need to be repeated each time it is used.
- ba-pagination is operable using assistive technology
- Has a visible focus indicator on all sides of each interactive element
- Colour contrast for all states in all BAgel themes
- Animations respect users' reduced motion settings
- High contrast mode adjustments