Skip to content

Commit 89cad3f

Browse files
crisbetommalerba
authored andcommitted
fix(tabs): don't show focus indication for mouse focus (#11194)
Similarly to other components, makes the tabs focus indication not to show for mouse focus. Fixes #11184.
1 parent 20cbdba commit 89cad3f

File tree

5 files changed

+24
-5
lines changed

5 files changed

+24
-5
lines changed

src/lib/tabs/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ ng_module(
2121
"//src/cdk/observers",
2222
"//src/cdk/portal",
2323
"//src/cdk/scrolling",
24+
"//src/cdk/a11y",
2425
"@rxjs",
2526
],
2627
tsconfig = "//src/lib:tsconfig-build.json",

src/lib/tabs/_tabs-theme.scss

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,11 @@
8383
}
8484

8585
@mixin _mat-tab-label-focus($tab-focus-color) {
86-
.mat-tab-label:not(.mat-tab-disabled):focus,
87-
.mat-tab-link:not(.mat-tab-disabled):focus {
88-
background-color: mat-color($tab-focus-color, lighter, 0.3);
86+
.mat-tab-label,
87+
.mat-tab-link {
88+
&.cdk-focused:not(.cdk-mouse-focused):not(.mat-tab-disabled) {
89+
background-color: mat-color($tab-focus-color, lighter, 0.3);
90+
}
8991
}
9092
}
9193

src/lib/tabs/tab-group.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[disableRipple]="disableRipple"
44
(indexFocused)="_focusChanged($event)"
55
(selectFocusedIndex)="selectedIndex = $event">
6-
<div class="mat-tab-label" role="tab" matTabLabelWrapper mat-ripple
6+
<div class="mat-tab-label" role="tab" matTabLabelWrapper mat-ripple cdkMonitorElementFocus
77
*ngFor="let tab of _tabs; let i = index"
88
[id]="_getTabLabelId(i)"
99
[attr.tabIndex]="_getTabIndex(tab, i)"

src/lib/tabs/tab-nav-bar/tab-nav-bar.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import {
4646
import {merge, of as observableOf, Subject} from 'rxjs';
4747
import {takeUntil} from 'rxjs/operators';
4848
import {MatInkBar} from '../ink-bar';
49+
import {FocusMonitor} from '@angular/cdk/a11y';
4950

5051

5152
// Boilerplate for applying mixins to MatTabNav.
@@ -222,7 +223,12 @@ export class MatTabLink extends _MatTabLinkMixinBase
222223
ngZone: NgZone,
223224
platform: Platform,
224225
@Optional() @Inject(MAT_RIPPLE_GLOBAL_OPTIONS) globalOptions: RippleGlobalOptions,
225-
@Attribute('tabindex') tabIndex: string) {
226+
@Attribute('tabindex') tabIndex: string,
227+
/**
228+
* @deprecated
229+
* @deletion-target 7.0.0 `_focusMonitor` parameter to be made required.
230+
*/
231+
private _focusMonitor?: FocusMonitor) {
226232
super();
227233

228234
this._tabLinkRipple = new RippleRenderer(this, ngZone, _elementRef, platform);
@@ -239,10 +245,18 @@ export class MatTabLink extends _MatTabLinkMixinBase
239245
animation: globalOptions.animation,
240246
};
241247
}
248+
249+
if (_focusMonitor) {
250+
_focusMonitor.monitor(_elementRef.nativeElement);
251+
}
242252
}
243253

244254
ngOnDestroy() {
245255
this._tabLinkRipple._removeTriggerEvents();
256+
257+
if (this._focusMonitor) {
258+
this._focusMonitor.stopMonitoring(this._elementRef.nativeElement);
259+
}
246260
}
247261

248262
/**

src/lib/tabs/tabs-module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {MatTabHeader} from './tab-header';
2020
import {MatTabLabel} from './tab-label';
2121
import {MatTabLabelWrapper} from './tab-label-wrapper';
2222
import {MatTabLink, MatTabNav} from './tab-nav-bar/tab-nav-bar';
23+
import {A11yModule} from '@angular/cdk/a11y';
2324

2425

2526
@NgModule({
@@ -29,6 +30,7 @@ import {MatTabLink, MatTabNav} from './tab-nav-bar/tab-nav-bar';
2930
PortalModule,
3031
MatRippleModule,
3132
ObserversModule,
33+
A11yModule,
3234
],
3335
// Don't export all components because some are only to be used internally.
3436
exports: [

0 commit comments

Comments
 (0)