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(input-date-picker): no longer emits redundant change event #8341

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 @@ -262,6 +262,31 @@ describe("calcite-input-date-picker", () => {
expect(changeEvent).toHaveReceivedEventTimes(0);
expect(await getDateInputValue(page)).toBe("3/7/");
});

it("should emit change event only once when valueAsDate is parsed as Unix Time Stamp programmatically and user updates the date", async () => {
const page = await newE2EPage();
await page.setContent(html` <calcite-input-date-picker></calcite-input-date-picker>`);

const inputDatePickerEl = await page.find("calcite-input-date-picker");
const changeEvent = await page.spyOnEvent("calciteInputDatePickerChange");

await page.$eval("calcite-input-date-picker", (element: any) => {
element.valueAsDate = new Date(1687528800000);
});

expect(await inputDatePickerEl.getProperty("value")).toEqual("2023-06-23");
expect(await getDateInputValue(page)).toEqual("6/23/2023");
expect(changeEvent).toHaveReceivedEventTimes(0);

await inputDatePickerEl.click();
await page.waitForChanges();
await selectDayInMonth(page, 28);
await page.waitForChanges();

expect(await inputDatePickerEl.getProperty("value")).toEqual("2023-06-28");
expect(await getDateInputValue(page)).toEqual("6/28/2023");
expect(changeEvent).toHaveReceivedEventTimes(1);
});
});

it("should clear active date properly when deleted and committed via keyboard", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,12 @@ export class InputDatePicker
this.warnAboutInvalidValue(this.value);
this.value = "";
}
} else if (this.range && this.valueAsDate) {
this.setRangeValue(this.valueAsDate as Date[]);
} else if (this.valueAsDate) {
if (this.range) {
this.setRangeValue(this.valueAsDate as Date[]);
} else if (!Array.isArray(this.valueAsDate)) {
this.value = dateToISO(this.valueAsDate);
}
}

if (this.min) {
Expand Down