Skip to content

Commit 260c5f0

Browse files
authored
fix(calendar): ngModel doesn't update with updateOn: 'blur' set (#14172)
* fix(calendar): ngModel doesn't update with updateOn: 'blur' set * demos(calendar): update sample
1 parent d721693 commit 260c5f0

File tree

5 files changed

+44
-3
lines changed

5 files changed

+44
-3
lines changed

projects/igniteui-angular/src/lib/calendar/calendar.component.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,7 @@ export class IgxCalendarComponent extends IgxCalendarBaseDirective implements Af
530530

531531
this.showActiveDay = false;
532532
this.monthViews.forEach(view => view.clearPreviewRange());
533+
this._onTouchedCallback();
533534
}
534535

535536
private handleArrowKeydown(event: KeyboardEvent, delta: number) {

projects/igniteui-angular/src/lib/calendar/days-view/days-view.component.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,10 @@ export class IgxDaysViewComponent extends IgxCalendarBaseDirective {
350350
});
351351
}
352352

353-
this.el.nativeElement.focus();
353+
if (this.tabIndex !== -1) {
354+
this.el.nativeElement.focus();
355+
}
356+
354357
this.activeDate = item.date.native;
355358
this.selectActiveDate();
356359
}

src/app/calendar/calendar.sample.html

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
[weekStart]="getWeekDayNumber(weekStart)"
1818
[headerOrientation]="headerOrientation"
1919
[orientation]="orientation"
20+
[(ngModel)]="date"
21+
[ngModelOptions]="{updateOn: 'blur'}"
2022
>
2123
</igx-calendar>
2224
</div>
@@ -168,7 +170,15 @@
168170
</div>
169171

170172
<small>Active date</small>
171-
<span>{{calendar.activeDate.toLocaleDateString()}}</span>
173+
<span>{{calendar.activeDate | date }}</span>
174+
175+
<small>Selected date(s)</small>
176+
177+
<ol class="selected-dates" [class.multiple]="selection.length > 1">
178+
@for (item of selection; track item) {
179+
<li>{{item | date }}</li>
180+
}
181+
</ol>
172182

173183
<div class="preview__info">
174184
<a

src/app/calendar/calendar.sample.scss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,13 @@ igx-date-range-picker {
122122
.gap {
123123
gap: 1rem;
124124
}
125+
126+
.selected-dates {
127+
margin: 0;
128+
padding-inline: 1rem;
129+
130+
&:not(.multiple) {
131+
padding: 0;
132+
list-style: none;
133+
}
134+
}

src/app/calendar/calendar.sample.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
CUSTOM_ELEMENTS_SCHEMA,
55
ChangeDetectionStrategy,
66
} from "@angular/core";
7-
import { NgFor } from "@angular/common";
7+
import { NgFor, DatePipe, DATE_PIPE_DEFAULT_OPTIONS } from "@angular/common";
88
import { FormsModule } from "@angular/forms";
99
import {
1010
DateRangeType,
@@ -65,6 +65,12 @@ defineComponents(IgcCalendarComponent);
6565
schemas: [CUSTOM_ELEMENTS_SCHEMA],
6666
standalone: true,
6767
changeDetection: ChangeDetectionStrategy.OnPush,
68+
providers: [
69+
{
70+
provide: DATE_PIPE_DEFAULT_OPTIONS,
71+
useValue: { dateFormat: 'longDate', }
72+
}
73+
],
6874
imports: [
6975
IgxButtonDirective,
7076
IgxRippleDirective,
@@ -80,6 +86,7 @@ defineComponents(IgcCalendarComponent);
8086
IgxSwitchComponent,
8187
IgxIconComponent,
8288
NgFor,
89+
DatePipe
8390
],
8491
})
8592
export class CalendarSampleComponent {
@@ -93,6 +100,8 @@ export class CalendarSampleComponent {
93100
year: "numeric",
94101
};
95102

103+
protected date = new Date();
104+
96105
private _today = new Date();
97106
private _locale: string;
98107
private _selectionType: ISelectionType;
@@ -296,4 +305,12 @@ export class CalendarSampleComponent {
296305
protected getWeekDayNumber(value: WeekDays | string) {
297306
return DaysMap[value];
298307
}
308+
309+
protected get selection(): Date[] {
310+
if (Array.isArray(this.date)) {
311+
return this.date;
312+
}
313+
314+
return [this.date];
315+
}
299316
}

0 commit comments

Comments
 (0)