Skip to content

Commit

Permalink
fix(date-picker): no longer disable min/max value month in select menu (
Browse files Browse the repository at this point in the history
#11350)

**Related Issue:** #11321 

## Summary

No longer disable min,max month's in select menu of date-picker.
  • Loading branch information
anveshmekala authored Jan 23, 2025
1 parent 62f2ef2 commit 18767bb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
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

0 comments on commit 18767bb

Please sign in to comment.