Skip to content
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

fix(list): incorrect padding for list-items with avatars, icons #9500

Merged
Merged
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
2 changes: 1 addition & 1 deletion src/demo-app/list/list-demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ <h2>Selection list</h2>
(change)="changeEventCount = changeEventCount + 1">
<h3 mat-subheader>Groceries</h3>

<mat-list-option value="bananas">Bananas</mat-list-option>
<mat-list-option value="bananas" checkboxPosition="before">Bananas</mat-list-option>
<mat-list-option selected value="oranges">Oranges</mat-list-option>
<mat-list-option value="apples">Apples</mat-list-option>
<mat-list-option value="strawberries">Strawberries</mat-list-option>
Expand Down
35 changes: 28 additions & 7 deletions src/lib/list/list.scss
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,35 @@ $mat-list-item-inset-divider-offset: 72px;

.mat-list-text {
@include mat-line-wrapper-base();
padding: 0 $mat-list-side-padding;

// We only want to override the padding if there isn't
// an avatar or icon before the element. Since the ripple
// will always be the first child in the container, we
// check whether this element is the second child.
&:nth-child(2) {
padding: 0;
// By default, there will be no padding for the list item text because the padding is already
// set on the `mat-list-item-content` element. Later, if the list-item detects that there are
// secondary items (avatar, checkbox), a padding on the proper side will be added.
padding: 0;
}

// There can be a secondary item (e.g. avatar-icon, checkbox) at the start of the
// list-item. This means that there should be a padding for the mat-list-text on the start-side.
.mat-list-item-content .mat-list-text:not(:nth-child(2)) {
padding-right: 0;
padding-left: $mat-list-side-padding;

[dir='rtl'] & {
padding-right: $mat-list-side-padding;
padding-left: 0;
}
}

// Reversed content is mainly used by the MatSelectionList for displaying the checkbox at the
// end of the list option. Since there is a secondary item (checkbox) at the end of the
// option, there needs to be a padding for the mat-list-text on the end-side.
.mat-list-item-content-reverse .mat-list-text:not(:nth-child(2)) {
padding-left: 0;
padding-right: $mat-list-side-padding;

[dir='rtl'] & {
padding-right: 0;
padding-left: $mat-list-side-padding;
}
}

Expand Down