Skip to content

fix(material/list): list item truncates on narrow screen widths #29033

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
28 changes: 22 additions & 6 deletions src/material/list/list.scss
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,28 @@ a.mdc-list-item--activated {
}
}

.mat-mdc-list-item.mdc-list-item--with-three-lines {
// List item lines or titles never wrap. MDC always enables wrapping for secondary text
// if the list item has acquired three lines. We unset these styles for line elements.
// https://github.com/material-components/material-components-web/blob/348665978ce73694ad4518626dd70cdf5b984113/packages/mdc-list/_evolution-mixins.scss#L205-L206.
// TODO: Consider removing once MDC supports the explicit tertiary line list variant.
// Increased list item height if it has multiple lines so bottom line doesn't get
// cut off. Also added padding-bottom so there's space btw the text and the divider.
.mat-mdc-list-item.mdc-list-item--with-leading-avatar.mdc-list-item--with-two-lines,
.mat-mdc-list-item.mdc-list-item--with-leading-checkbox.mdc-list-item--with-two-lines,
.mat-mdc-list-item.mdc-list-item--with-leading-icon.mdc-list-item--with-two-lines,
.mat-mdc-list-item.mdc-list-item--with-leading-avatar.mdc-list-item--with-three-lines,
.mat-mdc-list-item.mdc-list-item--with-leading-checkbox.mdc-list-item--with-three-lines,
.mat-mdc-list-item.mdc-list-item--with-leading-icon.mdc-list-item--with-three-lines {
height: auto;
padding-bottom: 8px;
}

.mat-mdc-list-item.mdc-list-item--with-three-lines,
.mat-mdc-list-item.mdc-list-item--with-two-lines {
height: auto;
padding-bottom: 13px;
Comment on lines +165 to +180
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just realized we can make this a little cleaner by nesting the special case right under where you set the padding-bottom:

Suggested change
// Increased list item height if it has multiple lines so bottom line doesn't get
// cut off. Also added padding-bottom so there's space btw the text and the divider.
.mat-mdc-list-item.mdc-list-item--with-leading-avatar.mdc-list-item--with-two-lines,
.mat-mdc-list-item.mdc-list-item--with-leading-checkbox.mdc-list-item--with-two-lines,
.mat-mdc-list-item.mdc-list-item--with-leading-icon.mdc-list-item--with-two-lines,
.mat-mdc-list-item.mdc-list-item--with-leading-avatar.mdc-list-item--with-three-lines,
.mat-mdc-list-item.mdc-list-item--with-leading-checkbox.mdc-list-item--with-three-lines,
.mat-mdc-list-item.mdc-list-item--with-leading-icon.mdc-list-item--with-three-lines {
height: auto;
padding-bottom: 8px;
}
.mat-mdc-list-item.mdc-list-item--with-three-lines,
.mat-mdc-list-item.mdc-list-item--with-two-lines {
height: auto;
padding-bottom: 13px;
.mat-mdc-list-item.mdc-list-item--with-three-lines,
.mat-mdc-list-item.mdc-list-item--with-two-lines {
height: auto;
padding-bottom: 13px;
&.mdc-list-item--with-leading-avatar,
&.mdc-list-item--with-leading-checkbox,
&.mdc-list-item--with-leading-icon {
padding-bottom: 8px;
}
...

// List item lines must wrap according to GAR 1.18(b). Removing the nowrap and
// adjusts .mat-mdc-list-item-title.mdc-list-item__primary-text height
// to accommodate any wrapping text. Fixes: b/247881646.
.mat-mdc-list-item-title.mdc-list-item__primary-text,
.mat-mdc-list-item-line.mdc-list-item__secondary-text {
white-space: nowrap;
white-space: normal;
line-height: normal;
}

Expand Down Expand Up @@ -218,3 +233,4 @@ mat-action-list button {
}
}
}

Loading