Skip to content

Commit e40902d

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 e029ea8 commit e40902d

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
@@ -61,22 +61,27 @@
6161
}
6262

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

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

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

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

src/material/tabs/_tabs-theme.scss

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

6464
// Override ink bar when background color is the same
6565
&.mat-background-#{$name} {
66-
@include _mat-ink-bar($color, default-contrast);
66+
> .mat-tab-header, > .mat-tab-link-container {
67+
@include _mat-ink-bar($color, default-contrast);
68+
}
6769
}
6870
}
6971
}
@@ -97,13 +99,16 @@
9799
}
98100

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

105110
// Set labels to contrast against background
106-
.mat-tab-label, .mat-tab-link {
111+
> .mat-tab-header .mat-tab-label, > .mat-tab-link-container .mat-tab-link {
107112
color: mat-color($background-color, default-contrast);
108113

109114
&.mat-tab-disabled {
@@ -112,17 +117,18 @@
112117
}
113118

114119
// Set pagination chevrons to contrast background
115-
.mat-tab-header-pagination-chevron {
120+
> .mat-tab-header-pagination .mat-tab-header-pagination-chevron {
116121
border-color: mat-color($background-color, default-contrast);
117122
}
118123

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

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

0 commit comments

Comments
 (0)