Skip to content

Commit 5a7da12

Browse files
authored
refactor(material/menu): remove MDC classes from markup (#27497)
After #27377 and #27378 we no longer use MDC classes directly in the markup. Instead we either use our own styles or we target our selectors with MDC mixins. However, the MDC classes were left in to reduce the amount of internal breakages. These leftover styles can still cause styles to bleed in from the MDC list so this change removes any remaining references.
1 parent cc02ea8 commit 5a7da12

File tree

4 files changed

+10
-33
lines changed

4 files changed

+10
-33
lines changed

src/material/menu/menu-item.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<ng-content select="mat-icon, [matMenuItemIcon]"></ng-content>
2-
<span class="mdc-list-item__primary-text"><ng-content></ng-content></span>
2+
<span class="mat-mdc-menu-item-text"><ng-content></ng-content></span>
33
<div class="mat-mdc-menu-ripple" matRipple
44
[matRippleDisabled]="disableRipple || disabled"
55
[matRippleTrigger]="_getHostElement()">

src/material/menu/menu-item.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const _MatMenuItemBase = mixinDisableRipple(mixinDisabled(class {}));
4242
inputs: ['disabled', 'disableRipple'],
4343
host: {
4444
'[attr.role]': 'role',
45-
'class': 'mat-mdc-menu-item mat-mdc-focus-indicator mdc-list-item',
45+
'class': 'mat-mdc-menu-item mat-mdc-focus-indicator',
4646
'[class.mat-mdc-menu-item-highlighted]': '_highlighted',
4747
'[class.mat-mdc-menu-item-submenu-trigger]': '_triggersSubmenu',
4848
'[attr.tabindex]': '_getTabIndex()',

src/material/menu/menu.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<ng-template>
22
<div
3-
class="mat-mdc-menu-panel mdc-menu-surface mdc-menu-surface--open mat-mdc-elevation-specific"
3+
class="mat-mdc-menu-panel mat-mdc-elevation-specific"
44
[id]="panelId"
55
[ngClass]="_classList"
66
(keydown)="_handleKeydown($event)"
@@ -13,7 +13,7 @@
1313
[attr.aria-label]="ariaLabel || null"
1414
[attr.aria-labelledby]="ariaLabelledby || null"
1515
[attr.aria-describedby]="ariaDescribedby || null">
16-
<div class="mat-mdc-menu-content mdc-list">
16+
<div class="mat-mdc-menu-content">
1717
<ng-content></ng-content>
1818
</div>
1919
</div>

src/material/menu/menu.scss

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ mat-menu {
1818
@include mdc-list-mixins.list-base($query: structure);
1919

2020
&,
21-
.mat-mdc-menu-item .mdc-list-item__primary-text {
21+
.mat-mdc-menu-item .mat-mdc-menu-item-text {
2222
@include mdc-typography.smooth-font();
23+
white-space: normal;
24+
2325
@include token-utils.use-tokens(tokens-mat-menu.$prefix, tokens-mat-menu.get-token-slots()) {
2426
@include token-utils.create-token-slot(font-family, item-label-text-font);
2527
@include token-utils.create-token-slot(line-height, item-label-text-line-height);
@@ -32,7 +34,8 @@ mat-menu {
3234

3335
.mat-mdc-menu-panel {
3436
@include token-utils.create-token-values(tokens-mat-menu.$prefix,
35-
tokens-mat-menu.get-unthemable-tokens());
37+
tokens-mat-menu.get-unthemable-tokens());
38+
@include menu-common.base;
3639
box-sizing: border-box;
3740
outline: 0;
3841

@@ -63,20 +66,6 @@ mat-menu {
6366
}
6467
}
6568

66-
// We need to increase the specificity for these styles to ensure we are not overridden by MDC's
67-
// .mdc-menu-surface styles. This can happen if the MDC styles are loaded in after our styles.
68-
.mat-mdc-menu-panel.mat-mdc-menu-panel {
69-
// Include Material's base menu panel styling which contain the `min-width`, `max-width` and some
70-
// styling to make scrolling smoother. MDC doesn't include the `min-width` and `max-width`, even
71-
// though they're explicitly defined in spec.
72-
@include menu-common.base;
73-
74-
// The CDK positioning uses flexbox to anchor the element, whereas MDC uses `position: absolute`.
75-
// Furthermore, the relative position ensures that the `offsetParent` is the menu, rather than
76-
// the overlay. This comes into play when we measure the `offsetTop` of a menu item.
77-
position: relative;
78-
}
79-
8069
.mat-mdc-menu-item {
8170
@include mdc-helpers.disable-mdc-fallback-declarations {
8271
@include mdc-list-mixins.item-base;
@@ -96,6 +85,7 @@ mat-menu {
9685
background: none;
9786
text-decoration: none;
9887
margin: 0; // Resolves an issue where buttons have an extra 2px margin on Safari.
88+
align-items: center;
9989

10090
// Set the `min-height` here ourselves, instead of going through
10191
// the `mdc-list-one-line-item-density` mixin, because it sets a `height`
@@ -117,13 +107,6 @@ mat-menu {
117107
}
118108
}
119109

120-
// If the MDC list is loaded after the menu, this gets overwritten which breaks the text
121-
// alignment. Ideally we'd wrap all the MDC mixins above with this selector, but the increased
122-
// specificity breaks some internal overrides.
123-
&.mdc-list-item {
124-
align-items: center;
125-
}
126-
127110
&[disabled] {
128111
cursor: default;
129112

@@ -159,12 +142,6 @@ mat-menu {
159142
}
160143
}
161144

162-
// Needs to be overwritten explicitly, because the style can
163-
// leak in from the list and cause the text to truncate.
164-
.mdc-list-item__primary-text {
165-
white-space: normal;
166-
}
167-
168145
&.mat-mdc-menu-item-submenu-trigger {
169146
@include menu-common.item-submenu-trigger(mdc-list-variables.$side-padding);
170147
}

0 commit comments

Comments
 (0)