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 @@ -805,4 +805,24 @@ describe("calcite-input-date-picker", () => {
expect(await getFocusedElementProp(page, "id")).toBe("next-sibling");
});
});

it("should reset input value", async () => {
const page = await newE2EPage();
const expectedValue = "2022-10-01";
const expectedInputValue = "10/1/2022";

await page.setContent(html` <calcite-input-date-picker value="${expectedValue}"></calcite-input-date-picker>`);

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

expect(await inputDatePickerEl.getProperty("value")).toEqual(expectedValue);
expect(await input.getProperty("value")).toEqual(expectedInputValue);
Comment thread
eriklharper marked this conversation as resolved.

inputDatePickerEl.setProperty("value", "");
await page.waitForChanges();

expect(await inputDatePickerEl.getProperty("value")).toEqual("");
expect(await input.getProperty("value")).toEqual("");
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ export class InputDatePicker
@Watch("value")
valueWatcher(newValue: string | string[]): void {
if (!this.userChangedValue) {
let newValueAsDate;
let newValueAsDate: Date | Date[];

if (Array.isArray(newValue)) {
newValueAsDate = getValueAsDateRange(newValue);
} else if (newValue) {
Expand Down Expand Up @@ -996,8 +997,8 @@ export class InputDatePicker
const localizedEndDate =
endDate && this.formatNumerals(endDate.toLocaleDateString(this.effectiveLocale));

localizedDate && this.setInputValue(localizedDate, "start");
this.range && localizedEndDate && this.setInputValue(localizedEndDate, "end");
this.setInputValue(localizedDate ?? "", "start");
this.setInputValue((this.range && localizedEndDate) ?? "", "end");
}

private setInputValue = (newValue: string, input: "start" | "end" = "start"): void => {
Expand Down