@@ -97,6 +97,12 @@ export class TabHeaders implements AfterViewInit, AfterContentInit {
9797 * @memberof Tabs
9898 */
9999 @Input ( ) cacheActive = false ;
100+ /**
101+ * Set to 'true' to have tabs automatically activated and have their content displayed when they recieve focus.
102+ * @memberof TabHeaders
103+ */
104+ @Input ( ) automaticActivation : boolean ;
105+
100106 /**
101107 * Gets the Unordered List element that holds the `Tab` headings from the view DOM.
102108 * @memberof TabHeaders
@@ -135,39 +141,58 @@ export class TabHeaders implements AfterViewInit, AfterContentInit {
135141 */
136142 @HostListener ( "keydown" , [ "$event" ] )
137143 keyboardInput ( event ) {
144+ let tabsArray = Array . from < any > ( this . tabs ) ;
145+
138146 if ( event . key === "Right" || event . key === "ArrowRight" ) {
139147 if ( this . currentSelectedTab < this . allTabHeaders . length - 1 ) {
140148 event . preventDefault ( ) ;
149+ if ( this . automaticActivation ) {
150+ this . selectTab ( event . target , tabsArray [ this . currentSelectedTab + 1 ] , this . currentSelectedTab ) ;
151+ }
141152 this . allTabHeaders [ this . currentSelectedTab + 1 ] . focus ( ) ;
142153 } else {
143154 event . preventDefault ( ) ;
155+ if ( this . automaticActivation ) {
156+ this . selectTab ( event . target , tabsArray [ 0 ] , 0 ) ;
157+ }
144158 this . allTabHeaders [ 0 ] . focus ( ) ;
145159 }
146160 }
147161
148162 if ( event . key === "Left" || event . key === "ArrowLeft" ) {
149163 if ( this . currentSelectedTab > 0 ) {
150164 event . preventDefault ( ) ;
165+ if ( this . automaticActivation ) {
166+ this . selectTab ( event . target , tabsArray [ this . currentSelectedTab - 1 ] , this . currentSelectedTab ) ;
167+ }
151168 this . allTabHeaders [ this . currentSelectedTab - 1 ] . focus ( ) ;
152169 } else {
153170 event . preventDefault ( ) ;
171+ if ( this . automaticActivation ) {
172+ this . selectTab ( event . target , tabsArray [ this . allTabHeaders . length - 1 ] , this . allTabHeaders . length ) ;
173+ }
154174 this . allTabHeaders [ this . allTabHeaders . length - 1 ] . focus ( ) ;
155175 }
156176 }
157177
158178 if ( event . key === "Home" ) {
159179 event . preventDefault ( ) ;
180+ if ( this . automaticActivation ) {
181+ this . selectTab ( event . target , tabsArray [ 0 ] , 0 ) ;
182+ }
160183 this . allTabHeaders [ 0 ] . focus ( ) ;
161184 }
162185
163186 if ( event . key === "End" ) {
164187 event . preventDefault ( ) ;
188+ if ( this . automaticActivation ) {
189+ this . selectTab ( event . target , tabsArray [ this . allTabHeaders . length - 1 ] , this . allTabHeaders . length ) ;
190+ }
165191 this . allTabHeaders [ this . allTabHeaders . length - 1 ] . focus ( ) ;
166192 }
167193
168- if ( event . key === " " ) {
169- let selectedTab = Array . from < any > ( this . tabInput ) ;
170- this . selectTab ( event . target , selectedTab [ this . currentSelectedTab ] , this . currentSelectedTab ) ;
194+ if ( event . key === " " && ! this . automaticActivation ) {
195+ this . selectTab ( event . target , tabsArray [ this . currentSelectedTab ] , this . currentSelectedTab ) ;
171196 }
172197 }
173198
0 commit comments