Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Injectable, ElementRef, NgZone, inject } from "@angular/core";
import { ChangeDetectorRef, ElementRef, Injectable, NgZone, inject } from "@angular/core";
import { EventManager } from "@angular/platform-browser";
import { PlatformUtil } from 'igniteui-angular/core';

@Injectable()
export class KeyboardNavigationService {
private eventManager = inject(EventManager);
private ngZone = inject(NgZone);
private cdr = inject(ChangeDetectorRef);

Comment thread
viktorkombov marked this conversation as resolved.
private keyHandlers = new Map<string, (event: KeyboardEvent) => void>();
private eventUnsubscribeFn: Function | null = null;
Expand All @@ -26,7 +27,10 @@ export class KeyboardNavigationService {
const handler = this.keyHandlers.get(event.key);

if (handler) {
this.ngZone.run(handler.bind(context, event));
this.ngZone.run(() => {
handler.call(context, event);
this.cdr.markForCheck();
});
}
Comment thread
viktorkombov marked this conversation as resolved.
}
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, ViewChild, ChangeDetectionStrategy } from '@angular/core';
import { ChangeDetectionStrategy, Component, provideZonelessChangeDetection, ViewChild } from '@angular/core';
import { TestBed } from '@angular/core/testing';
import { FormsModule } from '@angular/forms';
import { By } from '@angular/platform-browser';
Expand Down Expand Up @@ -729,6 +729,7 @@ describe('IgxMonthPicker', () => {

expect(monthPicker.activeView).toBe(IgxCalendarView.Decade);
});

});

@Component({
Expand All @@ -754,3 +755,31 @@ export class IgxMonthPickerSampleComponent {
year: 'numeric'
};
}

describe('IgxMonthPicker in zoneless change detection', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [NoopAnimationsModule, IgxMonthPickerSampleComponent],
providers: [provideZonelessChangeDetection()]
}).compileComponents();
});

it('should update the highlighted month after keyboard navigation', async () => {
const fixture = TestBed.createComponent(IgxMonthPickerSampleComponent);
fixture.detectChanges();
await fixture.whenStable();

const monthPicker = fixture.componentInstance.monthPicker;
const wrapper = fixture.debugElement.query(By.css('.igx-calendar__wrapper'));
wrapper.nativeElement.focus();
await fixture.whenStable();
const initiallyHighlightedMonth = fixture.debugElement.query(By.css('.igx-calendar-view__item--selected'));
UIInteractions.triggerKeyDownEvtUponElem('ArrowRight', wrapper.nativeElement);
await fixture.whenStable();

expect(monthPicker.monthsView.date.getMonth()).toBe(2);
const highlightedMonth = fixture.debugElement.query(By.css('.igx-calendar-view__item--selected'));
expect(highlightedMonth.nativeElement).not.toBe(initiallyHighlightedMonth.nativeElement);
expect(highlightedMonth.nativeElement.textContent.trim()).toBe('Mar');
});
Comment on lines +767 to +784
});
Loading