Use Pagination...
- For navigation across a range of pages of related content.
- To indicate a user's position within that range.
Don't use Pagination...
- For navigation within a small set of elements, where simple scrolling can suffice.
Pagination allows for navigation across a range of pages of related content, and also indicates a user's position within that range. SWAN provides a standard set of controls, leaving it up to the particular page to implement the pagination logic behind them.
Pagination with buttons
Use PaginationButton
and PaginationStep
to enable navigation across pages.
Implementation
- Pagination is a simple set of controls with no actual pagination logic behind them. The page that uses it will need to:
- attach the URLs and/or handle any clicks to the Previous and Next buttons
- attach a change handler to the input field, taking the user to the specified page when the input's value is changed
- Pagination buttons can use either
<a>
or<button>
tags. The React PaginationButton component will default to<a>
tags. Use<a>
tags if a click takes the user to a new page; use<button>
tags if a click loads new content into the same page. - If the user is on the first or last page, the Previous or Next button should be disabled accordingly:
- In the React API: add the
disabled
prop to thePaginationButton
. - In the Vanilla API: if your Pagination use
<a>
tags, change the Prev/Next button to a<span>
tag and add classswan-pagination-button-disabled
. If your Pagination uses<button>
tags, disable the button as you normally would for a button, by adding the attributedisabled="disabled"
.
- In the React API: add the
Accessibility
- The "buttons" in Pagination default to
<a>
tags, which means they are links and need anhref
attribute. If your Pagination buttons aren't links, and instead perform in-page actions, they should be<button>
tags, such as by usingas="button"
in the React API. - The buttons need additional text to guide the user as to their function.
- In the React API, use the
accessibleText
prop to provide guidance (as shown in the code example above). - In the Vanilla API, use
aria-label
andaria-describedby
attributes (as show in the code example above). Anyaria-label
values will need to be localized, since they will be presented to the user by screen readers and assistive devices.
- In the React API, use the