Skip to content
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 @@ -2,7 +2,7 @@
import { E2EElement, E2EPage, newE2EPage } from "@arcgis/lumina-compiler/puppeteerTesting";
import { beforeEach, describe, expect, it } from "vitest";
import { html } from "../../../support/formatting";
import { accessible, focusable, hidden, renders, t9n, themed } from "../../tests/commonTests";
import { accessible, focusable, hidden, renders, t9n, themed, defaults } from "../../tests/commonTests";
import { findAll } from "../../tests/utils/puppeteer";
import { CSS } from "./resources";

Expand Down Expand Up @@ -35,6 +35,19 @@ describe("calcite-pagination", () => {
t9n("calcite-pagination");
});

describe("defaults", () => {
defaults("calcite-pagination", [
{
propertyName: "totalItems",
defaultValue: 1,
},
{
propertyName: "startItem",
defaultValue: 1,
},
]);
});

describe("page links", () => {
it("should render only one page when totalItems is less than pageSize", async () => {
const page = await newE2EPage();
Expand Down Expand Up @@ -170,6 +183,15 @@ describe("calcite-pagination", () => {
expect(toggleSpy).toHaveReceivedEventTimes(2);
});
});
describe("start-item", () => {
it("checks page defaults to 1 when start-item is negative", async () => {
const page = await newE2EPage();
await page.setContent(`<calcite-pagination start-item="-2" page-size="3"></calcite-pagination>`);
const links = await findAll(page, `calcite-pagination >>> .${CSS.page}`);
expect(links.length).toBe(1);
expect(await links[0].getProperty("value")).toBe("1");
});
});
describe("showing one item at a time", () => {
let page: E2EPage;
let pagination: E2EElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class Pagination extends LitElement {
@property({ reflect: true }) startItem = 1;

/** Specifies the total number of items. */
@property({ reflect: true }) totalItems = 0;
@property({ reflect: true }) totalItems = 1;
Copy link
Copy Markdown
Member

@jcfranco jcfranco Jul 22, 2025

Choose a reason for hiding this comment

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

I don’t think this is correct since items aren’t the same as pages. Instead of changing the default, we should update the logic that handles total items.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we revisit this in a follow-up PR? Once fixed, this PR will need to be amended and the fix PR will need to use no changelog label since it will be fixed within the R3 development cycle.


//#endregion

Expand Down Expand Up @@ -232,8 +232,14 @@ export class Pagination extends LitElement {
private handleLastStartItemChange(): void {
const { totalItems, pageSize, totalPages } = this;

const isStartNegative = totalItems - pageSize < 0;

this.lastStartItem =
(totalItems % pageSize === 0 ? totalItems - pageSize : Math.floor(totalPages) * pageSize) + 1;
(totalItems % pageSize === 0
? isStartNegative
? 0
: totalItems - pageSize
: Math.floor(totalPages) * pageSize) + 1;
}

private handleIsXXSmall(): void {
Expand Down
Loading