Skip to content

Commit

Permalink
fix: pagination nav adjacent double ellipses (#17779)
Browse files Browse the repository at this point in the history
* fix: pagination nav adjacent double ellipses

* fix: test case
  • Loading branch information
riddhybansal authored Oct 21, 2024
1 parent a8f6da7 commit df8787e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
34 changes: 34 additions & 0 deletions packages/react/src/components/PaginationNav/PaginationNav-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,39 @@ describe('PaginationNav', () => {

expect(screen.getByText('4')).toHaveAttribute('aria-current', 'page');
});

it('should render PaginationNav correctly and navigate through different page ranges using select elements', async () => {
render(<PaginationNav totalItems={10} itemsShown={4} />);

// Initial state: < 1 2 ... 10 >
expect(screen.getByText('1')).toHaveAttribute('aria-current', 'page');
expect(screen.getByText('2')).toBeInTheDocument();
expect(screen.getByText('10')).toBeInTheDocument();

let selectElements = screen.getAllByLabelText('Select Page number');
expect(selectElements).toHaveLength(1);

// Select page 6 from the dropdown
await userEvent.selectOptions(selectElements[0], '6');

// New state: < ... 6 ... 10 >
expect(screen.getByText('6')).toHaveAttribute('aria-current', 'page');

// Check for two select elements in this state
selectElements = screen.getAllByLabelText('Select Page number');
expect(selectElements).toHaveLength(2);

// Select page 1 from the first dropdown
await userEvent.selectOptions(selectElements[0], '1');

// Final state: < 1 2 ... 10 >
expect(screen.getByText('1')).toHaveAttribute('aria-current', 'page');
expect(screen.getByText('2')).toBeInTheDocument();
expect(screen.getByText('10')).toBeInTheDocument();

// Check that we're back to one select element
selectElements = screen.getAllByLabelText('Select Page number');
expect(selectElements).toHaveLength(1);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,8 @@ const PaginationNav = React.forwardRef<HTMLElement, PaginationNavProps>(
function pageWouldBeHidden(page: number) {
const startOffset = itemsDisplayedOnPage <= 4 && page > 1 ? 0 : 1;

const wouldBeHiddenInFront = page >= startOffset && page <= cuts.front;
const wouldBeHiddenInFront =
(page >= startOffset && page <= cuts.front) || page === 0;
const wouldBeHiddenInBack =
page >= totalItems - cuts.back - 1 && page <= totalItems - 2;

Expand Down

0 comments on commit df8787e

Please sign in to comment.