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 with 0 elements #2316

Merged
merged 3 commits into from
Oct 24, 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 @@ -125,4 +125,24 @@ describe('pagination', () => {
})
);
});
it('should show no start element when total elements is zero', async () => {
const specPage = await newSpecPage({
components: [Pagination],
html: `<scale-pagination
hide-borders="true"
hide-border="true"
page-size="11"
start-element="0"
total-elements="0"
styles="style">
</scale-pagination>`,
});
const paginationInfoElement =
specPage.root.shadowRoot.querySelector('.pagination__info');
const buttonPrev = specPage.root.shadowRoot.querySelector(
'.pagination__prev-prompt'
);
expect(paginationInfoElement.textContent).toEqual('0-0 / 0');
expect(buttonPrev.hasAttribute('disabled')).toBe(true);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ export class Pagination {
/* 10. Render */
render() {
const total = this.totalElements;
const start = this.startElement + 1;
const start = total === 0 ? 0 : this.startElement + 1;
const end = Math.min(this.startElement + this.pageSize, total);
const isAtStart = start === 1;
const isAtStart = start === 1 || total === 0;
const isAtEnd = end === total;
return (
<Host>
Expand Down
Loading