Skip to content

Commit 01978b0

Browse files
committed
rewrite list css
1 parent e2330b8 commit 01978b0

File tree

2 files changed

+24
-42
lines changed

2 files changed

+24
-42
lines changed

src/lib/list/list.scss

Lines changed: 21 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -102,53 +102,34 @@ $mat-list-item-inset-divider-offset: 72px;
102102
padding: 0;
103103
}
104104

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:not(:nth-child(2)) {
108-
padding-right: 0;
109-
padding-left: $mat-list-side-padding;
110-
111-
[dir='rtl'] & {
112-
padding-right: $mat-list-side-padding;
113-
padding-left: 0;
114-
}
115-
}
116-
117-
// Reversed content is mainly used by the MatSelectionList for displaying the checkbox at the
118-
// end of the list option. Since there is a secondary item (checkbox) at the end of the
119-
// option, there needs to be a padding for the mat-list-text on the end-side.
120-
.mat-list-item-content-reverse .mat-list-text:not(:nth-child(2)) {
121-
padding-left: 0;
122-
padding-right: $mat-list-side-padding;
123-
124-
[dir='rtl'] & {
105+
&.mat-list-item-with-avatar,
106+
&.mat-list-option {
107+
.mat-list-item-content .mat-list-text {
125108
padding-right: 0;
126109
padding-left: $mat-list-side-padding;
110+
111+
[dir='rtl'] & {
112+
padding-right: $mat-list-side-padding;
113+
padding-left: 0;
114+
}
127115
}
128-
}
129116

130-
// If avatar is the 4th item, it means the list-item has both checkbox and avatar-icon.
131-
// This means that there should be a margin for the mat-list-avatar on the start-side.
132-
.mat-list-item-content .mat-list-avatar:nth-child(4) {
133-
margin-right: 0;
134-
margin-left: $mat-list-side-padding;
117+
.mat-list-item-content-reverse .mat-list-text {
118+
padding-left: 0;
119+
padding-right: $mat-list-side-padding;
135120

136-
[dir='rtl'] & {
137-
margin-right: $mat-list-side-padding;
138-
margin-left: 0;
121+
[dir='rtl'] & {
122+
padding-right: 0;
123+
padding-left: $mat-list-side-padding;
124+
}
139125
}
140-
}
126+
}
141127

142-
// Reversed content is mainly used by the MatSelectionList for displaying the checkbox at the
143-
// end of the list option. If avatar is the 4th item, it means the list-item has both checkbox
144-
// and avatar-icon. There needs to be a padding for the mat-list-avatar on the end-side.
145-
.mat-list-item-content-reverse .mat-list-avatar:nth-child(4) {
146-
margin-left: 0;
147-
margin-right: $mat-list-side-padding;
148-
149-
[dir='rtl'] & {
150-
margin-right: 0;
151-
margin-left: $mat-list-side-padding;
128+
&.mat-list-item-with-avatar.mat-list-option {
129+
.mat-list-item-content-reverse .mat-list-text,
130+
.mat-list-item-content .mat-list-text {
131+
padding-right: $mat-list-side-padding;
132+
padding-left: $mat-list-side-padding;
152133
}
153134
}
154135

src/lib/list/list.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ export class MatListSubheaderCssMatStyler {}
9797
host: {
9898
'class': 'mat-list-item',
9999
// @deletion-target 7.0.0 Remove `mat-list-item-avatar` in favor of `mat-list-item-with-avatar`.
100-
'[class.mat-list-item-avatar]': '_avatar',
101-
'[class.mat-list-item-with-avatar]': '_avatar',
100+
'[class.mat-list-item-avatar]': '_avatar || _icon',
101+
'[class.mat-list-item-with-avatar]': '_avatar || _icon',
102102
'(focus)': '_handleFocus()',
103103
'(blur)': '_handleBlur()',
104104
},
@@ -113,6 +113,7 @@ export class MatListItem extends _MatListItemMixinBase implements AfterContentIn
113113

114114
@ContentChildren(MatLine) _lines: QueryList<MatLine>;
115115
@ContentChild(MatListAvatarCssMatStyler) _avatar: MatListAvatarCssMatStyler;
116+
@ContentChild(MatListIconCssMatStyler) _icon: MatListIconCssMatStyler;
116117

117118
constructor(private _element: ElementRef,
118119
@Optional() private _navList: MatNavList) {

0 commit comments

Comments
 (0)