File tree Expand file tree Collapse file tree 3 files changed +30
-2
lines changed
material-experimental/mdc-tabs Expand file tree Collapse file tree 3 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -148,6 +148,19 @@ describe('MDC-based MatTabHeader', () => {
148
148
expect ( spaceEvent . defaultPrevented ) . toBe ( true ) ;
149
149
} ) ;
150
150
151
+ it ( 'should not prevent the default space/enter action if the current is selected' , ( ) => {
152
+ appComponent . tabHeader . focusIndex = appComponent . tabHeader . selectedIndex = 0 ;
153
+ fixture . detectChanges ( ) ;
154
+
155
+ const spaceEvent = dispatchKeyboardEvent ( tabListContainer , 'keydown' , SPACE ) ;
156
+ fixture . detectChanges ( ) ;
157
+ expect ( spaceEvent . defaultPrevented ) . toBe ( false ) ;
158
+
159
+ const enterEvent = dispatchKeyboardEvent ( tabListContainer , 'keydown' , ENTER ) ;
160
+ fixture . detectChanges ( ) ;
161
+ expect ( enterEvent . defaultPrevented ) . toBe ( false ) ;
162
+ } ) ;
163
+
151
164
it ( 'should move focus to the first tab when pressing HOME' , ( ) => {
152
165
appComponent . tabHeader . focusIndex = 3 ;
153
166
fixture . detectChanges ( ) ;
Original file line number Diff line number Diff line change @@ -269,8 +269,10 @@ export abstract class MatPaginatedTabHeader implements AfterContentChecked, Afte
269
269
break ;
270
270
case ENTER :
271
271
case SPACE :
272
- this . selectFocusedIndex . emit ( this . focusIndex ) ;
273
- this . _itemSelected ( event ) ;
272
+ if ( this . focusIndex !== this . selectedIndex ) {
273
+ this . selectFocusedIndex . emit ( this . focusIndex ) ;
274
+ this . _itemSelected ( event ) ;
275
+ }
274
276
break ;
275
277
default :
276
278
this . _keyManager . onKeydown ( event ) ;
Original file line number Diff line number Diff line change @@ -150,6 +150,19 @@ describe('MatTabHeader', () => {
150
150
expect ( spaceEvent . defaultPrevented ) . toBe ( true ) ;
151
151
} ) ;
152
152
153
+ it ( 'should not prevent the default space/enter action if the current is selected' , ( ) => {
154
+ appComponent . tabHeader . focusIndex = appComponent . tabHeader . selectedIndex = 0 ;
155
+ fixture . detectChanges ( ) ;
156
+
157
+ const spaceEvent = dispatchKeyboardEvent ( tabListContainer , 'keydown' , SPACE ) ;
158
+ fixture . detectChanges ( ) ;
159
+ expect ( spaceEvent . defaultPrevented ) . toBe ( false ) ;
160
+
161
+ const enterEvent = dispatchKeyboardEvent ( tabListContainer , 'keydown' , ENTER ) ;
162
+ fixture . detectChanges ( ) ;
163
+ expect ( enterEvent . defaultPrevented ) . toBe ( false ) ;
164
+ } ) ;
165
+
153
166
it ( 'should move focus to the first tab when pressing HOME' , ( ) => {
154
167
appComponent . tabHeader . focusIndex = 3 ;
155
168
fixture . detectChanges ( ) ;
You can’t perform that action at this time.
0 commit comments