Overview
In many enterprise applications, displaying large datasets efficiently is crucial. Without proper handling, a long list of items can be overwhelming and impact performance. Pagination is a common and effective technique to break down large data into smaller, manageable chunks, improving both user experience and application responsiveness.
This problem asks you to build a reusable client-side paginated data table component. This is a fundamental skill for any frontend engineer, ensuring users can navigate through extensive information without performance bottlenecks or excessive scrolling.
What you need to do / Task
Your task is to implement a React component that displays a list of user profiles in a table, complete with client-side pagination controls. The component should be able to paginate through a given array of data, displaying a fixed number of items per page.
Specifically, you must:
- Render a Data Table: Display the provided
mockUserData in an HTML table with appropriate headers (ID, Name, Email, Role).
- Implement Pagination Controls: Below the table, render a set of pagination controls including:
- 'Previous' button.
- Page number buttons (e.g., 1, 2, 3...). The current page should be visually distinct.
- 'Next' button.
- Manage Page State: When a 'Previous', 'Next', or page number button is clicked, the table content should update to show the items corresponding to the selected page.
- Handle Boundary Conditions: The 'Previous' button should be disabled when on the first page, and the 'Next' button should be disabled when on the last page.
- Accessibility: Ensure the pagination controls are accessible (e.g., using semantic HTML, ARIA attributes for navigation).
UI/UX expectations
- The data should be presented in a clear, readable table format.
- Pagination controls should be placed prominently below the table.
- The current page number should be clearly highlighted or styled differently from inactive page numbers.
- Disabled 'Previous'/'Next' buttons should be visually distinct (e.g., greyed out, unclickable).
- The entire component should be reasonably styled for clarity, but extensive visual design is not required.
Acceptance criteria
- The table correctly displays the headers and data from
mockUserData.
- Only
PAGINATION_PAGE_SIZE items are displayed on the table at any given time.
- Clicking 'Next' advances to the subsequent page, displaying new data.
- Clicking 'Previous' reverts to the prior page, displaying new data.
- Clicking a specific page number button navigates directly to that page.
- The 'Previous' button is disabled when the current page is 1.
- The 'Next' button is disabled when the current page is the last available page.
- The active page number is visually indicated.
- The pagination controls are navigable and understandable for users with assistive technologies (e.g., keyboard navigation, screen reader compatibility).