@@ -74,35 +74,32 @@ describe('MatTabHeader', () => {
74
74
expect ( appComponent . tabHeader . focusIndex ) . toBe ( 2 ) ;
75
75
} ) ;
76
76
77
- it ( 'should not set focus a disabled tab' , ( ) => {
77
+ it ( 'should be able to focus a disabled tab' , ( ) => {
78
78
appComponent . tabHeader . focusIndex = 0 ;
79
79
fixture . detectChanges ( ) ;
80
80
expect ( appComponent . tabHeader . focusIndex ) . toBe ( 0 ) ;
81
81
82
- // Set focus on the disabled tab, but focus should remain 0
83
82
appComponent . tabHeader . focusIndex = appComponent . disabledTabIndex ;
84
83
fixture . detectChanges ( ) ;
85
- expect ( appComponent . tabHeader . focusIndex ) . toBe ( 0 ) ;
84
+ expect ( appComponent . tabHeader . focusIndex ) . toBe ( appComponent . disabledTabIndex ) ;
86
85
} ) ;
87
86
88
- it ( 'should move focus right and skip disabled tabs' , ( ) => {
87
+ it ( 'should move focus right including over disabled tabs' , ( ) => {
89
88
appComponent . tabHeader . focusIndex = 0 ;
90
89
fixture . detectChanges ( ) ;
91
90
expect ( appComponent . tabHeader . focusIndex ) . toBe ( 0 ) ;
92
91
93
- // Move focus right, verify that the disabled tab is 1 and should be skipped
94
92
expect ( appComponent . disabledTabIndex ) . toBe ( 1 ) ;
95
93
dispatchKeyboardEvent ( tabListContainer , 'keydown' , RIGHT_ARROW ) ;
96
94
fixture . detectChanges ( ) ;
97
- expect ( appComponent . tabHeader . focusIndex ) . toBe ( 2 ) ;
95
+ expect ( appComponent . tabHeader . focusIndex ) . toBe ( 1 ) ;
98
96
99
- // Move focus right to index 3
100
97
dispatchKeyboardEvent ( tabListContainer , 'keydown' , RIGHT_ARROW ) ;
101
98
fixture . detectChanges ( ) ;
102
- expect ( appComponent . tabHeader . focusIndex ) . toBe ( 3 ) ;
99
+ expect ( appComponent . tabHeader . focusIndex ) . toBe ( 2 ) ;
103
100
} ) ;
104
101
105
- it ( 'should move focus left and skip disabled tabs' , ( ) => {
102
+ it ( 'should move focus left including over disabled tabs' , ( ) => {
106
103
appComponent . tabHeader . focusIndex = 3 ;
107
104
fixture . detectChanges ( ) ;
108
105
expect ( appComponent . tabHeader . focusIndex ) . toBe ( 3 ) ;
@@ -112,31 +109,47 @@ describe('MatTabHeader', () => {
112
109
fixture . detectChanges ( ) ;
113
110
expect ( appComponent . tabHeader . focusIndex ) . toBe ( 2 ) ;
114
111
115
- // Move focus left, verify that the disabled tab is 1 and should be skipped
116
112
expect ( appComponent . disabledTabIndex ) . toBe ( 1 ) ;
117
113
dispatchKeyboardEvent ( tabListContainer , 'keydown' , LEFT_ARROW ) ;
118
114
fixture . detectChanges ( ) ;
119
- expect ( appComponent . tabHeader . focusIndex ) . toBe ( 0 ) ;
115
+ expect ( appComponent . tabHeader . focusIndex ) . toBe ( 1 ) ;
120
116
} ) ;
121
117
122
118
it ( 'should support key down events to move and select focus' , ( ) => {
123
119
appComponent . tabHeader . focusIndex = 0 ;
124
120
fixture . detectChanges ( ) ;
125
121
expect ( appComponent . tabHeader . focusIndex ) . toBe ( 0 ) ;
126
122
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
+
127
135
// Move focus right to 2
128
136
dispatchKeyboardEvent ( tabListContainer , 'keydown' , RIGHT_ARROW ) ;
129
137
fixture . detectChanges ( ) ;
130
138
expect ( appComponent . tabHeader . focusIndex ) . toBe ( 2 ) ;
131
139
132
- // Select the focused index 2
140
+ // Select 2 which is enabled.
133
141
expect ( appComponent . selectedIndex ) . toBe ( 0 ) ;
134
- const enterEvent = dispatchKeyboardEvent ( tabListContainer , 'keydown' , ENTER ) ;
142
+ const secondEnterEvent = dispatchKeyboardEvent ( tabListContainer , 'keydown' , ENTER ) ;
135
143
fixture . detectChanges ( ) ;
136
144
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 ) ;
138
151
139
- // Move focus right to 0
152
+ // Move again to 0
140
153
dispatchKeyboardEvent ( tabListContainer , 'keydown' , LEFT_ARROW ) ;
141
154
fixture . detectChanges ( ) ;
142
155
expect ( appComponent . tabHeader . focusIndex ) . toBe ( 0 ) ;
@@ -174,7 +187,7 @@ describe('MatTabHeader', () => {
174
187
expect ( event . defaultPrevented ) . toBe ( true ) ;
175
188
} ) ;
176
189
177
- it ( 'should skip disabled items when moving focus using HOME' , ( ) => {
190
+ it ( 'should focus disabled items when moving focus using HOME' , ( ) => {
178
191
appComponent . tabHeader . focusIndex = 3 ;
179
192
appComponent . tabs [ 0 ] . disabled = true ;
180
193
fixture . detectChanges ( ) ;
@@ -183,8 +196,7 @@ describe('MatTabHeader', () => {
183
196
dispatchKeyboardEvent ( tabListContainer , 'keydown' , HOME ) ;
184
197
fixture . detectChanges ( ) ;
185
198
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 ) ;
188
200
} ) ;
189
201
190
202
it ( 'should move focus to the last tab when pressing END' , ( ) => {
@@ -199,7 +211,7 @@ describe('MatTabHeader', () => {
199
211
expect ( event . defaultPrevented ) . toBe ( true ) ;
200
212
} ) ;
201
213
202
- it ( 'should skip disabled items when moving focus using END' , ( ) => {
214
+ it ( 'should focus disabled items when moving focus using END' , ( ) => {
203
215
appComponent . tabHeader . focusIndex = 0 ;
204
216
appComponent . tabs [ 3 ] . disabled = true ;
205
217
fixture . detectChanges ( ) ;
@@ -208,7 +220,7 @@ describe('MatTabHeader', () => {
208
220
dispatchKeyboardEvent ( tabListContainer , 'keydown' , END ) ;
209
221
fixture . detectChanges ( ) ;
210
222
211
- expect ( appComponent . tabHeader . focusIndex ) . toBe ( 2 ) ;
223
+ expect ( appComponent . tabHeader . focusIndex ) . toBe ( 3 ) ;
212
224
} ) ;
213
225
214
226
it ( 'should not do anything if a modifier key is pressed' , ( ) => {
0 commit comments