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 1 commit
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("semantics", () => {
driskull marked this conversation as resolved.
Show resolved Hide resolved
it("should render a list internally", async () => {
driskull marked this conversation as resolved.
Show resolved Hide resolved
const page = await newE2EPage();
await page.setContent(`<calcite-pagination total-items="10" page-size="1"></calcite-pagination>`);
const list = await page.find(`calcite-pagination >>> ul`);
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 >>> li`);
expect(listItems.length).toBe(10);
});
});

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;
}

ul {
driskull marked this conversation as resolved.
Show resolved Hide resolved
@apply flex list-none m-0 p-0;
}

li {
@apply flex m-0 p-0;
}

:host([scale="s"]) {
& .chevron,
& .page,
Expand Down
137 changes: 73 additions & 64 deletions packages/calcite-components/src/components/pagination/pagination.tsx
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>
<button
aria-current={selected ? "page" : "false"}
class={{
[CSS.page]: true,
[CSS.selected]: selected,
}}
onClick={this.handlePageClick}
value={start}
>
{displayedPage}
</button>
</li>
);
}

Expand All @@ -467,19 +468,21 @@ export class Pagination
const disabled = pageSize === 1 ? startItem <= pageSize : startItem < pageSize;

return (
<button
aria-label={messages.previous}
class={{
[CSS.chevron]: true,
[CSS.disabled]: disabled,
}}
data-test-chevron="previous"
disabled={disabled}
key="previous"
onClick={this.previousClicked}
>
<calcite-icon flipRtl icon={ICONS.previous} scale={getIconScale(this.scale)} />
</button>
<li>
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 extract the list item rendering to a separate function and reuse?

Copy link
Member Author

Choose a reason for hiding this comment

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

I could create a functional component for a li but that seems a little overkill for this since its just a list item with a class.

<button
aria-label={messages.previous}
class={{
[CSS.chevron]: true,
[CSS.disabled]: disabled,
}}
data-test-chevron="previous"
disabled={disabled}
key="previous"
onClick={this.previousClicked}
>
<calcite-icon flipRtl icon={ICONS.previous} scale={getIconScale(this.scale)} />
</button>
</li>
);
}

Expand All @@ -490,19 +493,21 @@ export class Pagination
pageSize === 1 ? startItem + pageSize > totalItems : startItem + pageSize > totalItems;

return (
<button
aria-label={messages.next}
class={{
[CSS.chevron]: true,
[CSS.disabled]: disabled,
}}
data-test-chevron="next"
disabled={disabled}
key="next-button"
onClick={this.nextClicked}
>
<calcite-icon flipRtl icon={ICONS.next} scale={getIconScale(this.scale)} />
</button>
<li>
<button
aria-label={messages.next}
class={{
[CSS.chevron]: true,
[CSS.disabled]: disabled,
}}
data-test-chevron="next"
disabled={disabled}
key="next-button"
onClick={this.nextClicked}
>
<calcite-icon flipRtl icon={ICONS.next} scale={getIconScale(this.scale)} />
</button>
</li>
);
}

Expand All @@ -512,18 +517,20 @@ export class Pagination
const disabled = startItem === 1;

return isXXSmall ? (
<button
aria-label={messages.first}
class={{
[CSS.chevron]: true,
[CSS.disabled]: disabled,
}}
disabled={disabled}
key="first-button"
onClick={this.firstClicked}
>
<calcite-icon flipRtl icon={ICONS.first} scale={getIconScale(this.scale)} />
</button>
<li>
<button
aria-label={messages.first}
class={{
[CSS.chevron]: true,
[CSS.disabled]: disabled,
}}
disabled={disabled}
key="first-button"
onClick={this.firstClicked}
>
<calcite-icon flipRtl icon={ICONS.first} scale={getIconScale(this.scale)} />
</button>
</li>
) : null;
}

Expand All @@ -533,30 +540,32 @@ export class Pagination
const disabled = startItem === lastStartItem;

return isXXSmall ? (
<button
aria-label={messages.last}
class={{
[CSS.chevron]: true,
[CSS.disabled]: disabled,
}}
disabled={disabled}
key="last-button"
onClick={this.lastClicked}
>
<calcite-icon flipRtl icon={ICONS.last} scale={getIconScale(this.scale)} />
</button>
<li>
<button
aria-label={messages.last}
class={{
[CSS.chevron]: true,
[CSS.disabled]: disabled,
}}
disabled={disabled}
key="last-button"
onClick={this.lastClicked}
>
<calcite-icon flipRtl icon={ICONS.last} scale={getIconScale(this.scale)} />
</button>
</li>
) : null;
}

render(): VNode {
return (
<Fragment>
<ul>
{this.renderFirstChevron()}
{this.renderPreviousChevron()}
{this.renderItems()}
{this.renderNextChevron()}
{this.renderLastChevron()}
</Fragment>
</ul>
);
}
}
Loading