Skip to content

Commit

Permalink
fix(module:calendar): year dropdown update issue when date is changed…
Browse files Browse the repository at this point in the history
… programmatically (#8286)

* fix(module:calendar): year dropdown not changing with date being changed

* fix(module:calendar): year dropdown not changing with date being changed
  • Loading branch information
ParsaArvanehPA committed Apr 17, 2024
1 parent 9bcce6c commit ee68a2c
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion components/calendar/calendar-header.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import {
Component,
EventEmitter,
Input,
OnChanges,
OnInit,
Output,
SimpleChanges,
TemplateRef,
ViewEncapsulation
} from '@angular/core';
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit ee68a2c

Please sign in to comment.