diff --git a/modules/@angular/router/src/directives/router_link.ts b/modules/@angular/router/src/directives/router_link.ts index bedb665792..d2fe867e19 100644 --- a/modules/@angular/router/src/directives/router_link.ts +++ b/modules/@angular/router/src/directives/router_link.ts @@ -7,7 +7,7 @@ */ import {LocationStrategy} from '@angular/common'; -import {Directive, HostBinding, HostListener, Input, OnChanges, OnDestroy} from '@angular/core'; +import {Attribute, Directive, ElementRef, HostBinding, HostListener, Input, OnChanges, OnDestroy, Renderer} from '@angular/core'; import {Subscription} from 'rxjs/Subscription'; import {NavigationEnd, Router} from '../router'; @@ -89,7 +89,13 @@ export class RouterLink { @Input() replaceUrl: boolean; private commands: any[] = []; - constructor(private router: Router, private route: ActivatedRoute) {} + constructor( + private router: Router, private route: ActivatedRoute, + @Attribute('tabindex') tabIndex: string, renderer: Renderer, el: ElementRef) { + if (tabIndex == null) { + renderer.setElementAttribute(el.nativeElement, 'tabindex', '0'); + } + } @Input() set routerLink(data: any[]|string) { diff --git a/modules/@angular/router/test/integration.spec.ts b/modules/@angular/router/test/integration.spec.ts index 2f78de70ec..3b2f708fe6 100644 --- a/modules/@angular/router/test/integration.spec.ts +++ b/modules/@angular/router/test/integration.spec.ts @@ -1031,8 +1031,9 @@ describe('Integration', () => { advance(fixture); expect(fixture.nativeElement).toHaveText('team 22 [ link, right: ]'); - const native = fixture.nativeElement.querySelector('button'); - native.click(); + const button = fixture.nativeElement.querySelector('button'); + expect(button.getAttribute('tabindex')).toEqual('0'); + button.click(); advance(fixture); expect(fixture.nativeElement).toHaveText('team 33 [ simple, right: ]'); diff --git a/tools/public_api_guard/router/index.d.ts b/tools/public_api_guard/router/index.d.ts index eb5a2ce1d7..01c4d65b5e 100644 --- a/tools/public_api_guard/router/index.d.ts +++ b/tools/public_api_guard/router/index.d.ts @@ -249,7 +249,7 @@ export declare class RouterLink { routerLink: any[] | string; skipLocationChange: boolean; urlTree: UrlTree; - constructor(router: Router, route: ActivatedRoute); + constructor(router: Router, route: ActivatedRoute, tabIndex: string, renderer: Renderer, el: ElementRef); onClick(): boolean; }