Skip to content

fix(input-date-picker): ensure initial value is in range #9894

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

Merged
merged 1 commit into from
Jul 30, 2024
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
8 changes: 4 additions & 4 deletions packages/calcite-components/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4518,7 +4518,7 @@ export namespace Components {
*/
"detached": boolean;
/**
* When `displayMode` is `float-content`, specifies the maximum height of the component.
* When `displayMode` is `float-content` or `float`, specifies the maximum height of the component.
* @deprecated Use `heightScale` instead.
*/
"detachedHeightScale": Scale;
Expand Down Expand Up @@ -4547,7 +4547,7 @@ export namespace Components {
*/
"position": Extract<"start" | "end", Position>;
/**
* When `true` and `displayMode` is not `float-content`, the component's content area is resizable.
* When `true` and `displayMode` is not `float-content` or `float`, the component's content area is resizable.
*/
"resizable": boolean;
/**
Expand Down Expand Up @@ -12638,7 +12638,7 @@ declare namespace LocalJSX {
*/
"detached"?: boolean;
/**
* When `displayMode` is `float-content`, specifies the maximum height of the component.
* When `displayMode` is `float-content` or `float`, specifies the maximum height of the component.
* @deprecated Use `heightScale` instead.
*/
"detachedHeightScale"?: Scale;
Expand Down Expand Up @@ -12669,7 +12669,7 @@ declare namespace LocalJSX {
*/
"position"?: Extract<"start" | "end", Position>;
/**
* When `true` and `displayMode` is not `float-content`, the component's content area is resizable.
* When `true` and `displayMode` is not `float-content` or `float`, the component's content area is resizable.
*/
"resizable"?: boolean;
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,23 @@ describe("calcite-input-date-picker", () => {
});
});

it("ensures initial value is in range", async () => {
const page = await newE2EPage();
await page.emulateTimezone("America/Los_Angeles");
await page.setContent(
html`<calcite-input-date-picker
value="2017-07-22"
min="2018-01-01"
max="2018-12-31"
></calcite-input-date-picker>`,
);

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

expect(await element.getProperty("value")).toEqual("2018-01-01");
expect(await getDateInputValue(page)).toEqual("1/1/2018");
});

it("updates internally when min attribute is updated after initialization", async () => {
const page = await newE2EPage();
await page.emulateTimezone("America/Los_Angeles");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,11 +469,22 @@ export class InputDatePicker

const { open } = this;
open && this.openHandler();

if (this.min) {
this.minAsDate = dateFromISO(this.min);
}

if (this.max) {
this.maxAsDate = dateFromISO(this.max);
}

if (Array.isArray(this.value)) {
this.valueAsDate = getValueAsDateRange(this.value);
} else if (this.value) {
try {
this.valueAsDate = dateFromISO(this.value);
const date = dateFromISO(this.value);
const dateInRange = dateFromRange(date, this.minAsDate, this.maxAsDate);
this.valueAsDate = dateInRange;
} catch (error) {
this.warnAboutInvalidValue(this.value);
this.value = "";
Expand All @@ -486,14 +497,6 @@ export class InputDatePicker
}
}

if (this.min) {
this.minAsDate = dateFromISO(this.min);
}

if (this.max) {
this.maxAsDate = dateFromISO(this.max);
}

connectLabel(this);
connectForm(this);
connectMessages(this);
Expand Down
Loading