From ee68a2c90370a6e3a599fe9f914af20117d2faa6 Mon Sep 17 00:00:00 2001 From: Parsa Arvaneh <62149413+ParsaArvanehPA@users.noreply.github.com> Date: Wed, 17 Apr 2024 13:34:57 +0330 Subject: [PATCH] fix(module:calendar): year dropdown update issue when date is changed programmatically (#8286) * fix(module:calendar): year dropdown not changing with date being changed * fix(module:calendar): year dropdown not changing with date being changed --- components/calendar/calendar-header.component.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/components/calendar/calendar-header.component.ts b/components/calendar/calendar-header.component.ts index 34248f0b595..aa8e69eb222 100644 --- a/components/calendar/calendar-header.component.ts +++ b/components/calendar/calendar-header.component.ts @@ -9,8 +9,10 @@ import { Component, EventEmitter, Input, + OnChanges, OnInit, Output, + SimpleChanges, TemplateRef, ViewEncapsulation } from '@angular/core'; @@ -77,7 +79,7 @@ import { NzSelectModule, NzSelectSizeType } from 'ng-zorro-antd/select'; imports: [NzSelectModule, FormsModule, NzRadioModule, NgTemplateOutlet, NzStringTemplateOutletDirective], standalone: true }) -export class NzCalendarHeaderComponent implements OnInit { +export class NzCalendarHeaderComponent implements OnInit, OnChanges { @Input() mode: 'month' | 'year' = 'month'; @Input() fullscreen: boolean = true; @Input() activeDate: CandyDate = new CandyDate(); @@ -123,6 +125,16 @@ export class NzCalendarHeaderComponent implements OnInit { this.setUpMonths(); } + ngOnChanges(changes: SimpleChanges): void { + if (changes['activeDate']) { + const previousActiveDate = changes['activeDate'].previousValue as CandyDate; + const currentActiveDate = changes['activeDate'].currentValue as CandyDate; + if (previousActiveDate?.getYear() !== currentActiveDate?.getYear()) { + this.setUpYears(); + } + } + } + updateYear(year: number): void { this.yearChange.emit(year); this.setUpYears(year);