Skip to content

Commit d08c3c4

Browse files
committed
some cleanup
1 parent e498af3 commit d08c3c4

File tree

6 files changed

+50
-18
lines changed

6 files changed

+50
-18
lines changed

src/demo-app/a11y/a11y.html

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
<h1>Accessibility Demo</h1>
1+
<ng-container *ngIf="!fullscreen">
2+
<h1>
3+
Accessibility Demo
4+
</h1>
25

3-
<nav>
4-
<a (click)="skipNavigation()" href="javascript:void(0)">Skip navigation</a>
5-
<a *ngFor="let navItem of navItems" [routerLink]="[navItem.route]" (click)="skipNavigation()">
6-
{{navItem.name}}
7-
</a>
8-
</nav>
6+
<nav>
7+
<a (click)="skipNavigation()" href="javascript:void(0)">Skip navigation</a>
8+
<a *ngFor="let navItem of navItems" [routerLink]="[navItem.route]" (click)="skipNavigation()">
9+
{{navItem.name}}
10+
</a>
11+
</nav>
12+
</ng-container>
913

1014
<div #maincontent tabindex="-1">
1115
<h1 #header tabindex="-1" *ngIf="!!currentComponent">{{currentComponent}} Demo</h1>

src/demo-app/a11y/a11y.ts

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import {Component, ElementRef, ViewChild, ViewEncapsulation} from '@angular/core';
1+
import {Component, ElementRef, OnDestroy, ViewChild, ViewEncapsulation} from '@angular/core';
22
import {NavigationEnd, Router} from '@angular/router';
3+
import {Subscription} from 'rxjs/Subscription';
34

45
@Component({
56
moduleId: module.id,
@@ -16,9 +17,13 @@ export class AccessibilityHome {}
1617
encapsulation: ViewEncapsulation.None,
1718
preserveWhitespaces: false,
1819
})
19-
export class AccessibilityDemo {
20+
export class AccessibilityDemo implements OnDestroy {
2021
currentComponent: string = '';
2122

23+
fullscreen = false;
24+
25+
private _routerSubscription = Subscription.EMPTY;
26+
2227
@ViewChild('maincontent') mainContent: ElementRef;
2328
@ViewChild('header') sectionHeader: ElementRef;
2429

@@ -51,16 +56,26 @@ export class AccessibilityDemo {
5156
];
5257

5358
constructor(router: Router) {
54-
router.events.subscribe(event => {
55-
let nav = this.navItems.find(navItem => {
56-
let fragments = (event as NavigationEnd).url.split('/');
57-
return fragments[fragments.length - 1] === navItem.route;
58-
});
59-
this.currentComponent = nav ? nav.name : '';
59+
this._routerSubscription = router.events.subscribe((e) => {
60+
if (e instanceof NavigationEnd) {
61+
let fragments = e.url.split('/');
62+
let nav = this.navItems.find(navItem => {
63+
return fragments[fragments.length - 1] === navItem.route;
64+
});
65+
this.currentComponent = nav ? nav.name : '';
66+
67+
let routerState = router.routerState.root;
68+
while (routerState.children.length) routerState = routerState.children[0];
69+
this.fullscreen = !!routerState.snapshot.data.fullscreen;
70+
}
6071
});
6172
}
6273

6374
skipNavigation() {
6475
(this.currentComponent ? this.sectionHeader : this.mainContent).nativeElement.focus();
6576
}
77+
78+
ngOnDestroy() {
79+
this._routerSubscription.unsubscribe();
80+
}
6681
}

src/demo-app/a11y/routes.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ export const ACCESSIBILITY_DEMO_ROUTES: Routes = [
4949
{path: 'radio', component: RadioAccessibilityDemo},
5050
{path: 'select', component: SelectAccessibilityDemo},
5151
{path: 'sidenav', component: SidenavAccessibilityDemo},
52-
{path: 'sidenav/basic', component: SidenavBasicAccessibilityDemo},
53-
{path: 'sidenav/dual', component: SidenavDualAccessibilityDemo},
54-
{path: 'sidenav/mobile', component: SidenavMobileAccessibilityDemo},
52+
{path: 'sidenav/basic', component: SidenavBasicAccessibilityDemo, data: {fullscreen: true}},
53+
{path: 'sidenav/dual', component: SidenavDualAccessibilityDemo, data: {fullscreen: true}},
54+
{path: 'sidenav/mobile', component: SidenavMobileAccessibilityDemo, data: {fullscreen: true}},
5555
{path: 'slide-toggle', component: SlideToggleAccessibilityDemo},
5656
{path: 'slider', component: SliderAccessibilityDemo},
5757
{path: 'snack-bar', component: SnackBarAccessibilityDemo},

src/demo-app/a11y/sidenav/mobile-sidenav-a11y.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ <h1 class="a11y-demo-sidenav-app-name">Responsive Sidenav App</h1>
88

99
<md-sidenav-container
1010
class="a11y-demo-sidenav-container"
11+
[class.a11y-demo-sidenav-container-fixed]="mobileQuery.matches"
1112
[style.marginTop.px]="mobileQuery.matches ? 56 : 0">
1213
<md-sidenav
1314
#snav
@@ -20,12 +21,14 @@ <h1 class="a11y-demo-sidenav-app-name">Responsive Sidenav App</h1>
2021
<a md-list-item routerLink="../mobile">Responsive sidenav example</a>
2122
<a md-list-item routerLink="../dual">Dual sidenavs example</a>
2223
</md-nav-list>
24+
<p class="a11y-demo-sidenav-filler" *ngFor="let f of filler">Filler content</p>
2325
</md-sidenav>
2426

2527
<md-sidenav-content role="region">
2628
<button md-raised-button aria-label="Close responsive sidenav example" color="primary"
2729
class="a11y-demo-sidenav-close" routerLink="..">
2830
Close example
2931
</button>
32+
<p class="a11y-demo-sidenav-filler" *ngFor="let f of filler">Filler content</p>
3033
</md-sidenav-content>
3134
</md-sidenav-container>

src/demo-app/a11y/sidenav/mobile-sidenav-a11y.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import {ChangeDetectorRef, Component, OnDestroy, ViewEncapsulation} from '@angul
1212
export class SidenavMobileAccessibilityDemo implements OnDestroy {
1313
mobileQuery = matchMedia('(max-width: 600px)');
1414

15+
filler = Array(20).fill(0);
16+
1517
_mobileQueryListener: () => void;
1618

1719
constructor(changeDetectorRef: ChangeDetectorRef) {

src/demo-app/a11y/sidenav/shared.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,18 @@
1212
flex: 1;
1313
}
1414

15+
.a11y-demo-sidenav-container-fixed {
16+
flex: none;
17+
}
18+
1519
h1.a11y-demo-sidenav-app-name {
1620
margin-left: 8px;
1721
}
1822

1923
button.a11y-demo-sidenav-close {
2024
margin: 20px;
2125
}
26+
27+
.a11y-demo-sidenav-filler {
28+
margin: 100px 20px;
29+
}

0 commit comments

Comments
 (0)