@spartan-ng/brain 1.4.0-beta.3 → 1.4.0-beta.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -530,8 +530,13 @@ class BrnCalendarMonthSelect {
530
530
  .config()
531
531
  .months()
532
532
  .findIndex((month) => month === selectedMonth);
533
- const targetDate = this._dateAdapter.set(this._calendar.focusedDate(), { month });
534
- this._calendar.setFocusedDate(targetDate);
533
+ const focusedDate = this._calendar.focusedDate();
534
+ // Start from the first of the month so a day that does not exist in the target month
535
+ // (e.g. the 31st) cannot roll over into the following month - clamp it instead.
536
+ const targetDate = this._dateAdapter.set(this._dateAdapter.startOfMonth(focusedDate), { month });
537
+ const lastDay = this._dateAdapter.getDate(this._dateAdapter.endOfMonth(targetDate));
538
+ const day = Math.min(this._dateAdapter.getDate(focusedDate), lastDay);
539
+ this._calendar.setFocusedDate(this._dateAdapter.set(targetDate, { day }));
535
540
  }
536
541
  /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: BrnCalendarMonthSelect, deps: [], target: i0.ɵɵFactoryTarget.Directive });
537
542
  /** @nocollapse */ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.16", type: BrnCalendarMonthSelect, isStandalone: true, selector: "brnSelect[brnCalendarMonthSelect],hlm-select[brnCalendarMonthSelect]", ngImport: i0 });
@@ -818,8 +823,13 @@ class BrnCalendarYearSelect {
818
823
  }
819
824
  /** Focus selected year */
820
825
  yearSelected(year) {
821
- const targetDate = this._dateAdapter.set(this._calendar.focusedDate(), { year });
822
- this._calendar.setFocusedDate(targetDate);
826
+ const focusedDate = this._calendar.focusedDate();
827
+ // Start from the first of the month so a day that does not exist in the target year
828
+ // (e.g. the 29th of February in a non-leap year) is clamped instead of rolling over.
829
+ const targetDate = this._dateAdapter.set(this._dateAdapter.startOfMonth(focusedDate), { year });
830
+ const lastDay = this._dateAdapter.getDate(this._dateAdapter.endOfMonth(targetDate));
831
+ const day = Math.min(this._dateAdapter.getDate(focusedDate), lastDay);
832
+ this._calendar.setFocusedDate(this._dateAdapter.set(targetDate, { day }));
823
833
  }
824
834
  /** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.16", ngImport: i0, type: BrnCalendarYearSelect, deps: [], target: i0.ɵɵFactoryTarget.Directive });
825
835
  /** @nocollapse */ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "21.2.16", type: BrnCalendarYearSelect, isStandalone: true, selector: "brnSelect[brnCalendarYearSelect],hlm-select[brnCalendarYearSelect]", ngImport: i0 });