From 38da2587ebc666816a0047aa075ccbf530c11999 Mon Sep 17 00:00:00 2001 From: Volodymyr Pohrebniak Date: Fri, 15 Nov 2019 22:33:36 +0100 Subject: [PATCH] fix(pagination): don't focus links of disabled pagination (#3468) --- src/pagination/pagination.spec.ts | 28 +++++++++++++++++++--------- src/pagination/pagination.ts | 12 ++++++------ 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/pagination/pagination.spec.ts b/src/pagination/pagination.spec.ts index 0ccee67132..fa37c295b8 100644 --- a/src/pagination/pagination.spec.ts +++ b/src/pagination/pagination.spec.ts @@ -630,17 +630,27 @@ describe('ngb-pagination', () => { expect(fixture.componentInstance.onPageChange).not.toHaveBeenCalled(); })); - it('should set classes correctly for disabled state', fakeAsync(() => { - const html = ` { + const html = ``; - const fixture = createTestComponent(html); - tick(); + const fixture = createTestComponent(html); - const buttons = fixture.nativeElement.querySelectorAll('li'); - for (let i = 0; i < buttons.length; i++) { - expect(buttons[i]).toHaveCssClass('disabled'); - } - })); + const buttons = fixture.nativeElement.querySelectorAll('li'); + for (let i = 0; i < buttons.length; i++) { + expect(buttons[i]).toHaveCssClass('disabled'); + } + }); + + it('should set tabindex for links correctly for disabled state', () => { + const html = ``; + const fixture = createTestComponent(html); + + const buttonLinks = fixture.nativeElement.querySelectorAll('li a'); + for (let i = 0; i < buttonLinks.length; i++) { + expect(buttonLinks[i].getAttribute('tabindex')).toEqual('-1'); + } + }); }); describe('Customization', () => { diff --git a/src/pagination/pagination.ts b/src/pagination/pagination.ts index d16508fbea..374add03e4 100644 --- a/src/pagination/pagination.ts +++ b/src/pagination/pagination.ts @@ -132,7 +132,7 @@ export class NgbPaginationPrevious {
  • + (click)="selectPage(1); $event.preventDefault()" [attr.tabindex]="(hasPrevious() && !disabled ? null : '-1')"> @@ -141,25 +141,25 @@ export class NgbPaginationPrevious {
  • + (click)="selectPage(page-1); $event.preventDefault()" [attr.tabindex]="(hasPrevious() && !disabled ? null : '-1')">
  • - + - +
  • + (click)="selectPage(page+1); $event.preventDefault()" [attr.tabindex]="(hasNext() && !disabled ? null : '-1')"> @@ -167,7 +167,7 @@ export class NgbPaginationPrevious {
  • + (click)="selectPage(pageCount); $event.preventDefault()" [attr.tabindex]="(hasNext() && !disabled ? null : '-1')">