Skip to content

Commit 4c0fb35

Browse files
committed
add router link active to icon buttons
1 parent 2383720 commit 4c0fb35

File tree

5 files changed

+12
-15
lines changed

5 files changed

+12
-15
lines changed

src/app/app.component.spec.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,4 @@ describe('AppComponent', () => {
1414
expect(app).toBeTruthy();
1515
});
1616

17-
it(`should have the 'SwimResultsHelperApplication' title`, () => {
18-
const fixture = TestBed.createComponent(AppComponent);
19-
const app = fixture.componentInstance;
20-
expect(app.title).toEqual('SwimResultsHelperApplication');
21-
});
22-
23-
it('should render title', () => {
24-
const fixture = TestBed.createComponent(AppComponent);
25-
fixture.detectChanges();
26-
const compiled = fixture.nativeElement as HTMLElement;
27-
expect(compiled.querySelector('h1')?.textContent).toContain('Hello, SwimResultsHelperApplication');
28-
});
2917
});
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
<button (click)="onClick($event)">
1+
<button (click)="onClick($event)" routerLinkActive="active" [routerLink]="btnRouterLink">
22
<mat-icon>{{icon}}</mat-icon>
33
</button>

src/app/layout/element/icon-button/icon-button.component.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,9 @@ button {
1818
&:hover {
1919
filter: brightness(1.3);
2020
}
21+
22+
&.active {
23+
filter: brightness(1.3);
24+
color: cornflowerblue;
25+
}
2126
}

src/app/layout/element/icon-button/icon-button.component.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
import {Component, EventEmitter, Input, Output} from '@angular/core';
22
import {MatIcon} from '@angular/material/icon';
3+
import {RouterLink, RouterLinkActive} from '@angular/router';
34

45
@Component({
56
selector: 'app-icon-button',
67
imports: [
7-
MatIcon
8+
MatIcon,
9+
RouterLinkActive,
10+
RouterLink
811
],
912
templateUrl: './icon-button.component.html',
1013
styleUrl: './icon-button.component.scss'
1114
})
1215
export class IconButtonComponent {
1316
@Input() icon: string = "dashboard";
17+
@Input() btnRouterLink?: string;
1418

1519
@Output() btnClicked = new EventEmitter<PointerEvent>();
1620

src/app/layout/sidebar/sidebar.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
<li><app-icon-button icon="upload"></app-icon-button></li>
66
<li><app-icon-button icon="file_map"></app-icon-button></li>
77
<hr>
8-
<li><app-icon-button icon="live_tv" (btnClicked)="onOldLive()"></app-icon-button></li>
8+
<li><app-icon-button icon="live_tv" btnRouterLink="/old"></app-icon-button></li>
99
</ul>

0 commit comments

Comments
 (0)