Skip to content

Commit e61f727

Browse files
ngdatepicker.component bugfixes
1 parent d9a5b32 commit e61f727

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

src/app/ngdatepicker/components/ngdatepicker/ngdatepicker.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div class="ngdatepicker" [class.ngdatepicker-visible]="visible">
22
<div class="ngdatepicker-header">
3-
<div class="ngdatepicker-header-arrow" (click)="backwards()">
3+
<div class="ngdatepicker-header-arrow" (click)="backwards($event)">
44
<div class="responsive-flex-wrapper">
55
<i class="material-icons">keyboard_arrow_left</i>
66
</div>
@@ -19,7 +19,7 @@
1919
</ng-container>
2020
</ng-container>
2121
</div>
22-
<div class="ngdatepicker-header-arrow" (click)="forwards()">
22+
<div class="ngdatepicker-header-arrow" (click)="forwards($event)">
2323
<div class="responsive-flex-wrapper">
2424
<i class="material-icons">keyboard_arrow_right</i>
2525
</div>

src/app/ngdatepicker/components/ngdatepicker/ngdatepicker.component.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { NgDate } from '../../models/ngDate';
88
styleUrls: ['./ngdatepicker.component.scss'],
99
changeDetection: ChangeDetectionStrategy.OnPush
1010
})
11-
export class NgDatepickerComponent implements AfterViewChecked {
11+
export class NgDatepickerComponent {
1212
private readonly yearCellsCount: number = 16;
1313
private readonly dayTimespan: number = 24 * 3600 * 1000;
1414
private readonly datesRows: number = 6;
@@ -29,10 +29,6 @@ export class NgDatepickerComponent implements AfterViewChecked {
2929

3030
constructor(private readonly changeDetectorRef: ChangeDetectorRef) {}
3131

32-
ngAfterViewChecked() {
33-
this.changeDetectorRef.markForCheck();
34-
}
35-
3632
get monthString(): string {
3733
return this.months[this.month];
3834
}
@@ -158,7 +154,12 @@ export class NgDatepickerComponent implements AfterViewChecked {
158154
this.year = this.date.getFullYear();
159155
}
160156

161-
backwards() {
157+
backwards(e: Event) {
158+
if (e) {
159+
e.stopPropagation();
160+
e.stopImmediatePropagation();
161+
}
162+
162163
switch (this.currentDatepickerView) {
163164
case DatepickerView.Days:
164165
this.month--;
@@ -194,7 +195,12 @@ export class NgDatepickerComponent implements AfterViewChecked {
194195
this.changeDetectorRef.markForCheck();
195196
}
196197

197-
forwards() {
198+
forwards(e: Event) {
199+
if (e) {
200+
e.stopPropagation();
201+
e.stopImmediatePropagation();
202+
}
203+
198204
switch (this.currentDatepickerView) {
199205
case DatepickerView.Days:
200206
this.month++;
@@ -253,12 +259,12 @@ export class NgDatepickerComponent implements AfterViewChecked {
253259
(ngDate.date.getMonth() < this.month && ngDate.date.getFullYear() === this.year) ||
254260
(ngDate.date.getMonth() > this.month && ngDate.date.getFullYear() < this.year)
255261
) {
256-
this.backwards();
262+
this.backwards(e);
257263
} else if (
258264
(ngDate.date.getMonth() > this.month && ngDate.date.getFullYear() === this.year) ||
259265
(ngDate.date.getMonth() < this.month && ngDate.date.getFullYear() > this.year)
260266
) {
261-
this.forwards();
267+
this.forwards(e);
262268
}
263269
} else {
264270
if (this.minDate) {
@@ -272,7 +278,7 @@ export class NgDatepickerComponent implements AfterViewChecked {
272278
return;
273279
}
274280
}
275-
281+
276282
this.dateChanged.emit(ngDate.date);
277283
this.hide();
278284
}

src/app/ngdatepicker/directives/ngdatepicker.directive.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ export class NgDatepickerDirective implements OnInit, OnChanges, OnDestroy {
4747

4848
this.appendToBody();
4949
this.initGlobalScrollHandler();
50-
51-
this.updateInstance();
5250
}
5351

5452
ngOnChanges() {
@@ -95,6 +93,7 @@ export class NgDatepickerDirective implements OnInit, OnChanges, OnDestroy {
9593

9694
NgDatepickerDirective.ngDatepickerDirectives.forEach(d => d.datepickerInstance.hide());
9795

96+
this.updateInstance();
9897
this.datepickerInstance.show();
9998
}
10099

0 commit comments

Comments
 (0)