/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ import { ChangeDetectorRef, ContentChildren, Directive, ElementRef, EventEmitter, Input, Optional, Output, QueryList, Renderer2 } from '@angular/core'; import { from, of } from 'rxjs'; import { mergeAll } from 'rxjs/operators'; import { NavigationEnd } from '../events'; import { Router } from '../router'; import { RouterLink } from './router_link'; import * as i0 from "@angular/core"; import * as i1 from "../router"; import * as i2 from "./router_link"; /** * * @description * * Tracks whether the linked route of an element is currently active, and allows you * to specify one or more CSS classes to add to the element when the linked route * is active. * * Use this directive to create a visual distinction for elements associated with an active route. * For example, the following code highlights the word "Bob" when the router * activates the associated route: * * ``` * Bob * ``` * * Whenever the URL is either '/user' or '/user/bob', the "active-link" class is * added to the anchor tag. If the URL changes, the class is removed. * * You can set more than one class using a space-separated string or an array. * For example: * * ``` * Bob * Bob * ``` * * To add the classes only when the URL matches the link exactly, add the option `exact: true`: * * ``` * Bob * ``` * * To directly check the `isActive` status of the link, assign the `RouterLinkActive` * instance to a template variable. * For example, the following checks the status without assigning any CSS classes: * * ``` * * Bob {{ rla.isActive ? '(already open)' : ''}} * * ``` * * You can apply the `RouterLinkActive` directive to an ancestor of linked elements. * For example, the following sets the active-link class on the `
` parent tag * when the URL is either '/user/jim' or '/user/bob'. * * ``` *
* Jim * Bob *
* ``` * * The `RouterLinkActive` directive can also be used to set the aria-current attribute * to provide an alternative distinction for active elements to visually impaired users. * * For example, the following code adds the 'active' class to the Home Page link when it is * indeed active and in such case also sets its aria-current attribute to 'page': * * ``` * Home Page * ``` * * @ngModule RouterModule * * @publicApi */ export class RouterLinkActive { get isActive() { return this._isActive; } constructor(router, element, renderer, cdr, link) { this.router = router; this.element = element; this.renderer = renderer; this.cdr = cdr; this.link = link; this.classes = []; this._isActive = false; /** * Options to configure how to determine if the router link is active. * * These options are passed to the `Router.isActive()` function. * * @see {@link Router#isActive} */ this.routerLinkActiveOptions = { exact: false }; /** * * You can use the output `isActiveChange` to get notified each time the link becomes * active or inactive. * * Emits: * true -> Route is active * false -> Route is inactive * * ``` * Bob * ``` */ this.isActiveChange = new EventEmitter(); this.routerEventsSubscription = router.events.subscribe((s) => { if (s instanceof NavigationEnd) { this.update(); } }); } /** @nodoc */ ngAfterContentInit() { // `of(null)` is used to force subscribe body to execute once immediately (like `startWith`). of(this.links.changes, of(null)).pipe(mergeAll()).subscribe(_ => { this.update(); this.subscribeToEachLinkOnChanges(); }); } subscribeToEachLinkOnChanges() { this.linkInputChangesSubscription?.unsubscribe(); const allLinkChanges = [...this.links.toArray(), this.link] .filter((link) => !!link) .map(link => link.onChanges); this.linkInputChangesSubscription = from(allLinkChanges).pipe(mergeAll()).subscribe(link => { if (this._isActive !== this.isLinkActive(this.router)(link)) { this.update(); } }); } set routerLinkActive(data) { const classes = Array.isArray(data) ? data : data.split(' '); this.classes = classes.filter(c => !!c); } /** @nodoc */ ngOnChanges(changes) { this.update(); } /** @nodoc */ ngOnDestroy() { this.routerEventsSubscription.unsubscribe(); this.linkInputChangesSubscription?.unsubscribe(); } update() { if (!this.links || !this.router.navigated) return; queueMicrotask(() => { const hasActiveLinks = this.hasActiveLinks(); if (this._isActive !== hasActiveLinks) { this._isActive = hasActiveLinks; this.cdr.markForCheck(); this.classes.forEach((c) => { if (hasActiveLinks) { this.renderer.addClass(this.element.nativeElement, c); } else { this.renderer.removeClass(this.element.nativeElement, c); } }); if (hasActiveLinks && this.ariaCurrentWhenActive !== undefined) { this.renderer.setAttribute(this.element.nativeElement, 'aria-current', this.ariaCurrentWhenActive.toString()); } else { this.renderer.removeAttribute(this.element.nativeElement, 'aria-current'); } // Emit on isActiveChange after classes are updated this.isActiveChange.emit(hasActiveLinks); } }); } isLinkActive(router) { const options = isActiveMatchOptions(this.routerLinkActiveOptions) ? this.routerLinkActiveOptions : // While the types should disallow `undefined` here, it's possible without strict inputs (this.routerLinkActiveOptions.exact || false); return (link) => link.urlTree ? router.isActive(link.urlTree, options) : false; } hasActiveLinks() { const isActiveCheckFn = this.isLinkActive(this.router); return this.link && isActiveCheckFn(this.link) || this.links.some(isActiveCheckFn); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: RouterLinkActive, deps: [{ token: i1.Router }, { token: i0.ElementRef }, { token: i0.Renderer2 }, { token: i0.ChangeDetectorRef }, { token: i2.RouterLink, optional: true }], target: i0.ɵɵFactoryTarget.Directive }); } static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.12", type: RouterLinkActive, isStandalone: true, selector: "[routerLinkActive]", inputs: { routerLinkActiveOptions: "routerLinkActiveOptions", ariaCurrentWhenActive: "ariaCurrentWhenActive", routerLinkActive: "routerLinkActive" }, outputs: { isActiveChange: "isActiveChange" }, queries: [{ propertyName: "links", predicate: RouterLink, descendants: true }], exportAs: ["routerLinkActive"], usesOnChanges: true, ngImport: i0 }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: RouterLinkActive, decorators: [{ type: Directive, args: [{ selector: '[routerLinkActive]', exportAs: 'routerLinkActive', standalone: true, }] }], ctorParameters: function () { return [{ type: i1.Router }, { type: i0.ElementRef }, { type: i0.Renderer2 }, { type: i0.ChangeDetectorRef }, { type: i2.RouterLink, decorators: [{ type: Optional }] }]; }, propDecorators: { links: [{ type: ContentChildren, args: [RouterLink, { descendants: true }] }], routerLinkActiveOptions: [{ type: Input }], ariaCurrentWhenActive: [{ type: Input }], isActiveChange: [{ type: Output }], routerLinkActive: [{ type: Input }] } }); /** * Use instead of `'paths' in options` to be compatible with property renaming */ function isActiveMatchOptions(options) { return !!options.paths; } //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicm91dGVyX2xpbmtfYWN0aXZlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vLi4vcGFja2FnZ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