Skip to content

Commit dfbd8d2

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 1c2f6b7 commit dfbd8d2

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
@@ -111,7 +111,7 @@ <h2>Selection list</h2>
111111
(change)="changeEventCount = changeEventCount + 1">
112112
<h3 mat-subheader>Groceries</h3>
113113

114-
<mat-list-option value="bananas">Bananas</mat-list-option>
114+
<mat-list-option value="bananas" checkboxPosition="before">Bananas</mat-list-option>
115115
<mat-list-option selected value="oranges">Oranges</mat-list-option>
116116
<mat-list-option value="apples">Apples</mat-list-option>
117117
<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
@@ -92,17 +92,40 @@ $mat-list-item-inset-divider-offset: 72px;
9292

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

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

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

0 commit comments

Comments
 (0)