Provides an easy way to navigate through multiple pages of content. It helps users move between paginated data efficiently while maintaining a clean and structured UI.
About
This component generates a navigation bar with page numbers, previous and next buttons, and optional first and last page controls. It is designed to be flexible, allowing customization of appearance, behavior, and accessibility features to fit different use cases. Whether handling large datasets, blog posts, or product listings, the Pagination Nav ensures smooth and intuitive navigation.
Example
The Pagination component accepts a data prop, which is an array of objects. Each object represents a page link with a url and an optional active property to indicate the current page.
Alignment
The align prop controls the horizontal position of the pagination. The accepted values are: 'start', 'center', and 'end'. The default value is center.
Sizing
You can control the button size of the pagination with the size prop. Available values are: 'xs', 'sm', 'md', 'lg', 'xl', 'auto'. Default value md.
Flat Pagination
Add flat attribute to the Pagination component to make the pagination flat/border-less.
Prev/Next Button
You can use the hidePrevious, hideNext, and hidePreviousNext attributes to control the visibility of navigation buttons in the Pagination component. The hidePrevious hides the previous button, hideNext hides the next button, and hidePreviousNext hides both.
Hide Prev/Next Button
The example below demonstrates how to hide the previous button, next button, or both using attributes. The first example hides the previous button, the second hides the next button, and the third hides both.
Custom Previous/Next Button Content
The previousButton and nextButton props allow you to customize the content of the previous and next buttons in the Pagination component. These props accept both plain text and HTML, giving you flexibility in styling and design.
By default, previousButton is set to "← Prev", and nextButton is set to "Next →". You can modify these values to fit your needs, such as changing the text or adding icons.
Onclick Function
In some cases, you may need custom functionality when clicking the previous or next button. You can achieve this using the onPreviousClick and onNextClick props by passing your custom functions to them.
Hide Page Number Buttons
In some cases, you may only need the previous and next buttons without page numbers. The Pagination component supports this by default - simply leave the data prop empty, and it will display only the previous and next buttons.
<Pagination />Rounded Corner
The rounded prop in the Pagination component allows you to easily control the border radius, ensuring consistent design throughout the application. This prop supports several predefined values, providing flexibility while maintaining a uniform look. Available values are: none, sm, md, lg, xl, and full. Default value md.
Animation Speed
The animateSpeed prop controls the animation (hover animation in this case) speed of Pagination. Options include 'none' for no animation, 'slower' or slow for a gradual effect, normal (default) for standard speed, and fast or faster for quicker animations.
<Pagination {data} animateSpeed="slower" />
<Pagination {data} animateSpeed="slow" />
<Pagination {data} animateSpeed="normal" />
<Pagination {data} animateSpeed="fast" />
<Pagination {data} animateSpeed="faster" />
<Pagination {data} animateSpeed="none" />Accessibility
The Pagination component is designed with accessibility in mind, ensuring easy navigation for all users, including those using screen readers or keyboard navigation.
- Keyboard Navigation: Users can navigate through pagination using the tab key to move focus and Enter or Space to activate a button.
- ARIA Labels: The component includes appropriate
aria-labelattributes for previous, next, and page buttons, improving screen reader support. - Focus Indicators: Clear focus styles ensure visibility when navigating with a keyboard.
- Semantic HTML: Uses proper HTML elements (
button,a,nav, andul/li) to enhance usability and compatibility with assistive technologies.
These features help make the Pagination component more accessible and user-friendly.