Pagination Reference

This document provides a comprehensive guide to implementing and customizing pagination components within the MSDN design system.

Overview

Pagination is a crucial UI pattern for breaking down large sets of data into manageable pages. It improves user experience by:

Component Structure

The standard pagination component consists of:

Basic Implementation

Here's a typical HTML structure for a pagination component:

<nav aria-label="Page navigation">
  <ul class="pagination">
    <li class="disabled">
      <span aria-hidden="true">‹</span>
      <span class="sr-only">Previous</span>
    </li>
    <li><a href="#">1</a></li>
    <li><a href="#">2</a></li>
    <li class="active"><a href="#">3</a></li>
    <li><a href="#">4</a></li>
    <li><a href="#">5</a></li>
    <li class="ellipsis"><span>...</span></li>
    <li><a href="#">10</a></li>
    <li>
      <a href="#" aria-label="Next">
        <span aria-hidden="true">›</span>
        <span class="sr-only">Next</span>
      </a>
    </li>
  </ul>
</nav>

CSS Styling

The provided CSS styles the pagination component for clarity and usability. Key classes include:

Example Usage

Here's a visual representation of the pagination component:

Accessibility Considerations

Ensure your pagination implementation is accessible:

Customization

You can customize the pagination component by modifying the CSS variables or directly adjusting the styles. Consider:

Tip: When dealing with a very large number of pages, consider implementing a "jump to page" input field for more efficient navigation.

JavaScript Integration

While the styling is pure CSS, you'll typically use JavaScript to handle the dynamic behavior of pagination:

Example JavaScript Snippet (Conceptual)

This is a conceptual example showing how you might handle click events and state updates:

document.addEventListener('DOMContentLoaded', () => {
    const paginationContainer = document.querySelector('.pagination');

    if (paginationContainer) {
        paginationContainer.addEventListener('click', (event) => {
            const target = event.target;
            if (target.tagName === 'A' && !target.closest('li').classList.contains('disabled')) {
                event.preventDefault(); // Prevent default link behavior

                const pageNumber = target.textContent;
                console.log('Navigating to page:', pageNumber);

                // Here you would typically:
                // 1. Remove the 'active' class from the currently active page link.
                // 2. Add the 'active' class to the clicked link.
                // 3. Fetch the data for the 'pageNumber'.
                // 4. Update the content area with the fetched data.
                // 5. Update Previous/Next button states if necessary.

                // Example of updating active state (simplified):
                const currentActive = paginationContainer.querySelector('li.active a');
                if (currentActive) {
                    currentActive.parentElement.classList.remove('active');
                }
                target.parentElement.classList.add('active');
            }
        });
    }
});