File tree Expand file tree Collapse file tree 4 files changed +13
-21
lines changed Expand file tree Collapse file tree 4 files changed +13
-21
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ <h1>Tab Nav Bar</h1>
14
14
[active] ="rla.isActive ">
15
15
{{tabLink.label}}
16
16
</ a >
17
- < a mat-tab-link disabled > Disabled Link</ a >
17
+ < a routerLink =" foggy-tab " mat-tab-link disabled > Disabled Link</ a >
18
18
</ nav >
19
19
< router-outlet > </ router-outlet >
20
20
</ div >
@@ -308,5 +308,5 @@ <h1>Lazy Loaded Tabs</h1>
308
308
</ mat-tab >
309
309
< mat-tab label ="Third ">
310
310
< counter > </ counter >
311
- </ mat-tab >
311
+ </ mat-tab >
312
312
</ mat-tab-group >
Original file line number Diff line number Diff line change 17
17
text-decoration : none ; // Removes anchor underline styling
18
18
position : relative ;
19
19
overflow : hidden ; // Keeps the ripple from extending outside the element bounds
20
+
21
+ & .mat-tab-disabled {
22
+ // We use `pointer-events` to make the element unclickable when it's disabled, rather than
23
+ // preventing the default action through JS, because we can't prevent the action reliably
24
+ // due to other directives potentially registering their events earlier. This shouldn't cause
25
+ // the user to click through, because we always have a `.mat-tab-links` behind the link.
26
+ pointer-events : none ;
27
+ }
20
28
}
21
29
22
30
@media ($mat-xsmall ) {
Original file line number Diff line number Diff line change @@ -125,21 +125,15 @@ describe('MatTabNavBar', () => {
125
125
. toBe ( true , 'Expected element to no longer be keyboard focusable if disabled.' ) ;
126
126
} ) ;
127
127
128
- it ( 'should prevent default action for clicks if links are disabled ' , ( ) => {
128
+ it ( 'should make disabled links unclickable ' , ( ) => {
129
129
const tabLinkElement = fixture . debugElement . query ( By . css ( 'a' ) ) . nativeElement ;
130
130
131
- const mouseEvent = createMouseEvent ( 'click' ) ;
132
- spyOn ( mouseEvent , 'preventDefault' ) ;
133
- tabLinkElement . dispatchEvent ( mouseEvent ) ;
134
- expect ( mouseEvent . preventDefault ) . not . toHaveBeenCalled ( ) ;
131
+ expect ( getComputedStyle ( tabLinkElement ) . pointerEvents ) . not . toBe ( 'none' ) ;
135
132
136
133
fixture . componentInstance . disabled = true ;
137
134
fixture . detectChanges ( ) ;
138
135
139
- const mouseEventWhileDisabled = createMouseEvent ( 'click' ) ;
140
- spyOn ( mouseEventWhileDisabled , 'preventDefault' ) ;
141
- tabLinkElement . dispatchEvent ( mouseEventWhileDisabled ) ;
142
- expect ( mouseEventWhileDisabled . preventDefault ) . toHaveBeenCalled ( ) ;
136
+ expect ( getComputedStyle ( tabLinkElement ) . pointerEvents ) . toBe ( 'none' ) ;
143
137
} ) ;
144
138
145
139
it ( 'should show ripples for tab links' , ( ) => {
Original file line number Diff line number Diff line change @@ -188,7 +188,6 @@ export const _MatTabLinkMixinBase =
188
188
'[attr.tabIndex]' : 'tabIndex' ,
189
189
'[class.mat-tab-disabled]' : 'disabled' ,
190
190
'[class.mat-tab-label-active]' : 'active' ,
191
- '(click)' : '_handleClick($event)'
192
191
}
193
192
} )
194
193
export class MatTabLink extends _MatTabLinkMixinBase
@@ -249,13 +248,4 @@ export class MatTabLink extends _MatTabLinkMixinBase
249
248
ngOnDestroy ( ) {
250
249
this . _tabLinkRipple . _removeTriggerEvents ( ) ;
251
250
}
252
-
253
- /**
254
- * Handles the click event, preventing default navigation if the tab link is disabled.
255
- */
256
- _handleClick ( event : MouseEvent ) {
257
- if ( this . disabled ) {
258
- event . preventDefault ( ) ;
259
- }
260
- }
261
251
}
You can’t perform that action at this time.
0 commit comments