Skip to content

Commit 934f7eb

Browse files
crisbetommalerba
authored andcommitted
fix(material/tabs): background color inherited to nested groups (#21533)
Fixes that setting a `backgroundColor` on a top-level tab group ends up being inherited to all grounds nested within it. The problem was that our selectors were too broad and they were targeting all descendants. Fixes #14819. Fixes #21530. (cherry picked from commit bf0dff8)
1 parent e1ec7d0 commit 934f7eb

File tree

2 files changed

+27
-16
lines changed

2 files changed

+27
-16
lines changed

src/material-experimental/mdc-tabs/_tabs-theme.scss

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,27 @@
6262
}
6363

6464
@mixin _mat-mdc-tabs-background($background-color, $foreground-color) {
65-
.mat-mdc-tab-header, .mat-mdc-tab-links, .mat-mdc-tab-header-pagination {
65+
// Note that these selectors target direct descendants so
66+
// that the styles don't apply to any nested tab groups.
67+
68+
> .mat-mdc-tab-header, > .mat-mdc-tab-link-container, > .mat-mdc-tab-header-pagination {
6669
// Set background color for the tab group
6770
@include mdc-theme-prop(background-color, $background-color);
6871
}
6972

70-
// Set labels to contrast against background
71-
.mdc-tab__text-label, .mat-mdc-tab-link {
72-
@include mdc-theme-prop(color, $foreground-color);
73-
}
73+
> .mat-mdc-tab-header, > .mat-mdc-tab-link-container {
74+
// Set labels to contrast against background
75+
.mdc-tab__text-label, .mat-mdc-tab-link {
76+
@include mdc-theme-prop(color, $foreground-color);
77+
}
7478

75-
.mat-ripple-element, .mdc-tab__ripple::before {
76-
@include mdc-theme-prop(background-color, $foreground-color);
77-
}
79+
.mat-ripple-element, .mdc-tab__ripple::before {
80+
@include mdc-theme-prop(background-color, $foreground-color);
81+
}
7882

79-
.mdc-tab-indicator__content--underline, .mat-mdc-tab-header-pagination-chevron {
80-
@include mdc-theme-prop(border-color, $foreground-color);
83+
.mdc-tab-indicator__content--underline, .mat-mdc-tab-header-pagination-chevron {
84+
@include mdc-theme-prop(border-color, $foreground-color);
85+
}
8186
}
8287
}
8388

src/material/tabs/_tabs-theme.scss

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@
6262

6363
// Override ink bar when background color is the same
6464
&.mat-background-#{$name} {
65-
@include _mat-ink-bar($color, default-contrast);
65+
> .mat-tab-header, > .mat-tab-link-container {
66+
@include _mat-ink-bar($color, default-contrast);
67+
}
6668
}
6769
}
6870
}
@@ -96,13 +98,16 @@
9698
}
9799

98100
@mixin _mat-tabs-background($background-color) {
101+
// Note that these selectors target direct descendants so
102+
// that the styles don't apply to any nested tab groups.
103+
99104
// Set background color for the tab group
100-
.mat-tab-header, .mat-tab-links, .mat-tab-header-pagination {
105+
> .mat-tab-header, > .mat-tab-link-container, > .mat-tab-header-pagination {
101106
background-color: mat-color($background-color);
102107
}
103108

104109
// Set labels to contrast against background
105-
.mat-tab-label, .mat-tab-link {
110+
> .mat-tab-header .mat-tab-label, > .mat-tab-link-container .mat-tab-link {
106111
color: mat-color($background-color, default-contrast);
107112

108113
&.mat-tab-disabled {
@@ -111,17 +116,18 @@
111116
}
112117

113118
// Set pagination chevrons to contrast background
114-
.mat-tab-header-pagination-chevron {
119+
> .mat-tab-header-pagination .mat-tab-header-pagination-chevron {
115120
border-color: mat-color($background-color, default-contrast);
116121
}
117122

118-
.mat-tab-header-pagination-disabled .mat-tab-header-pagination-chevron {
123+
> .mat-tab-header-pagination-disabled .mat-tab-header-pagination-chevron {
119124
border-color: mat-color($background-color, default-contrast, 0.4);
120125
}
121126

122127
// Set ripples color to be the contrast color of the new background. Otherwise the ripple
123128
// color will be based on the app background color.
124-
.mat-ripple-element {
129+
> .mat-tab-header .mat-ripple-element,
130+
> .mat-tab-link-container .mat-ripple-element {
125131
background-color: mat-color($background-color, default-contrast, 0.12);
126132
}
127133
}

0 commit comments

Comments
 (0)