@@ -129,7 +129,7 @@ describe('<md-tabs>', function () {
129
129
130
130
} ) ) ;
131
131
132
- it ( 'should select tab on space or enter' , inject ( function ( $mdConstant ) {
132
+ it ( 'should select tab on space or enter' , inject ( function ( $document , $ mdConstant) {
133
133
var tabs = setup ( '<md-tabs>' +
134
134
'<md-tab></md-tab>' +
135
135
'<md-tab></md-tab>' +
@@ -140,10 +140,15 @@ describe('<md-tabs>', function () {
140
140
triggerKeydown ( tabs . find ( 'md-tabs-canvas' ) . eq ( 0 ) , $mdConstant . KEY_CODE . RIGHT_ARROW ) ;
141
141
triggerKeydown ( tabs . find ( 'md-tabs-canvas' ) . eq ( 0 ) , $mdConstant . KEY_CODE . ENTER ) ;
142
142
expect ( tabItems . eq ( 1 ) ) . toBeActiveTab ( ) ;
143
+ expect ( tabItems . eq ( 1 ) . attr ( 'tabindex' ) ) . toBe ( '0' ) ;
143
144
144
145
triggerKeydown ( tabs . find ( 'md-tabs-canvas' ) . eq ( 0 ) , $mdConstant . KEY_CODE . LEFT_ARROW ) ;
145
146
triggerKeydown ( tabs . find ( 'md-tabs-canvas' ) . eq ( 0 ) , $mdConstant . KEY_CODE . SPACE ) ;
146
147
expect ( tabItems . eq ( 0 ) ) . toBeActiveTab ( ) ;
148
+ // Active tab should be added to the tab order as per ARIA practices.
149
+ expect ( tabItems . eq ( 0 ) . attr ( 'tabindex' ) ) . toBe ( '0' ) ;
150
+ // Deactivated tab should be removed from the tab order.
151
+ expect ( tabItems . eq ( 1 ) . attr ( 'tabindex' ) ) . toBe ( '-1' ) ;
147
152
} ) ) ;
148
153
149
154
it ( 'should bind to selected' , function ( ) {
@@ -157,14 +162,11 @@ describe('<md-tabs>', function () {
157
162
158
163
expect ( tabItems . eq ( 0 ) ) . toBeActiveTab ( ) ;
159
164
expect ( tabs . scope ( ) . current ) . toBe ( 0 ) ;
160
- expect ( dummyTabs . eq ( 0 ) . attr ( 'aria-selected' ) ) . toBe ( 'true' ) ;
161
165
162
166
tabs . scope ( ) . $apply ( 'current = 1' ) ;
163
167
expect ( tabItems . eq ( 1 ) ) . toBeActiveTab ( ) ;
164
168
165
169
expect ( tabItems . eq ( 0 ) . attr ( 'aria-selected' ) ) . toBe ( 'false' ) ;
166
- expect ( dummyTabs . eq ( 0 ) . attr ( 'aria-selected' ) ) . toBe ( 'false' ) ;
167
- expect ( dummyTabs . eq ( 1 ) . attr ( 'aria-selected' ) ) . toBe ( 'true' ) ;
168
170
169
171
tabItems . eq ( 2 ) . triggerHandler ( 'click' ) ;
170
172
expect ( tabs . scope ( ) . current ) . toBe ( 2 ) ;
@@ -176,28 +178,40 @@ describe('<md-tabs>', function () {
176
178
'<md-tab ng-disabled="disabled1"></md-tab>' +
177
179
'</md-tabs>' ) ;
178
180
var tabItems = tabs . find ( 'md-tab-item' ) ;
179
- var dummyTabs = tabs . find ( 'md-dummy-tab' ) ;
180
181
181
182
expect ( tabItems . eq ( 0 ) ) . toBeActiveTab ( ) ;
182
- expect ( dummyTabs . eq ( 0 ) . attr ( 'aria-selected' ) ) . toBe ( 'true' ) ;
183
+ expect ( tabItems . eq ( 0 ) . attr ( 'aria-selected' ) ) . toBe ( 'true' ) ;
183
184
184
185
tabs . scope ( ) . $apply ( 'disabled0 = true' ) ;
185
186
expect ( tabItems . eq ( 1 ) ) . toBeActiveTab ( ) ;
186
187
187
188
expect ( tabItems . eq ( 0 ) . attr ( 'aria-disabled' ) ) . toBe ( 'true' ) ;
188
- expect ( dummyTabs . eq ( 0 ) . attr ( 'aria-disabled' ) ) . toBe ( 'true' ) ;
189
189
expect ( tabItems . eq ( 1 ) . attr ( 'aria-disabled' ) ) . toBe ( 'false' ) ;
190
- expect ( dummyTabs . eq ( 1 ) . attr ( 'aria-disabled' ) ) . toBe ( 'false' ) ;
191
190
192
191
tabs . scope ( ) . $apply ( 'disabled0 = false; disabled1 = true' ) ;
193
192
expect ( tabItems . eq ( 0 ) ) . toBeActiveTab ( ) ;
194
193
195
194
expect ( tabItems . eq ( 0 ) . attr ( 'aria-disabled' ) ) . toBe ( 'false' ) ;
196
- expect ( dummyTabs . eq ( 0 ) . attr ( 'aria-disabled' ) ) . toBe ( 'false' ) ;
197
195
expect ( tabItems . eq ( 1 ) . attr ( 'aria-disabled' ) ) . toBe ( 'true' ) ;
198
- expect ( dummyTabs . eq ( 1 ) . attr ( 'aria-disabled' ) ) . toBe ( 'true' ) ;
199
196
} ) ;
200
197
198
+ it ( 'should reconcile focused and active tabs' , inject ( function ( $mdConstant ) {
199
+ var tabs = setup ( '<md-tabs>' +
200
+ '<md-tab label="super label"></md-tab>' +
201
+ '<md-tab label="super label two"></md-tab>' +
202
+ '</md-tabs>' +
203
+ '<div tabindex="0">Focusable element</div>' ) ;
204
+ var ctrl = tabs . controller ( 'mdTabs' ) ;
205
+ var tabItems = tabs . find ( 'md-tab-item' ) ;
206
+ triggerKeydown ( tabs . find ( 'md-tabs-canvas' ) . eq ( 0 ) , $mdConstant . KEY_CODE . RIGHT_ARROW ) ;
207
+ expect ( tabItems . eq ( 0 ) ) . toBeActiveTab ( ) ;
208
+ expect ( ctrl . getFocusedTabId ( ) ) . toBe ( tabItems . eq ( 1 ) . attr ( 'id' ) ) ;
209
+
210
+ triggerKeydown ( tabs . find ( 'md-tabs-canvas' ) . eq ( 0 ) , $mdConstant . KEY_CODE . TAB ) ;
211
+ expect ( tabItems . eq ( 0 ) ) . toBeActiveTab ( ) ;
212
+ expect ( ctrl . getFocusedTabId ( ) ) . toBe ( tabItems . eq ( 0 ) . attr ( 'id' ) ) ;
213
+ } ) ) ;
214
+
201
215
} ) ;
202
216
203
217
describe ( 'tab label & content DOM' , function ( ) {
@@ -353,12 +367,12 @@ describe('<md-tabs>', function () {
353
367
var tabs = setup ( '<md-tabs>' +
354
368
'<md-tab label="label!">content!</md-tab>' +
355
369
'</md-tabs>' ) ;
356
- var tabItem = tabs . find ( 'md-dummy- tab' ) ;
370
+ var tabItem = tabs . find ( 'md-tab-item ' ) ;
357
371
var tabContent = angular . element ( tabs [ 0 ] . querySelector ( 'md-tab-content' ) ) ;
358
372
359
373
$timeout . flush ( ) ;
360
374
361
- expect ( tabs . find ( 'md-tabs-canvas ' ) . attr ( 'role' ) ) . toBe ( 'tablist' ) ;
375
+ expect ( tabs . find ( 'md-pagination-wrapper ' ) . attr ( 'role' ) ) . toBe ( 'tablist' ) ;
362
376
363
377
expect ( tabItem . attr ( 'id' ) ) . toBeTruthy ( ) ;
364
378
expect ( tabItem . attr ( 'aria-controls' ) ) . toBe ( tabContent . attr ( 'id' ) ) ;
0 commit comments