Skip to content

Commit bfcc33a

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 e0634c9 commit bfcc33a

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
@@ -18,13 +18,13 @@ export class MenuDemo {
1818
selected = '';
1919
items = [
2020
{text: 'Refresh'},
21-
{text: 'Settings'},
21+
{text: 'Settings with a longer name so we can test text wrapping'},
2222
{text: 'Help', disabled: true},
2323
{text: 'Sign Out'}
2424
];
2525

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

src/material/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/material/core/style/_menu-common.scss

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

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

2734
// Needs to be a block for the ellipsis to work.
28-
display: block;
29-
line-height: $mat-menu-item-height;
30-
height: $mat-menu-item-height;
35+
display: $display;
36+
height: $height;
37+
line-height: $line-height;
3138
padding: 0 $mat-menu-side-padding;
39+
box-sizing: border-box;
3240

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

src/material/menu/menu.scss

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
$mat-menu-vertical-padding: 8px !default;
77
$mat-menu-border-radius: 4px !default;
88
$mat-menu-submenu-indicator-size: 10px !default;
9+
$mat-menu-item-vertical-padding: 8px !default;
910

1011
.mat-menu-panel {
1112
@include mat-menu-base();
@@ -41,9 +42,17 @@ $mat-menu-submenu-indicator-size: 10px !default;
4142

4243
.mat-menu-item {
4344
@include mat-button-reset();
44-
@include mat-menu-item-base();
45+
@include mat-menu-item-base(flex, false, auto, normal);
4546
position: relative;
4647

48+
// TODO(crisbeto): most of these can be moved into the `mat-menu-item-base`
49+
// once we start allowing text wrapping in mat-select and mat-autocomplete.
50+
align-items: center;
51+
white-space: normal;
52+
min-height: $mat-menu-item-height;
53+
padding-top: $mat-menu-item-vertical-padding;
54+
padding-bottom: $mat-menu-item-vertical-padding;
55+
4756
&[disabled] {
4857
// Usually every click inside the menu closes it, however some browsers will stop events
4958
// when the user clicks on a disabled item, **except** when the user clicks on a non-disabled

0 commit comments

Comments
 (0)