diff --git a/src/datepicker/datepicker-navigation.spec.ts b/src/datepicker/datepicker-navigation.spec.ts index de5088829f..5ba3c729dc 100644 --- a/src/datepicker/datepicker-navigation.spec.ts +++ b/src/datepicker/datepicker-navigation.spec.ts @@ -92,17 +92,35 @@ describe('ngb-datepicker-navigation', () => { it('should send navigation events', () => { const fixture = createTestComponent(``); - - const links = getNavigationLinks(fixture.nativeElement); + const[previousButton, nextButton] = getNavigationLinks(fixture.nativeElement); + const previousButtonSpan = previousButton.querySelector('span'); + const nextButtonSpan = nextButton.querySelector('span'); spyOn(fixture.componentInstance, 'onNavigate'); // prev - links[0].click(); + previousButton.click(); + expect(fixture.componentInstance.onNavigate).toHaveBeenCalledWith(NavigationEvent.PREV); + previousButtonSpan.click(); expect(fixture.componentInstance.onNavigate).toHaveBeenCalledWith(NavigationEvent.PREV); // next - links[1].click(); + nextButton.click(); expect(fixture.componentInstance.onNavigate).toHaveBeenCalledWith(NavigationEvent.NEXT); + nextButtonSpan.click(); + expect(fixture.componentInstance.onNavigate).toHaveBeenCalledWith(NavigationEvent.NEXT); + }); + + it('should retain focus on the navigation links after click', () => { + const fixture = createTestComponent(``); + const[previousButton, nextButton] = getNavigationLinks(fixture.nativeElement); + + // prev + previousButton.click(); + expect(document.activeElement).toBe(previousButton); + + // next + nextButton.click(); + expect(document.activeElement).toBe(nextButton); }); it('should have buttons of type button', () => { diff --git a/src/datepicker/datepicker-navigation.ts b/src/datepicker/datepicker-navigation.ts index 4d033fe626..a9def7bb16 100644 --- a/src/datepicker/datepicker-navigation.ts +++ b/src/datepicker/datepicker-navigation.ts @@ -10,7 +10,7 @@ import {NgbDatepickerI18n} from './datepicker-i18n'; styleUrls: ['./datepicker-navigation.scss'], template: `
-