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): Fix showing the placeholder when resetting the value #7156

Merged
merged 3 commits into from
Jun 14, 2023
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);
eriklharper marked this conversation as resolved.
Show resolved Hide 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