1
1
import { Component , ElementRef , ViewChild , ViewEncapsulation } from '@angular/core' ;
2
+ import { NavigationEnd , Router } from '@angular/router' ;
2
3
3
4
@Component ( {
4
5
moduleId : module . id ,
@@ -15,7 +16,10 @@ export class AccessibilityHome {}
15
16
encapsulation : ViewEncapsulation . None ,
16
17
} )
17
18
export class AccessibilityDemo {
19
+ currentComponent : string = '' ;
20
+
18
21
@ViewChild ( 'maincontent' ) mainContent : ElementRef ;
22
+ @ViewChild ( 'header' ) sectionHeader : ElementRef ;
19
23
20
24
navItems = [
21
25
{ name : 'Home' , route : '.' } ,
@@ -43,8 +47,17 @@ export class AccessibilityDemo {
43
47
{ name : 'Tooltip' , route : 'tooltip' } ,
44
48
] ;
45
49
50
+ constructor ( private router : Router ) {
51
+ router . events . subscribe ( event => {
52
+ let nav = this . navItems . find ( navItem => {
53
+ let fragments = ( event as NavigationEnd ) . url . split ( '/' ) ;
54
+ return fragments [ fragments . length - 1 ] === navItem . route ;
55
+ } ) ;
56
+ this . currentComponent = nav ? nav . name : '' ;
57
+ } ) ;
58
+ }
59
+
46
60
skipNavigation ( ) {
47
- this . mainContent . nativeElement . scrollIntoView ( ) ;
48
- this . mainContent . nativeElement . focus ( ) ;
61
+ ( this . currentComponent ? this . sectionHeader : this . mainContent ) . nativeElement . focus ( ) ;
49
62
}
50
63
}
0 commit comments