feat(router): routerLink add tabindex attribute (#13094)

Fixes #10895
This commit is contained in:
Dzmitry Shylovich 2016-12-10 02:38:50 +03:00 committed by Victor Berchet
parent 90c223591f
commit a006c1418a
3 changed files with 12 additions and 5 deletions

View File

@ -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) {

View File

@ -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: ]');

View File

@ -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;
}