Skip to content

Commit

Permalink
fix: pass route extras in routerLink (#2905)
Browse files Browse the repository at this point in the history
Signed-off-by: Akshat Patel <akshat@live.ca>
Co-authored-by: Andrea Paolucci <35496522+Licen-it@users.noreply.github.com>
  • Loading branch information
Akshat55 and Licen-it committed May 29, 2024
1 parent 65c7392 commit 1c1c314
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
20 changes: 5 additions & 15 deletions src/ui-shell/sidenav/side-nav.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class FooComponent { }
@Component({
template: `
<cds-sidenav [allowExpansion]="allowExpansion" [hidden]="hidden">
<cds-sidenav-menu title="Example Title"></cds-sidenav-menu>
<cds-sidenav-menu title="Example Title"></cds-sidenav-menu>
<cds-sidenav-item
[route]="route"
[useRouter]="useRouter"
Expand Down Expand Up @@ -67,7 +67,7 @@ describe("SideNav", () => {
});
});

it("should work", () => {
it("should work", () => {
fixture = TestBed.createComponent(SideNav);
expect(fixture.componentInstance instanceof SideNav).toBe(true);
});
Expand All @@ -81,7 +81,7 @@ describe("SideNav", () => {
fixture.detectChanges();
});

it("should emit the navigation status promise when the link is activated and call onNavigation", async () => {
it("should emit the navigation status promise when the link is activated and call onNavigation", async () => {
wrapper = fixture.componentInstance;
spyOn(wrapper, "onNavigation").and.callThrough();
fixture.detectChanges();
Expand Down Expand Up @@ -110,7 +110,7 @@ describe("SideNav", () => {
it("should set the sidenav-menu title to Example Title", () => {
fixture.detectChanges();
element = fixture.debugElement.query(By.css("cds-sidenav-menu"));
expect(element.nativeElement.textContent).toEqual("Example Title");
expect(element.nativeElement.textContent).toEqual("Example Title");
});

it("should toggle expanded on click", () => {
Expand Down Expand Up @@ -140,16 +140,6 @@ describe("SideNav", () => {
fixture.detectChanges();
});

it("should not emit the navigation status promise when the link is activated and call onNavigation", async () => {
wrapper = fixture.componentInstance;
spyOn(wrapper, "onNavigation").and.callThrough();
fixture.detectChanges();
element = fixture.debugElement.query(By.css(".cds--side-nav__link"));
element.nativeElement.click();
fixture.detectChanges();
expect(wrapper.onNavigation).not.toHaveBeenCalled();
});

it("should expand sidenav-menu on click", () => {
wrapper = fixture.componentInstance;
fixture.detectChanges();
Expand All @@ -167,7 +157,7 @@ describe("SideNav", () => {
it("should set the sidenav-menu title to Example Title", () => {
fixture.detectChanges();
element = fixture.debugElement.query(By.css("cds-sidenav-menu"));
expect(element.nativeElement.textContent).toEqual("Example Title");
expect(element.nativeElement.textContent).toEqual("Example Title");
});

it("should toggle expanded on click", () => {
Expand Down
13 changes: 7 additions & 6 deletions src/ui-shell/sidenav/sidenav-item.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,22 @@ import { Router } from "@angular/router";
selector: "cds-sidenav-item, ibm-sidenav-item",
template: `
<a *ngIf="!useRouter; else sidenavItemRouterTpl"
class="cds--side-nav__link"
[ngClass]="{
class="cds--side-nav__link"
[ngClass]="{
'cds--side-nav__item--active': active
}"
[href]="href"
[attr.aria-current]="(active ? 'page' : null)"
[attr.title]="title ? title : null"
(click)="navigate($event)">
[href]="href"
[attr.aria-current]="(active ? 'page' : null)"
[attr.title]="title ? title : null"
(click)="navigate($event)">
<ng-template [ngTemplateOutlet]="sidenavItemContentTpl"></ng-template>
</a>
<ng-template #sidenavItemRouterTpl>
<a
[routerLink]="route"
routerLinkActive="cds--side-nav__item--active"
(click)="navigate($event)"
ariaCurrentWhenActive="page"
[attr.title]="title ? title : null"
class="cds--side-nav__link">
Expand Down

0 comments on commit 1c1c314

Please sign in to comment.