Skip to content
This repository was archived by the owner on Dec 18, 2024. It is now read-only.

Commit ae1429b

Browse files
committed
fix(component-sidenav): apply aria-current to selected nav items & improve contrast
- use Roboto font instead of system-ui for `docs-nav-content-btn`s - use a different background color for selected route, in addition to different text color - increase opacity of `docs-nav-content-btn`s to meet contrast guidelines - switch to `mat-nav-list` to get the benefits of better contrast and hover/focus styles - plus slightly more padding for touch interfaces Fixes #694. Relates to #671.
1 parent 51c95ff commit ae1429b

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

src/app/pages/component-sidenav/_component-sidenav-theme.scss

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
}
1818

1919
.docs-nav-content-btn {
20-
color: rgba(mat-color($foreground, text), .5);
20+
color: rgba(mat-color($foreground, text), 0.7);
21+
font-family: Roboto, "Helvetica Neue", sans-serif;
2122

2223
&:focus {
2324
// override the default background
@@ -37,6 +38,10 @@
3738
&:hover {
3839
color: mat-color($primary, if($is-dark-theme, 200, default));
3940
}
41+
42+
&.docs-component-viewer-sidenav-item-selected {
43+
background: rgba(0, 0, 0, $nav-background-focus-opacity);
44+
}
4045
}
4146
}
4247

src/app/pages/component-sidenav/component-nav.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
{{category.name}}
1010
<mat-icon>{{panel.expanded ? 'keyboard_arrow_up' : 'keyboard_arrow_down'}}</mat-icon>
1111
</button>
12-
<ul [@bodyExpansion]="panel.expanded ? 'expanded' : 'collapsed'" id="panel-{{category.id}}">
13-
<li *ngFor="let component of category.items">
14-
<a [routerLink]="'/' + (params | async)?.section+ '/' + component.id"
15-
routerLinkActive="docs-component-viewer-sidenav-item-selected">
16-
{{component.name}}
17-
</a>
18-
</li>
19-
</ul>
12+
<mat-nav-list dense [@bodyExpansion]="panel.expanded ? 'expanded' : 'collapsed'" id="panel-{{category.id}}">
13+
<a mat-list-item *ngFor="let component of category.items"
14+
[routerLink]="'/' + (params | async)?.section+ '/' + component.id"
15+
routerLinkActive="docs-component-viewer-sidenav-item-selected"
16+
[attr.aria-current]="currentItemId === component.id ? 'page': 'false'">
17+
{{component.name}}
18+
</a>
19+
</mat-nav-list>
2020
<hr *ngIf="!last" />
2121
</nav>
2222
</div>

src/app/pages/component-sidenav/component-sidenav.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import {HttpClientModule} from '@angular/common/http';
3737
import {StackBlitzButtonModule} from '../../shared/stack-blitz';
3838
import {SvgViewerModule} from '../../shared/svg-viewer/svg-viewer';
3939
import {ExampleModule} from '@angular/components-examples';
40+
import {MatListModule} from '@angular/material/list';
4041

4142
const SMALL_WIDTH_BREAKPOINT = 720;
4243

@@ -81,6 +82,7 @@ export class ComponentSidenav implements OnInit {
8182
export class ComponentNav implements OnInit, OnDestroy {
8283
@Input() params: Observable<Params>;
8384
expansions: {[key: string]: boolean} = {};
85+
currentItemId: string;
8486
private _onDestroy = new Subject<void>();
8587

8688
constructor(public docItems: DocumentationItems,
@@ -91,7 +93,7 @@ export class ComponentNav implements OnInit, OnDestroy {
9193
startWith(null),
9294
switchMap(() => this.params),
9395
takeUntil(this._onDestroy)
94-
).subscribe(p => this.setExpansions(p));
96+
).subscribe(params => this.setExpansions(params));
9597
}
9698

9799
ngOnDestroy() {
@@ -103,14 +105,12 @@ export class ComponentNav implements OnInit, OnDestroy {
103105
setExpansions(params: Params) {
104106
const categories = this.docItems.getCategories(params.section);
105107
for (const category of (categories || [])) {
106-
if (this.expansions[category.id]) {
107-
continue;
108-
}
109108

110109
let match = false;
111110
for (const item of category.items) {
112111
if (this._router.url.indexOf(item.id) > -1) {
113112
match = true;
113+
this.currentItemId = item.id;
114114
break;
115115
}
116116
}
@@ -167,6 +167,9 @@ const routes: Routes = [ {
167167

168168
@NgModule({
169169
imports: [
170+
MatSidenavModule,
171+
MatListModule,
172+
RouterModule,
170173
CommonModule,
171174
ComponentCategoryListModule,
172175
ComponentHeaderModule,

0 commit comments

Comments
 (0)