Skip to content

Commit

Permalink
feat(router): routerLink add tabindex attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
Dzmitry Shylovich authored and Dzmitry Shylovich committed Dec 3, 2016
1 parent 6cf7a1b commit e8c0e7e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
8 changes: 6 additions & 2 deletions modules/@angular/router/src/directives/router_link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -99,7 +99,11 @@ export class RouterLink {

constructor(
private router: Router, private route: ActivatedRoute,
private locationStrategy: LocationStrategy) {}
@Attribute('tabindex') tabIndex: string, renderer: Renderer, el: ElementRef) {
if (tabIndex == null) {
renderer.setElementAttribute(el.nativeElement, 'tabindex', '0');
}
}

@Input()
set routerLink(data: any[]|string) {
Expand Down
5 changes: 3 additions & 2 deletions modules/@angular/router/test/integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1005,8 +1005,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: ]');
Expand Down
2 changes: 1 addition & 1 deletion tools/public_api_guard/router/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ export declare class RouterLink {
routerLink: any[] | string;
skipLocationChange: boolean;
urlTree: UrlTree;
constructor(router: Router, route: ActivatedRoute, locationStrategy: LocationStrategy);
constructor(router: Router, route: ActivatedRoute, tabIndex: string, renderer: Renderer, el: ElementRef);
onClick(): boolean;
}

Expand Down

0 comments on commit e8c0e7e

Please sign in to comment.