Skip to content

Commit 9321753

Browse files
ddariborkaraivanov
andauthored
feat(date-picker): Set calendar activeDate on user input (#1819)
Co-authored-by: Radoslav Karaivanov <[email protected]>
1 parent 3c465e0 commit 9321753

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/components/date-picker/date-picker.spec.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,31 @@ describe('Date picker', () => {
938938
expect(selectedMonths).lengthOf(1);
939939
});
940940

941+
it('should update the calendar view when typing, i.e. switch to other month', async () => {
942+
const eventSpy = spy(picker, 'emitEvent');
943+
const date = new CalendarDay({ year: 2025, month: 1, date: 1 });
944+
picker.value = date.native;
945+
picker.open = true;
946+
picker.inputFormat = 'MM/dd/yyyy';
947+
await elementUpdated(picker);
948+
949+
dateTimeInput.focus();
950+
dateTimeInput.setSelectionRange(0, 1);
951+
await elementUpdated(picker);
952+
953+
simulateKeyboard(dateTimeInput, arrowUp);
954+
simulateKeyboard(dateTimeInput, arrowUp);
955+
956+
await elementUpdated(picker);
957+
958+
expect(eventSpy).calledWith('igcInput');
959+
expect(eventSpy).not.calledWith('igcChange');
960+
961+
const expectedValue = new CalendarDay({ year: 2025, month: 3, date: 1 })
962+
.native;
963+
checkDatesEqual(calendar.activeDate, expectedValue);
964+
});
965+
941966
describe('Readonly state', () => {
942967
describe('Dropdown mode', () => {
943968
beforeEach(async () => {

src/components/date-picker/date-picker.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ export default class IgcDatePickerComponent extends FormAssociatedRequiredMixin(
541541

542542
super.handleAnchorClick();
543543
await this.updateComplete;
544-
this._calendar[focusActiveDate]();
544+
this._calendar[focusActiveDate]({ preventScroll: true });
545545
}
546546

547547
protected _handleInputChangeEvent(event: CustomEvent<Date>): void {
@@ -583,6 +583,7 @@ export default class IgcDatePickerComponent extends FormAssociatedRequiredMixin(
583583
}
584584

585585
this.value = (event.target as IgcDateTimeInputComponent).value!;
586+
this._calendar.activeDate = this.value ?? this._calendar.activeDate;
586587
this.emitEvent('igcInput', { detail: this.value });
587588
}
588589

0 commit comments

Comments
 (0)