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

TablePaginator only shows ellipses when needed #2303

Merged
merged 7 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
5 changes: 5 additions & 0 deletions .changeset/fluffy-pillows-flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@itwin/itwinui-react': patch
---

`TablePaginator` shows ellipses only whenever needed.
9 changes: 7 additions & 2 deletions packages/itwinui-react/src/core/Table/TablePaginator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ export const TablePaginator = (props: TablePaginatorProps) => {
endPage = totalPagesCount;
}

// Show ellipsis only if there is a gap between the extremities and the middle pages
const showStartEllipsis = startPage > 1;
const showEndEllipsis = endPage < totalPagesCount - 1;

const hasNoRows = totalPagesCount === 0;
const showPagesList = totalPagesCount > 1 || isLoading;
const showPageSizeList =
Expand Down Expand Up @@ -326,18 +330,19 @@ export const TablePaginator = (props: TablePaginatorProps) => {
if (visibleCount === 1) {
return pageButton(focusedIndex);
}

return (
<>
{startPage !== 0 && (
<>
{pageButton(0, 0)}
{ellipsis}
{showStartEllipsis && ellipsis}
r100-stack marked this conversation as resolved.
Show resolved Hide resolved
</>
)}
{pageList.slice(startPage, endPage)}
{endPage !== totalPagesCount && !isLoading && (
<>
{ellipsis}
{showEndEllipsis && ellipsis}
r100-stack marked this conversation as resolved.
Show resolved Hide resolved
{pageButton(totalPagesCount - 1, 0)}
</>
)}
Expand Down
80 changes: 78 additions & 2 deletions testing/e2e/app/routes/Table/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ test.describe('Table Paginator', () => {
);

// Go to the 6th page
await page.locator('button').last().click({ clickCount: 5 });
await page.locator('button').last().click();

await expect(page.locator(`[role="cell"]`).first()).toHaveText('Name 250');
await expect(page.locator(`[role="cell"]`).last()).toHaveText(
Expand All @@ -468,7 +468,7 @@ test.describe('Table Paginator', () => {
await setContainerSize(page, '800px');

// Go to the 6th page
await page.locator('button').last().click({ clickCount: 5 });
await page.locator('button').last().click();

const paginatorButtons = page.locator('#paginator button', {
hasText: /[0-9]+/,
Expand Down Expand Up @@ -519,6 +519,82 @@ test.describe('Table Paginator', () => {
});
});

test(`should show ellipses only when a gap of one or more pages`, async ({
page,
}) => {
await page.goto(`/Table?exampleType=withTablePaginator`);

await expectOverflowState({
page,
expectedItemLength: 11,
expectedOverflowingEllipsisVisibleCount: 0,
});

await setContainerSize(page, '800px');

const paginatorButtons = page.locator('#paginator button', {
hasText: /[0-9]+/,
});
const ellipses = page.locator('#paginator span', {
hasText: /^…$/,
});

await expect(paginatorButtons).toHaveText(['1', '2', '3', '4', '5', '11']);
await expect(ellipses).toHaveCount(1);

await paginatorButtons.locator('*', { hasText: '4' }).click();
await expect(paginatorButtons).toHaveText([
'1',
'2',
'3',
'4',
'5',
'6',
'11',
]);
await expect(ellipses).toHaveCount(1);

await paginatorButtons.locator('*', { hasText: '5' }).click();
await expect(paginatorButtons).toHaveText([
'1',
'3',
'4',
'5',
'6',
'7',
'11',
]);
await expect(ellipses).toHaveCount(2);

await paginatorButtons.locator('*', { hasText: '11' }).click();
await expect(paginatorButtons).toHaveText(['1', '7', '8', '9', '10', '11']);
await expect(ellipses).toHaveCount(1);

await paginatorButtons.locator('*', { hasText: '8' }).click();
await expect(paginatorButtons).toHaveText([
'1',
'6',
'7',
'8',
'9',
'10',
'11',
]);
await expect(ellipses).toHaveCount(1);

await paginatorButtons.locator('*', { hasText: '7' }).click();
await expect(paginatorButtons).toHaveText([
'1',
'5',
'6',
'7',
'8',
'9',
'11',
]);
await expect(ellipses).toHaveCount(2);
});

test(`should at minimum always show one page`, async ({ page }) => {
await page.goto(`/Table?exampleType=withTablePaginator`);

Expand Down
Loading