Skip to content

fix(menu): allow text wrapping in menu items #14503

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/dev-app/menu/menu-demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ export class MenuDemo {
selected = '';
items = [
{text: 'Refresh'},
{text: 'Settings'},
{text: 'Settings with a longer name so we can test text wrapping'},
{text: 'Help', disabled: true},
{text: 'Sign Out'}
];

iconItems = [
{text: 'Redial', icon: 'dialpad'},
{text: 'Redial with a longer name so we can test text wrapping', icon: 'dialpad'},
{text: 'Check voicemail', icon: 'voicemail', disabled: true},
{text: 'Disable alerts', icon: 'notifications_off'}
];
Expand Down
1 change: 0 additions & 1 deletion src/material/core/option/option.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
display: flex;
flex-direction: row;
max-width: 100%;
box-sizing: border-box;
align-items: center;
-webkit-tap-highlight-color: transparent;

Expand Down
18 changes: 13 additions & 5 deletions src/material/core/style/_menu-common.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,22 @@ $mat-menu-icon-margin: 16px !default;
-webkit-overflow-scrolling: touch; // for momentum scroll on mobile
}

@mixin mat-menu-item-base() {
@include mat-truncate-line();
@mixin mat-menu-item-base(
$display: block,
$truncate: true,
$height: $mat-menu-item-height,
$line-height: $height) {

@if $truncate {
@include mat-truncate-line();
}

// Needs to be a block for the ellipsis to work.
display: block;
line-height: $mat-menu-item-height;
height: $mat-menu-item-height;
display: $display;
height: $height;
line-height: $line-height;
padding: 0 $mat-menu-side-padding;
box-sizing: border-box;

text-align: left;
text-decoration: none; // necessary to reset anchor tags
Expand Down
11 changes: 10 additions & 1 deletion src/material/menu/menu.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
$mat-menu-vertical-padding: 8px !default;
$mat-menu-border-radius: 4px !default;
$mat-menu-submenu-indicator-size: 10px !default;
$mat-menu-item-vertical-padding: 8px !default;

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

.mat-menu-item {
@include mat-button-reset();
@include mat-menu-item-base();
@include mat-menu-item-base(flex, false, auto, normal);
position: relative;

// TODO(crisbeto): most of these can be moved into the `mat-menu-item-base`
// once we start allowing text wrapping in mat-select and mat-autocomplete.
align-items: center;
white-space: normal;
min-height: $mat-menu-item-height;
padding-top: $mat-menu-item-vertical-padding;
padding-bottom: $mat-menu-item-vertical-padding;

&[disabled] {
// Usually every click inside the menu closes it, however some browsers will stop events
// when the user clicks on a disabled item, **except** when the user clicks on a non-disabled
Expand Down