Skip to content

Commit 2b074ef

Browse files
devversionandrewseguin
authored andcommitted
fix(list): incorrect padding for list-items with avatars, icons (#9163)
Currently list-items with an avatar, icon or checkbox have a both-sided margin for the text of 16px, while there is still a padding of 16px for the `mat-list-item-content` of 16px. This means that there is a 32px padding, that is not valid per specs. The padding for the mat-list-text should be just on the side of the secondary item (e.g. avatar, icon or checkbox), and the other side should have no padding, because the `mat-list-item-content` already has a padding for that one. Fixes #9156
1 parent f5fa4c8 commit 2b074ef

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

src/demo-app/list/list-demo.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ <h2>Selection list</h2>
110110
(change)="changeEventCount = changeEventCount + 1">
111111
<h3 mat-subheader>Groceries</h3>
112112

113-
<mat-list-option value="bananas">Bananas</mat-list-option>
113+
<mat-list-option value="bananas" checkboxPosition="before">Bananas</mat-list-option>
114114
<mat-list-option selected value="oranges">Oranges</mat-list-option>
115115
<mat-list-option value="apples">Apples</mat-list-option>
116116
<mat-list-option value="strawberries">Strawberries</mat-list-option>

src/lib/list/list.scss

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,40 @@ $mat-dense-list-icon-size: 20px;
9090

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

95-
// We only want to override the padding if there isn't
96-
// an avatar or icon before the element. Since the ripple
97-
// will always be the first child in the container, we
98-
// check whether this element is the second child.
94+
// By default, padding will be always added on the start-side of the mat-list-text, because
95+
// we assume that there is always a secondary item (e.g. avatar-icon, checkbox). But if the
96+
// mat-list-text element is the second element, then there is no secondary item and
97+
// the padding can be removed.
9998
&:nth-child(2) {
10099
padding: 0;
101100
}
102101
}
103102

103+
// There can be a secondary item (e.g. avatar-icon, checkbox) at the start of the
104+
// list-item. This means that there should be a padding for the mat-list-text on the start-side.
105+
.mat-list-item-content .mat-list-text {
106+
padding-left: $mat-list-side-padding;
107+
108+
[dir='rtl'] & {
109+
padding-right: $mat-list-side-padding;
110+
padding-left: 0;
111+
}
112+
}
113+
114+
// Reversed content is mainly used by the MatSelectionList for displaying the checkbox at the
115+
// end of the list option. Since there is a secondary item (checkbox) at the end of the
116+
// option, there needs to be a padding for the mat-list-text on the end-side.
117+
.mat-list-item-content-reverse .mat-list-text {
118+
padding-left: 0;
119+
padding-right: $mat-list-side-padding;
120+
121+
[dir='rtl'] & {
122+
padding-right: 0;
123+
padding-left: $mat-list-side-padding;
124+
}
125+
}
126+
104127
.mat-list-avatar {
105128
flex-shrink: 0;
106129
width: $mat-list-avatar-size;

0 commit comments

Comments
 (0)