Skip to content

Commit 91e40bd

Browse files
committed
fix(menu): allow text wrapping in menu items
Allows for the text inside menu items to wrap, instead of having it be truncated. The text was being truncated as a limitation on `mat-select` and `mat-autocomplete`, however we don't have the same limitation on `mat-menu`.
1 parent e9466a4 commit 91e40bd

File tree

4 files changed

+25
-9
lines changed

4 files changed

+25
-9
lines changed

src/dev-app/menu/menu-demo.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ export class MenuDemo {
1919
selected = '';
2020
items = [
2121
{text: 'Refresh'},
22-
{text: 'Settings'},
22+
{text: 'Settings with a longer name so we can test text wrapping'},
2323
{text: 'Help', disabled: true},
2424
{text: 'Sign Out'}
2525
];
2626

2727
iconItems = [
28-
{text: 'Redial', icon: 'dialpad'},
28+
{text: 'Redial with a longer name so we can test text wrapping', icon: 'dialpad'},
2929
{text: 'Check voicemail', icon: 'voicemail', disabled: true},
3030
{text: 'Disable alerts', icon: 'notifications_off'}
3131
];

src/lib/core/option/option.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
display: flex;
1212
flex-direction: row;
1313
max-width: 100%;
14-
box-sizing: border-box;
1514
align-items: center;
1615
-webkit-tap-highlight-color: transparent;
1716

src/lib/core/style/_menu-common.scss

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,22 @@ $mat-menu-icon-margin: 16px !default;
2020
-webkit-overflow-scrolling: touch; // for momentum scroll on mobile
2121
}
2222

23-
@mixin mat-menu-item-base() {
24-
@include mat-truncate-line();
23+
@mixin mat-menu-item-base(
24+
$display: block,
25+
$truncate: true,
26+
$height: $mat-menu-item-height,
27+
$line-height: $height) {
28+
29+
@if $truncate {
30+
@include mat-truncate-line();
31+
}
2532

2633
// Needs to be a block for the ellipsis to work.
27-
display: block;
28-
line-height: $mat-menu-item-height;
29-
height: $mat-menu-item-height;
34+
display: $display;
35+
height: $height;
36+
line-height: $line-height;
3037
padding: 0 $mat-menu-side-padding;
38+
box-sizing: border-box;
3139

3240
text-align: left;
3341
text-decoration: none; // necessary to reset anchor tags

src/lib/menu/menu.scss

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
@import '../../cdk/a11y/a11y';
66

77
$mat-menu-vertical-padding: 8px !default;
8+
$mat-menu-item-vertical-padding: 8px !default;
89
$mat-menu-border-radius: 4px !default;
910
$mat-menu-submenu-indicator-size: 10px !default;
1011

@@ -27,9 +28,17 @@ $mat-menu-submenu-indicator-size: 10px !default;
2728

2829
.mat-menu-item {
2930
@include mat-button-reset();
30-
@include mat-menu-item-base();
31+
@include mat-menu-item-base(flex, false, auto, normal);
3132
position: relative;
3233

34+
// TODO(crisbeto): most of these can be moved into the `mat-menu-item-base`
35+
// once we start allowing text wrapping in mat-select and mat-autocomplete.
36+
align-items: center;
37+
white-space: normal;
38+
min-height: $mat-menu-item-height;
39+
padding-top: $mat-menu-item-vertical-padding;
40+
padding-bottom: $mat-menu-item-vertical-padding;
41+
3342
@include cdk-high-contrast {
3443
&.cdk-program-focused,
3544
&.cdk-keyboard-focused,

0 commit comments

Comments
 (0)