Skip to content

Commit bdf35c1

Browse files
committed
feat(dp): update calendar selection on typing + test
1 parent 93cb0b0 commit bdf35c1

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

projects/igniteui-angular/src/lib/date-picker/date-picker.component.spec.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,32 @@ describe('IgxDatePicker', () => {
249249
.toBeTrue();
250250
expect(datePicker.isFocused).toBeTrue();
251251
}));
252+
253+
it('should update the calendar selection on typing', fakeAsync(() => {
254+
const date = new Date(2025, 0, 1);
255+
datePicker.value = date;
256+
datePicker.open();
257+
fixture.detectChanges();
258+
259+
const input = fixture.debugElement.query(By.css('.igx-input-group__input'));
260+
input.nativeElement.focus();
261+
tick();
262+
fixture.detectChanges();
263+
264+
fixture.detectChanges();
265+
UIInteractions.simulateTyping('02/01/2025', input);
266+
267+
const expectedDate = new Date(2025, 0, 2);
268+
expect(datePicker.value).toEqual(expectedDate);
269+
expect(datePicker.activeDate).toEqual(expectedDate);
270+
271+
const activeDescendantDate = new Date(expectedDate.setHours(0, 0, 0, 0)).getTime().toString();
272+
expect(datePicker['_calendar'].activeDate).toEqual(expectedDate);
273+
expect(datePicker['_calendar'].viewDate.getMonth()).toEqual(expectedDate.getMonth());
274+
expect(datePicker['_calendar'].value).toEqual(expectedDate);
275+
const wrapper = fixture.debugElement.query(By.css('.igx-calendar__wrapper')).nativeElement;
276+
expect(wrapper.getAttribute('aria-activedescendant')).toEqual(activeDescendantDate);
277+
}));
252278
});
253279

254280
describe('NgControl integration', () => {
@@ -776,7 +802,7 @@ describe('IgxDatePicker', () => {
776802

777803
mockCdr = jasmine.createSpyObj('ChangeDetectorRef', ['detectChanges']);
778804

779-
mockCalendar = { selected: new EventEmitter<any>() };
805+
mockCalendar = { selected: new EventEmitter<any>(), selectDate: () => {} };
780806
const mockComponentInstance = {
781807
calendar: mockCalendar,
782808
todaySelection: new EventEmitter<any>(),

projects/igniteui-angular/src/lib/date-picker/date-picker.component.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,9 @@ export class IgxDatePickerComponent extends PickerBaseDirective implements Contr
833833
return;
834834
}
835835
this._dateValue = DateTimeUtil.isValidDate(value) ? value : DateTimeUtil.parseIsoDate(value);
836+
if (this._calendar) {
837+
this._calendar.selectDate(this._dateValue);
838+
}
836839
}
837840

838841
private updateValidity() {

0 commit comments

Comments
 (0)