Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: pagination nav adjacent double ellipses #17779

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading