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): use semantic internal elements #9479

Merged
merged 6 commits into from
May 31, 2024
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 @@ -41,6 +41,17 @@ describe("calcite-pagination", () => {
});
});

describe("semantic elements are used", () => {
it("should render a native list internally", async () => {
const page = await newE2EPage();
await page.setContent(`<calcite-pagination total-items="10" page-size="1"></calcite-pagination>`);
const list = await page.find(`calcite-pagination >>> .${CSS.list}`);
expect(list).not.toBeNull();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also assert on the element types? Maybe we can the following test util:

function assertElementTag(element: E2EElement, tag: keyof HTMLElementTagNameMap): void {
  return expect(element.tagName.toLowerCase()).toBe(tag);
}

const listItems = await page.findAll(`calcite-pagination >>> .${CSS.listItem}`);
expect(listItems.length).toBe(12);
});
});

describe("ellipsis rendering", () => {
it("should not render either ellipsis when total pages is less than or equal to 5", async () => {
const page = await newE2EPage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
writing-mode: horizontal-tb;
}

.list {
@apply flex list-none m-0 p-0;
}

.list-item {
@apply flex m-0 p-0;
}

:host([scale="s"]) {
& .chevron,
& .page,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
Element,
Event,
EventEmitter,
Fragment,
h,
Method,
Prop,
Expand Down Expand Up @@ -447,17 +446,19 @@ export class Pagination
const selected = start === this.startItem;

return (
<button
aria-current={selected ? "page" : "false"}
class={{
[CSS.page]: true,
[CSS.selected]: selected,
}}
onClick={this.handlePageClick}
value={start}
>
{displayedPage}
</button>
<li class={CSS.listItem}>
<button
aria-current={selected ? "page" : "false"}
class={{
[CSS.page]: true,
[CSS.selected]: selected,
}}
onClick={this.handlePageClick}
value={start}
>
{displayedPage}
</button>
</li>
);
}

Expand Down Expand Up @@ -550,13 +551,13 @@ export class Pagination

render(): VNode {
return (
<Fragment>
{this.renderFirstChevron()}
{this.renderPreviousChevron()}
<ul class={CSS.list}>
<li class={CSS.listItem}>{this.renderFirstChevron()}</li>
driskull marked this conversation as resolved.
Show resolved Hide resolved
<li class={CSS.listItem}>{this.renderPreviousChevron()}</li>
{this.renderItems()}
{this.renderNextChevron()}
{this.renderLastChevron()}
</Fragment>
<li class={CSS.listItem}>{this.renderNextChevron()}</li>
<li class={CSS.listItem}>{this.renderLastChevron()}</li>
</ul>
);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export const CSS = {
list: "list",
listItem: "list-item",
page: "page",
selected: "selected",
chevron: "chevron",
Expand Down
137 changes: 81 additions & 56 deletions packages/calcite-components/src/components/table/table.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { html } from "../../../support/formatting";
import { accessible, renders, hidden, defaults, reflects } from "../../tests/commonTests";
import { createSelectedItemsAsserter, getFocusedElementProp } from "../../tests/utils";
import { CSS } from "../table-header/resources";
import { CSS as PAGINATION_CSS } from "../pagination/resources";
import { CSS as CELL_CSS } from "../table-cell/resources";
import { SLOTS } from "../table/resources";

Expand Down Expand Up @@ -1106,13 +1107,16 @@ describe("selection modes", () => {
expect(await element.getProperty("selectedItems")).toHaveLength(1);
await selectedItemAsserter([row1.id]);

await page.$eval("calcite-table", () => {
const table = document.querySelector("calcite-table");
const pagination = table.shadowRoot.querySelector("calcite-pagination");
const button = pagination.shadowRoot.querySelector<HTMLButtonElement>("button.page:nth-of-type(2)");
await page.$eval(
"calcite-table",
(table, PAGINATION_CSS) => {
const pagination = table.shadowRoot.querySelector("calcite-pagination");
const button = pagination.shadowRoot.querySelectorAll<HTMLButtonElement>(`.${PAGINATION_CSS.page}`)[1];
jcfranco marked this conversation as resolved.
Show resolved Hide resolved

button?.click();
});
button?.click();
},
PAGINATION_CSS,
);

await page.waitForChanges();
expect(tableSelectSpy).toHaveReceivedEventTimes(0);
Expand Down Expand Up @@ -1155,35 +1159,44 @@ describe("pagination event", () => {

expect(tablePaginateSpy).toHaveReceivedEventTimes(0);

await page.$eval("calcite-table", () => {
const table = document.querySelector("calcite-table");
const pagination = table.shadowRoot.querySelector("calcite-pagination");
const button = pagination.shadowRoot.querySelector<HTMLButtonElement>("button.page:nth-of-type(2)");
await page.$eval(
"calcite-table",
(table, PAGINATION_CSS) => {
const pagination = table.shadowRoot.querySelector("calcite-pagination");
const button = pagination.shadowRoot.querySelectorAll<HTMLButtonElement>(`.${PAGINATION_CSS.page}`)[1];

button?.click();
});
button?.click();
},
PAGINATION_CSS,
);

await page.waitForChanges();
expect(tablePaginateSpy).toHaveReceivedEventTimes(1);

await page.$eval("calcite-table", () => {
const table = document.querySelector("calcite-table");
const pagination = table.shadowRoot.querySelector("calcite-pagination");
const button = pagination.shadowRoot.querySelector<HTMLButtonElement>("button.page:nth-of-type(3)");
await page.$eval(
"calcite-table",
(table, PAGINATION_CSS) => {
const pagination = table.shadowRoot.querySelector("calcite-pagination");
const button = pagination.shadowRoot.querySelectorAll<HTMLButtonElement>(`.${PAGINATION_CSS.page}`)[1];

button?.click();
});
button?.click();
},
PAGINATION_CSS,
);

await page.waitForChanges();
expect(tablePaginateSpy).toHaveReceivedEventTimes(2);

await page.$eval("calcite-table", () => {
const table = document.querySelector("calcite-table");
const pagination = table.shadowRoot.querySelector("calcite-pagination");
const button = pagination.shadowRoot.querySelector<HTMLButtonElement>("button.page:nth-of-type(4)");
await page.$eval(
"calcite-table",
(table, PAGINATION_CSS) => {
const pagination = table.shadowRoot.querySelector("calcite-pagination");
const button = pagination.shadowRoot.querySelectorAll<HTMLButtonElement>(`.${PAGINATION_CSS.page}`)[1];

button?.click();
});
button?.click();
},
PAGINATION_CSS,
);

await page.waitForChanges();
expect(tablePaginateSpy).toHaveReceivedEventTimes(3);
Expand Down Expand Up @@ -1403,15 +1416,18 @@ describe("keyboard navigation", () => {
await page.waitForChanges();
expect(await getFocusedElementProp(page, "id")).toBe("head-1a");

await page.$eval("calcite-table", () => {
const table = document.querySelector("calcite-table");
const headerCell = document.getElementById("head-1a");
await page.$eval(
"calcite-table",
(table, PAGINATION_CSS) => {
const headerCell = document.getElementById("head-1a");

const pagination = table.shadowRoot.querySelector("calcite-pagination");
const button = pagination.shadowRoot.querySelector<HTMLButtonElement>("button.page:nth-of-type(3)");
button?.click();
(headerCell as HTMLCalciteTableHeaderElement).setFocus();
});
const pagination = table.shadowRoot.querySelector("calcite-pagination");
const button = pagination.shadowRoot.querySelectorAll<HTMLButtonElement>(`.${PAGINATION_CSS.page}`)[1];
button?.click();
(headerCell as HTMLCalciteTableHeaderElement).setFocus();
},
PAGINATION_CSS,
);

await page.waitForChanges();
expect(await getFocusedElementProp(page, "id")).toBe("head-1a");
Expand Down Expand Up @@ -1451,16 +1467,19 @@ describe("keyboard navigation", () => {
await page.waitForChanges();
expect(await getFocusedElementProp(page, "id")).toBe("cell-4b");

await page.$eval("calcite-table", () => {
const table = document.querySelector("calcite-table");
const headerCell = document.getElementById("head-1a");
await page.$eval(
"calcite-table",
(table, PAGINATION_CSS) => {
const headerCell = document.getElementById("head-1a");

const pagination = table.shadowRoot.querySelector("calcite-pagination");
const button = pagination.shadowRoot.querySelector<HTMLButtonElement>("button.page:nth-of-type(4)");
const pagination = table.shadowRoot.querySelector("calcite-pagination");
const button = pagination.shadowRoot.querySelectorAll<HTMLButtonElement>(`.${PAGINATION_CSS.page}`)[2];

button?.click();
(headerCell as HTMLCalciteTableHeaderElement).setFocus();
});
button?.click();
(headerCell as HTMLCalciteTableHeaderElement).setFocus();
},
PAGINATION_CSS,
);

await page.waitForChanges();
expect(await getFocusedElementProp(page, "id")).toBe("head-1a");
Expand Down Expand Up @@ -1827,16 +1846,19 @@ describe("keyboard navigation", () => {
await page.waitForChanges();
expect(await getFocusedElementProp(page, "id")).toBe("foot-2b");

await page.$eval("calcite-table", () => {
const table = document.querySelector("calcite-table");
const headerCell = document.getElementById("head-1a");
await page.$eval(
"calcite-table",
(table, PAGINATION_CSS) => {
const headerCell = document.getElementById("head-1a");

const pagination = table.shadowRoot.querySelector("calcite-pagination");
const button = pagination.shadowRoot.querySelector<HTMLButtonElement>("button.page:nth-of-type(3)");
const pagination = table.shadowRoot.querySelector("calcite-pagination");
const button = pagination.shadowRoot.querySelectorAll<HTMLButtonElement>(`.${PAGINATION_CSS.page}`)[1];

button?.click();
(headerCell as HTMLCalciteTableHeaderElement).setFocus();
});
button?.click();
(headerCell as HTMLCalciteTableHeaderElement).setFocus();
},
PAGINATION_CSS,
);

await page.waitForChanges();
expect(await getFocusedElementProp(page, "id")).toBe("head-1a");
Expand Down Expand Up @@ -2436,15 +2458,18 @@ describe("keyboard navigation", () => {
),
).toEqual({ "0": CSS.numberCell });

await page.$eval("calcite-table", () => {
const table = document.querySelector("calcite-table");
const headerCell = document.getElementById("head-1a");
await page.$eval(
"calcite-table",
(table, PAGINATION_CSS) => {
const headerCell = document.getElementById("head-1a");

const pagination = table.shadowRoot.querySelector("calcite-pagination");
const button = pagination.shadowRoot.querySelector<HTMLButtonElement>("button.page:nth-of-type(3)");
button?.click();
(headerCell as HTMLCalciteTableHeaderElement).setFocus();
});
const pagination = table.shadowRoot.querySelector("calcite-pagination");
const button = pagination.shadowRoot.querySelectorAll<HTMLButtonElement>(`.${PAGINATION_CSS.page}`)[1];
button?.click();
(headerCell as HTMLCalciteTableHeaderElement).setFocus();
},
PAGINATION_CSS,
);

await page.waitForChanges();

Expand Down
Loading