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(date-picker): no longer disable min/max value month in select menu #11350

Merged
merged 4 commits into from
Jan 23, 2025
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 @@ -325,10 +325,13 @@ export class DatePickerMonthHeader extends LitElement {
private isMonthInRange(index: number): boolean {
const newActiveDate = getDateInMonth(this.activeDate, index);

if (!this.min && !this.max) {
if ((!this.min && !this.max) || inRange(newActiveDate, this.min, this.max)) {
return true;
}
return (!!this.max && newActiveDate < this.max) || (!!this.min && newActiveDate > this.min);

return (
hasSameMonthAndYear(newActiveDate, this.max) || hasSameMonthAndYear(newActiveDate, this.min)
);
}

private async handlePenultimateValidMonth(event: MouseEvent | KeyboardEvent): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,28 @@ describe("calcite-date-picker", () => {
await setActiveDate(page, dateBeforeMin);
expect(await getActiveDate(page)).toEqual(new Date(dateBeforeMin).toISOString());
});

it("should not disable min & max month option", async () => {
const page = await newE2EPage();
await page.setContent(html`<calcite-date-picker value="2025-03-20"></calcite-date-picker>`);

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

datePicker.setProperty("min", "2025-02-15");
datePicker.setProperty("max", "2025-04-15");
await page.waitForChanges();

const monthSelect = await page.find(
"calcite-date-picker >>> calcite-date-picker-month >>> calcite-date-picker-month-header >>> calcite-select",
);
const monthOptions = await monthSelect.findAll("calcite-option");

expect(await monthOptions[0].getProperty("disabled")).toBe(true);
expect(await monthOptions[1].getProperty("disabled")).toBe(false);
expect(await monthOptions[2].getProperty("disabled")).toBe(false);
expect(await monthOptions[3].getProperty("disabled")).toBe(false);
expect(await monthOptions[4].getProperty("disabled")).toBe(true);
});
});

describe("translation support", () => {
Expand Down
Loading