@@ -4,14 +4,12 @@ import {
44 Input ,
55 HostListener ,
66 ViewChild ,
7- AfterViewInit ,
87 ContentChildren ,
9- AfterContentInit
8+ AfterContentInit ,
9+ ViewChildren ,
10+ ElementRef
1011} from "@angular/core" ;
1112
12- import { fromEvent } from "rxjs" ;
13- import { throttleTime } from "rxjs/operators" ;
14-
1513import { Tab } from "./tab.component" ;
1614
1715
@@ -61,6 +59,7 @@ import { Tab } from "./tab.component";
6159 role="presentation"
6260 (click)="selectTab(tabref, tab, i)">
6361 <a
62+ #tabItem
6463 [attr.aria-selected]="tab.active"
6564 [attr.tabindex]="(tab.active?0:-1)"
6665 [attr.aria-controls]="tab.id"
@@ -88,24 +87,20 @@ import { Tab } from "./tab.component";
8887 `
8988} )
9089
91- export class TabHeaders implements AfterViewInit , AfterContentInit {
90+ export class TabHeaders implements AfterContentInit {
9291 /**
9392 * List of `Tab` components.
94- * @type {QueryList<Tab> }
95- * @memberof TabHeaders
9693 */
9794 // disable the next line because we need to rename the input
9895 // tslint:disable-next-line
9996 @Input ( "tabs" ) tabInput : QueryList < Tab > ;
10097 /**
10198 * Set to 'true' to have `Tab` items cached and not reloaded on tab switching.
10299 * Duplicate from `n-tabs` to support standalone headers
103- * @memberof Tabs
104100 */
105101 @Input ( ) cacheActive = false ;
106102 /**
107103 * Set to 'true' to have tabs automatically activated and have their content displayed when they receive focus.
108- * @memberof TabHeaders
109104 */
110105 @Input ( ) followFocus : boolean ;
111106 /**
@@ -115,7 +110,6 @@ export class TabHeaders implements AfterViewInit, AfterContentInit {
115110
116111 /**
117112 * Gets the Unordered List element that holds the `Tab` headings from the view DOM.
118- * @memberof TabHeaders
119113 */
120114 @ViewChild ( "tabList" ) headerContainer ;
121115 /**
@@ -128,26 +122,21 @@ export class TabHeaders implements AfterViewInit, AfterContentInit {
128122 public tabs : QueryList < Tab > ;
129123 /**
130124 * The index of the first visible tab.
131- * @memberof TabHeaders
132125 */
133126 public firstVisibleTab = 0 ;
134127 /**
135128 * The DOM element containing the `Tab` headings displayed.
136- * @memberof TabHeaders
137129 */
138- public allTabHeaders ;
130+ @ ViewChildren ( "tabItem" ) allTabHeaders : QueryList < ElementRef > ;
139131 /**
140132 * Controls the manual focusing done by tabbing through headings.
141- * @memberof TabHeaders
142133 */
143134 public currentSelectedTab : number ;
144135 public tabListVisible = false ;
145136
146137 // keyboard accessibility
147138 /**
148139 * Controls the keydown events used for tabbing through the headings.
149- * @param {any } event
150- * @memberof TabHeaders
151140 */
152141 @HostListener ( "keydown" , [ "$event" ] )
153142 keyboardInput ( event ) {
@@ -160,13 +149,13 @@ export class TabHeaders implements AfterViewInit, AfterContentInit {
160149 if ( this . followFocus ) {
161150 this . selectTab ( event . target , tabsArray [ this . currentSelectedTab + 1 ] , this . currentSelectedTab ) ;
162151 }
163- this . allTabHeaders [ this . currentSelectedTab + 1 ] . focus ( ) ;
152+ this . allTabHeaders . toArray ( ) [ this . currentSelectedTab + 1 ] . nativeElement . focus ( ) ;
164153 } else {
165154 event . preventDefault ( ) ;
166155 if ( this . followFocus ) {
167156 this . selectTab ( event . target , tabsArray [ 0 ] , 0 ) ;
168157 }
169- this . allTabHeaders [ 0 ] . focus ( ) ;
158+ this . allTabHeaders . first . nativeElement . focus ( ) ;
170159 }
171160 }
172161
@@ -177,13 +166,13 @@ export class TabHeaders implements AfterViewInit, AfterContentInit {
177166 if ( this . followFocus ) {
178167 this . selectTab ( event . target , tabsArray [ this . currentSelectedTab - 1 ] , this . currentSelectedTab ) ;
179168 }
180- this . allTabHeaders [ this . currentSelectedTab - 1 ] . focus ( ) ;
169+ this . allTabHeaders . toArray ( ) [ this . currentSelectedTab - 1 ] . nativeElement . focus ( ) ;
181170 } else {
182171 event . preventDefault ( ) ;
183172 if ( this . followFocus ) {
184173 this . selectTab ( event . target , tabsArray [ this . allTabHeaders . length - 1 ] , this . allTabHeaders . length ) ;
185174 }
186- this . allTabHeaders [ this . allTabHeaders . length - 1 ] . focus ( ) ;
175+ this . allTabHeaders . toArray ( ) [ this . allTabHeaders . length - 1 ] . nativeElement . focus ( ) ;
187176 }
188177 }
189178
@@ -192,15 +181,15 @@ export class TabHeaders implements AfterViewInit, AfterContentInit {
192181 if ( this . followFocus ) {
193182 this . selectTab ( event . target , tabsArray [ 0 ] , 0 ) ;
194183 }
195- this . allTabHeaders [ 0 ] . focus ( ) ;
184+ this . allTabHeaders . toArray ( ) [ 0 ] . nativeElement . focus ( ) ;
196185 }
197186
198187 if ( event . key === "End" ) {
199188 event . preventDefault ( ) ;
200189 if ( this . followFocus ) {
201190 this . selectTab ( event . target , tabsArray [ this . allTabHeaders . length - 1 ] , this . allTabHeaders . length ) ;
202191 }
203- this . allTabHeaders [ this . allTabHeaders . length - 1 ] . focus ( ) ;
192+ this . allTabHeaders . toArray ( ) [ this . allTabHeaders . length - 1 ] . nativeElement . focus ( ) ;
204193 }
205194
206195 // `"Spacebar"` is IE11 specific value
@@ -219,25 +208,12 @@ export class TabHeaders implements AfterViewInit, AfterContentInit {
219208 this . tabs . forEach ( tab => tab . cacheActive = this . cacheActive ) ;
220209 this . tabs . changes . subscribe ( ( ) => {
221210 this . setFirstTab ( ) ;
222- // also update the tab headers list
223- this . allTabHeaders = this . headerContainer . nativeElement . querySelectorAll ( "li a" ) ;
224211 } ) ;
225212 this . setFirstTab ( ) ;
226213 }
227214
228- /**
229- * Performs check to see if there is overflow and needs scrolling.
230- * @memberof TabHeaders
231- */
232- ngAfterViewInit ( ) {
233- this . allTabHeaders = this . headerContainer . nativeElement . querySelectorAll ( "li a" ) ;
234- }
235-
236215 /**
237216 * Controls manually focusing tabs.
238- * @param {HTMLElement } ref
239- * @param {number } index
240- * @memberof TabHeaders
241217 */
242218 public onTabFocus ( ref : HTMLElement , index : number ) {
243219 this . currentSelectedTab = index ;
@@ -259,10 +235,6 @@ export class TabHeaders implements AfterViewInit, AfterContentInit {
259235
260236 /**
261237 * Selects `Tab` 'tab' and moves it into view on the view DOM if it is not already.
262- * @param ref
263- * @param tab
264- * @param tabIndex
265- * @memberof TabHeaders
266238 */
267239 public selectTab ( ref : HTMLElement , tab : Tab , tabIndex : number ) {
268240 if ( tab . disabled ) {
@@ -279,8 +251,6 @@ export class TabHeaders implements AfterViewInit, AfterContentInit {
279251
280252 /**
281253 * Determines which `Tab` is initially selected.
282- * @protected
283- * @memberof Tabs
284254 */
285255 protected setFirstTab ( ) {
286256 setTimeout ( ( ) => {
0 commit comments