Pagination
A pagination component lets users navigate through content split across multiple pages.
Expand code
<Pagination pages={10}/>Pages
The pages prop defines how many pages will be available to navigate.
Expand code
<Pagination pages={3}/>
<Pagination pages={15}/>Active page
You can set the currently selected page with the activePage prop.
If the prop is omitted, it will fall back to 1.
Expand code
<Pagination pages={12} activePage={6}/>The currently selected page must not be greater than the number of total pages and must be at least 1.
Change detection
You can handle navigation changes with the prop onChange. The function will be called whenever one of the controls or
any visible page is clicked.
Expand code
const [page, setPage] = React.useState(1);
<div>current page: {page}</div>
<Pagination pages={10} activePage={page} onChange={setPage}/>Controls
Visibility
The props disableFirstButton, disablepreviousButton, disableNextButton and disableLastButton determine whether
a control should be hidden.
By default, all controls are visible.
Expand code
<Pagination pages={10} disableFirstButton disableLastButton/>
<Pagination pages={10} disableNextButton disablePrevButton/>
<Pagination pages={10} disableFirstButton disableLastButton disableNextButton disablePrevButton/>Custom icons
You can use different icons for the controls, by using the firstButton, previousButton, nextButton or lastButton prop.
Expand code
// const first = <svg>...</svg>
// const last = <svg>...</svg>
<Pagination pages={10} firstButton={first} lastButton={last} disableNextButton disablePrevButton/>Boundary
The boundary prop sets the amount of visible entries at the bounds of the pagination.
Expand code
<Pagination pages={15} activePage={7} boundary={3}/>The boundary must not be greater than the number of total pages and must be at least 1.
Siblings
Customize the amount of visible pages around the currently selected page with the siblings prop.
Expand code
<Pagination pages={15} activePage={7} siblings={3}/>Accessibility
Every control and page has the ARIA attribute aria-label. You can customize it by using the ariaLabels prop.
By default, the aria-label attributes are set to Go to (first/previous/next/last/) page and Go to page x.
Expand code
const aria: AriaLabels = {
first: 'First page',
last: 'Last page',
next: 'Next page',
prev: 'Previous page',
page: 'Page'
};
<Pagination pages={10} ariaLabels={aria}/>Props
| Name | Type | Default | Description |
|---|---|---|---|
| activePage | number | 1 | currently selected page |
| ariaLabels | object | - | Sets the aria-label attributes for the controls and pages |
| boundary | number | 1 | Visible pages at the pagination bounds |
| disableFirstButton | boolean | false | Enable or disable the first page control |
| disableLastButton | boolean | false | Enable or disable the last page control |
| disableNextButton | boolean | false | Enable or disable the next page control |
| disablePrevButton | boolean | false | Enable or disable the previous page control |
| firstButton | node | - | Use a custom icon |
| lastButton | node | - | Use a custom icon |
| nextButton | node | - | Use a custom icon |
| onChange | function | - | On change, get the current page |
| prevButton | node | - | Use a custom icon |
| pages | number | - | Number of available pages |
| siblings | number | 1 | Number of pages surrounding the selected page |