@@ -74,35 +74,32 @@ describe('MatTabHeader', () => {
7474 expect ( appComponent . tabHeader . focusIndex ) . toBe ( 2 ) ;
7575 } ) ;
7676
77- it ( 'should not set focus a disabled tab' , ( ) => {
77+ it ( 'should be able to focus a disabled tab' , ( ) => {
7878 appComponent . tabHeader . focusIndex = 0 ;
7979 fixture . detectChanges ( ) ;
8080 expect ( appComponent . tabHeader . focusIndex ) . toBe ( 0 ) ;
8181
82- // Set focus on the disabled tab, but focus should remain 0
8382 appComponent . tabHeader . focusIndex = appComponent . disabledTabIndex ;
8483 fixture . detectChanges ( ) ;
85- expect ( appComponent . tabHeader . focusIndex ) . toBe ( 0 ) ;
84+ expect ( appComponent . tabHeader . focusIndex ) . toBe ( appComponent . disabledTabIndex ) ;
8685 } ) ;
8786
88- it ( 'should move focus right and skip disabled tabs' , ( ) => {
87+ it ( 'should move focus right including over disabled tabs' , ( ) => {
8988 appComponent . tabHeader . focusIndex = 0 ;
9089 fixture . detectChanges ( ) ;
9190 expect ( appComponent . tabHeader . focusIndex ) . toBe ( 0 ) ;
9291
93- // Move focus right, verify that the disabled tab is 1 and should be skipped
9492 expect ( appComponent . disabledTabIndex ) . toBe ( 1 ) ;
9593 dispatchKeyboardEvent ( tabListContainer , 'keydown' , RIGHT_ARROW ) ;
9694 fixture . detectChanges ( ) ;
97- expect ( appComponent . tabHeader . focusIndex ) . toBe ( 2 ) ;
95+ expect ( appComponent . tabHeader . focusIndex ) . toBe ( 1 ) ;
9896
99- // Move focus right to index 3
10097 dispatchKeyboardEvent ( tabListContainer , 'keydown' , RIGHT_ARROW ) ;
10198 fixture . detectChanges ( ) ;
102- expect ( appComponent . tabHeader . focusIndex ) . toBe ( 3 ) ;
99+ expect ( appComponent . tabHeader . focusIndex ) . toBe ( 2 ) ;
103100 } ) ;
104101
105- it ( 'should move focus left and skip disabled tabs' , ( ) => {
102+ it ( 'should move focus left including over disabled tabs' , ( ) => {
106103 appComponent . tabHeader . focusIndex = 3 ;
107104 fixture . detectChanges ( ) ;
108105 expect ( appComponent . tabHeader . focusIndex ) . toBe ( 3 ) ;
@@ -112,31 +109,47 @@ describe('MatTabHeader', () => {
112109 fixture . detectChanges ( ) ;
113110 expect ( appComponent . tabHeader . focusIndex ) . toBe ( 2 ) ;
114111
115- // Move focus left, verify that the disabled tab is 1 and should be skipped
116112 expect ( appComponent . disabledTabIndex ) . toBe ( 1 ) ;
117113 dispatchKeyboardEvent ( tabListContainer , 'keydown' , LEFT_ARROW ) ;
118114 fixture . detectChanges ( ) ;
119- expect ( appComponent . tabHeader . focusIndex ) . toBe ( 0 ) ;
115+ expect ( appComponent . tabHeader . focusIndex ) . toBe ( 1 ) ;
120116 } ) ;
121117
122118 it ( 'should support key down events to move and select focus' , ( ) => {
123119 appComponent . tabHeader . focusIndex = 0 ;
124120 fixture . detectChanges ( ) ;
125121 expect ( appComponent . tabHeader . focusIndex ) . toBe ( 0 ) ;
126122
123+ // Move focus right to 1
124+ dispatchKeyboardEvent ( tabListContainer , 'keydown' , RIGHT_ARROW ) ;
125+ fixture . detectChanges ( ) ;
126+ expect ( appComponent . tabHeader . focusIndex ) . toBe ( 1 ) ;
127+
128+ // Try to select 1. Should not work since it's disabled.
129+ expect ( appComponent . selectedIndex ) . toBe ( 0 ) ;
130+ const firstEnterEvent = dispatchKeyboardEvent ( tabListContainer , 'keydown' , ENTER ) ;
131+ fixture . detectChanges ( ) ;
132+ expect ( appComponent . selectedIndex ) . toBe ( 0 ) ;
133+ expect ( firstEnterEvent . defaultPrevented ) . toBe ( false ) ;
134+
127135 // Move focus right to 2
128136 dispatchKeyboardEvent ( tabListContainer , 'keydown' , RIGHT_ARROW ) ;
129137 fixture . detectChanges ( ) ;
130138 expect ( appComponent . tabHeader . focusIndex ) . toBe ( 2 ) ;
131139
132- // Select the focused index 2
140+ // Select 2 which is enabled.
133141 expect ( appComponent . selectedIndex ) . toBe ( 0 ) ;
134- const enterEvent = dispatchKeyboardEvent ( tabListContainer , 'keydown' , ENTER ) ;
142+ const secondEnterEvent = dispatchKeyboardEvent ( tabListContainer , 'keydown' , ENTER ) ;
135143 fixture . detectChanges ( ) ;
136144 expect ( appComponent . selectedIndex ) . toBe ( 2 ) ;
137- expect ( enterEvent . defaultPrevented ) . toBe ( true ) ;
145+ expect ( secondEnterEvent . defaultPrevented ) . toBe ( true ) ;
146+
147+ // Move focus left to 1
148+ dispatchKeyboardEvent ( tabListContainer , 'keydown' , LEFT_ARROW ) ;
149+ fixture . detectChanges ( ) ;
150+ expect ( appComponent . tabHeader . focusIndex ) . toBe ( 1 ) ;
138151
139- // Move focus right to 0
152+ // Move again to 0
140153 dispatchKeyboardEvent ( tabListContainer , 'keydown' , LEFT_ARROW ) ;
141154 fixture . detectChanges ( ) ;
142155 expect ( appComponent . tabHeader . focusIndex ) . toBe ( 0 ) ;
@@ -174,7 +187,7 @@ describe('MatTabHeader', () => {
174187 expect ( event . defaultPrevented ) . toBe ( true ) ;
175188 } ) ;
176189
177- it ( 'should skip disabled items when moving focus using HOME' , ( ) => {
190+ it ( 'should focus disabled items when moving focus using HOME' , ( ) => {
178191 appComponent . tabHeader . focusIndex = 3 ;
179192 appComponent . tabs [ 0 ] . disabled = true ;
180193 fixture . detectChanges ( ) ;
@@ -183,8 +196,7 @@ describe('MatTabHeader', () => {
183196 dispatchKeyboardEvent ( tabListContainer , 'keydown' , HOME ) ;
184197 fixture . detectChanges ( ) ;
185198
186- // Note that the second tab is disabled by default already.
187- expect ( appComponent . tabHeader . focusIndex ) . toBe ( 2 ) ;
199+ expect ( appComponent . tabHeader . focusIndex ) . toBe ( 0 ) ;
188200 } ) ;
189201
190202 it ( 'should move focus to the last tab when pressing END' , ( ) => {
@@ -199,7 +211,7 @@ describe('MatTabHeader', () => {
199211 expect ( event . defaultPrevented ) . toBe ( true ) ;
200212 } ) ;
201213
202- it ( 'should skip disabled items when moving focus using END' , ( ) => {
214+ it ( 'should focus disabled items when moving focus using END' , ( ) => {
203215 appComponent . tabHeader . focusIndex = 0 ;
204216 appComponent . tabs [ 3 ] . disabled = true ;
205217 fixture . detectChanges ( ) ;
@@ -208,7 +220,7 @@ describe('MatTabHeader', () => {
208220 dispatchKeyboardEvent ( tabListContainer , 'keydown' , END ) ;
209221 fixture . detectChanges ( ) ;
210222
211- expect ( appComponent . tabHeader . focusIndex ) . toBe ( 2 ) ;
223+ expect ( appComponent . tabHeader . focusIndex ) . toBe ( 3 ) ;
212224 } ) ;
213225
214226 it ( 'should not do anything if a modifier key is pressed' , ( ) => {
0 commit comments