From e6a29205f957baa5249ebf828090e100b4c5cb68 Mon Sep 17 00:00:00 2001 From: Brandon Date: Mon, 25 Apr 2016 13:09:53 -0500 Subject: [PATCH] feat(LinkActive): Added default class when link is active (#72) * feat(LinkActive): Added default class when link is active * fix(guard): Fixed guard in lib export Closes #71 --- lib/index.ts | 2 +- lib/link-active.ts | 2 +- spec/link-active.spec.ts | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/index.ts b/lib/index.ts index 2d63384..1ff3f81 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -34,7 +34,7 @@ export function provideRouter(routes: Routes) { } -export { Guard, createGuard } from './guard'; +export { Guard, provideGuard } from './guard'; export { LocationChange, Router } from './router'; export { Middleware, createMiddleware } from './middleware'; export { RouteParams, QueryParams } from './params'; diff --git a/lib/link-active.ts b/lib/link-active.ts index 75077cc..749529e 100644 --- a/lib/link-active.ts +++ b/lib/link-active.ts @@ -30,7 +30,7 @@ export interface LinkActiveOptions { */ @Directive({ selector: '[linkActive]' }) export class LinkActive implements AfterViewInit, OnDestroy { - @Input('linkActive') activeClass: string; + @Input('linkActive') activeClass: string = 'active'; @Input() activeOptions: LinkActiveOptions = { exact: true }; private _sub: any; diff --git a/spec/link-active.spec.ts b/spec/link-active.spec.ts index e7d6a23..2034805 100644 --- a/spec/link-active.spec.ts +++ b/spec/link-active.spec.ts @@ -59,6 +59,22 @@ describe('Link Active', () => { }); })); + it('should add a default class to the active element if not provided', injectAsync([TestComponentBuilder, Router], (tcb, router$) => { + router$.next({ + path: '/page' + }); + + return compile(tcb, 'Page') + .then((fixture) => { + fixture.detectChanges(); + let compiled = fixture.debugElement.nativeElement; + let link: Element = compiled.querySelector('a'); + + fixture.detectChanges(); + expect(link.getAttribute('class')).toEqual('active'); + }); + })); + it('should support multiple classes on the active element', injectAsync([TestComponentBuilder, Router], (tcb, router$) => { router$.next({ path: '/page'