Skip to content

Commit

Permalink
fix(pagination): prevents console error when page-size is set to zero (
Browse files Browse the repository at this point in the history
…#8017)

**Related Issue:** #2093 

## Summary

Prevents console error messages when `page-size` is set to `0` via
attribute or programmatically.
  • Loading branch information
anveshmekala authored Oct 16, 2023
1 parent 881a6f4 commit d09d485
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,25 @@ describe("calcite-pagination", () => {
});
});

describe("pageSize", () => {
it("should set pageSize to one when set to zero via attribute", async () => {
const page = await newE2EPage();
await page.setContent(`<calcite-pagination start-item="1" total-items="5" page-size="0"></calcite-pagination>`);
const pagination = await page.find("calcite-pagination");
expect(await pagination.getProperty("pageSize")).toBe(1);
});

it("should set pageSize to one when set to zero programmatically", async () => {
const page = await newE2EPage();
await page.setContent(`<calcite-pagination start-item="1" total-items="50" page-size="10"></calcite-pagination>`);
const pagination = await page.find("calcite-pagination");
expect(await pagination.getProperty("pageSize")).toBe(10);
pagination.setProperty("pageSize", 0);
await page.waitForChanges();
expect(await pagination.getProperty("pageSize")).toBe(1);
});
});

describe("number locale support", () => {
let page: E2EPage;
let element: E2EElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class Pagination
@Prop() numberingSystem: NumberingSystem;

/** Specifies the number of items per page. */
@Prop({ reflect: true }) pageSize = 20;
@Prop({ mutable: true, reflect: true }) pageSize = 20;

/** Specifies the size of the component. */
@Prop({ reflect: true }) scale: Scale = "m";
Expand All @@ -112,9 +112,12 @@ export class Pagination
/** Specifies the total number of items. */
@Prop({ reflect: true }) totalItems = 0;

@Watch("pageSize")
@Watch("totalItems")
@Watch("pageSize")
handleTotalPages(): void {
if (this.pageSize < 1) {
this.pageSize = 1;
}
this.totalPages = this.totalItems / this.pageSize;
}

Expand Down

0 comments on commit d09d485

Please sign in to comment.