[CL-206] update bit-nav components to active match query params (#8242)

* remove exactMatch input in favor of routerLinkActiveOptions
This commit is contained in:
Will Martin 2024-03-11 11:22:04 -04:00 committed by GitHub
parent 687f0e590a
commit d66365fd53
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 32 additions and 29 deletions

View File

@ -4,8 +4,8 @@
[ariaLabel]="['organization' | i18n, activeOrganization.name].join(' ')" [ariaLabel]="['organization' | i18n, activeOrganization.name].join(' ')"
icon="bwi-business" icon="bwi-business"
[route]="['../', activeOrganization.id]" [route]="['../', activeOrganization.id]"
[routerLinkActiveOptions]="{ exact: true }"
[(open)]="open" [(open)]="open"
[exactMatch]="true"
> >
<i <i
slot="end" slot="end"
@ -21,7 +21,7 @@
[ariaLabel]="['organization' | i18n, org.name].join(' ')" [ariaLabel]="['organization' | i18n, org.name].join(' ')"
[route]="['../', org.id]" [route]="['../', org.id]"
(mainContentClicked)="toggle()" (mainContentClicked)="toggle()"
[exactMatch]="true" [routerLinkActiveOptions]="{ exact: true }"
> >
<i <i
slot="end" slot="end"

View File

@ -1,8 +1,8 @@
import { Directive, EventEmitter, Input, Output } from "@angular/core"; import { Directive, EventEmitter, Input, Output } from "@angular/core";
import { ActivatedRoute } from "@angular/router"; import { RouterLink, RouterLinkActive } from "@angular/router";
/** /**
* Base class used in `NavGroupComponent` and `NavItemComponent` * `NavGroupComponent` builds upon `NavItemComponent`. This class represents the properties that are passed down to `NavItemComponent`.
*/ */
@Directive() @Directive()
export abstract class NavBaseComponent { export abstract class NavBaseComponent {
@ -22,14 +22,36 @@ export abstract class NavBaseComponent {
@Input() icon: string; @Input() icon: string;
/** /**
* Route to be passed to internal `routerLink` * Optional route to be passed to internal `routerLink`. If not provided, the nav component will render as a button.
*
* See: {@link RouterLink.routerLink}
*
* ---
*
* We can't name this "routerLink" because Angular will mount the `RouterLink` directive.
*
* See: {@link https://github.com/angular/angular/issues/24482}
*/ */
@Input() route: string | any[]; @Input() route?: RouterLink["routerLink"];
/** /**
* Passed to internal `routerLink` * Passed to internal `routerLink`
*
* See {@link RouterLink.relativeTo}
*/ */
@Input() relativeTo?: ActivatedRoute | null; @Input() relativeTo?: RouterLink["relativeTo"];
/**
* Passed to internal `routerLink`
*
* See {@link RouterLinkActive.routerLinkActiveOptions}
*/
@Input() routerLinkActiveOptions?: RouterLinkActive["routerLinkActiveOptions"] = {
paths: "subset",
queryParams: "ignored",
fragment: "ignored",
matrixParams: "ignored",
};
/** /**
* If this item is used within a tree, set `variant` to `"tree"` * If this item is used within a tree, set `variant` to `"tree"`

View File

@ -4,12 +4,12 @@
[icon]="icon" [icon]="icon"
[route]="route" [route]="route"
[relativeTo]="relativeTo" [relativeTo]="relativeTo"
[routerLinkActiveOptions]="routerLinkActiveOptions"
[variant]="variant" [variant]="variant"
(mainContentClicked)="toggle()" (mainContentClicked)="toggle()"
[treeDepth]="treeDepth" [treeDepth]="treeDepth"
(mainContentClicked)="mainContentClicked.emit()" (mainContentClicked)="mainContentClicked.emit()"
[ariaLabel]="ariaLabel" [ariaLabel]="ariaLabel"
[exactMatch]="exactMatch"
[hideActiveStyles]="parentHideActiveStyles" [hideActiveStyles]="parentHideActiveStyles"
> >
<ng-template #button> <ng-template #button>

View File

@ -39,11 +39,6 @@ export class NavGroupComponent extends NavBaseComponent implements AfterContentI
@Input() @Input()
open = false; open = false;
/**
* if `true`, use `exact` match for path instead of `subset`.
*/
@Input() exactMatch: boolean;
@Output() @Output()
openChange = new EventEmitter<boolean>(); openChange = new EventEmitter<boolean>();

View File

@ -54,7 +54,7 @@
[relativeTo]="relativeTo" [relativeTo]="relativeTo"
[attr.aria-label]="ariaLabel || text" [attr.aria-label]="ariaLabel || text"
routerLinkActive routerLinkActive
[routerLinkActiveOptions]="rlaOptions" [routerLinkActiveOptions]="routerLinkActiveOptions"
[ariaCurrentWhenActive]="'page'" [ariaCurrentWhenActive]="'page'"
(isActiveChange)="setIsActive($event)" (isActiveChange)="setIsActive($event)"
(click)="mainContentClicked.emit()" (click)="mainContentClicked.emit()"

View File

@ -1,5 +1,4 @@
import { Component, HostListener, Input, Optional } from "@angular/core"; import { Component, HostListener, Optional } from "@angular/core";
import { IsActiveMatchOptions } from "@angular/router";
import { BehaviorSubject, map } from "rxjs"; import { BehaviorSubject, map } from "rxjs";
import { NavBaseComponent } from "./nav-base.component"; import { NavBaseComponent } from "./nav-base.component";
@ -24,19 +23,6 @@ export class NavItemComponent extends NavBaseComponent {
protected get showActiveStyles() { protected get showActiveStyles() {
return this._isActive && !this.hideActiveStyles; return this._isActive && !this.hideActiveStyles;
} }
protected rlaOptions: IsActiveMatchOptions = {
paths: "subset",
queryParams: "exact",
fragment: "ignored",
matrixParams: "ignored",
};
/**
* if `true`, use `exact` match for path instead of `subset`.
*/
@Input() set exactMatch(val: boolean) {
this.rlaOptions.paths = val ? "exact" : "subset";
}
/** /**
* The design spec calls for the an outline to wrap the entire element when the template's anchor/button has :focus-visible. * The design spec calls for the an outline to wrap the entire element when the template's anchor/button has :focus-visible.