Skip to content

Commit 7d81b6f

Browse files
crisbetojelbourn
authored andcommitted
fix(list): align avatar size in dense list with spec (#10028)
* Fixes the dense list avatar being slightly larger than the spec. * Removes an unnecessary setter from the `MatListItem` class. Fixes #10019.
1 parent d26aa6e commit 7d81b6f

File tree

3 files changed

+19
-21
lines changed

3 files changed

+19
-21
lines changed

src/lib/list/list.scss

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@ $mat-dense-two-line-height: 60px;
2828
$mat-dense-three-line-height: 76px;
2929
$mat-dense-multi-line-padding: 16px;
3030
$mat-dense-list-icon-size: 20px;
31+
$mat-dense-avatar-size: 36px;
3132

3233
$mat-list-item-inset-divider-offset: 72px;
3334

3435
// This mixin provides all list-item styles, changing font size and height
3536
// based on whether the list is in dense mode.
36-
@mixin mat-list-item-base($base-height, $avatar-height, $two-line-height,
37-
$three-line-height, $multi-line-padding, $icon-size) {
37+
@mixin mat-list-item-base($base-height, $height-with-avatar, $two-line-height,
38+
$three-line-height, $multi-line-padding, $icon-size, $avatar-size) {
3839

3940
// Prevents the wrapper `mat-list-item-content` from collapsing due to it
4041
// being `inline` by default.
@@ -68,8 +69,8 @@ $mat-list-item-inset-divider-offset: 72px;
6869
pointer-events: none;
6970
}
7071

71-
&.mat-list-item-avatar {
72-
height: $avatar-height;
72+
&.mat-list-item-with-avatar {
73+
height: $height-with-avatar;
7374
}
7475

7576
&.mat-2-line {
@@ -128,12 +129,12 @@ $mat-list-item-inset-divider-offset: 72px;
128129

129130
.mat-list-avatar {
130131
flex-shrink: 0;
131-
width: $mat-list-avatar-size;
132-
height: $mat-list-avatar-size;
132+
width: $avatar-size;
133+
height: $avatar-size;
133134
border-radius: 50%;
134135

135136
~ .mat-divider-inset {
136-
@include mat-inset-divider-offset($mat-list-avatar-size, $mat-list-side-padding);
137+
@include mat-inset-divider-offset($avatar-size, $mat-list-side-padding);
137138
}
138139
}
139140

@@ -210,7 +211,8 @@ $mat-list-item-inset-divider-offset: 72px;
210211
$mat-list-two-line-height,
211212
$mat-list-three-line-height,
212213
$mat-list-multi-line-padding,
213-
$mat-list-icon-size
214+
$mat-list-icon-size,
215+
$mat-list-avatar-size
214216
);
215217
}
216218
}
@@ -232,7 +234,8 @@ $mat-list-item-inset-divider-offset: 72px;
232234
$mat-dense-two-line-height,
233235
$mat-dense-three-line-height,
234236
$mat-dense-multi-line-padding,
235-
$mat-dense-list-icon-size
237+
$mat-dense-list-icon-size,
238+
$mat-dense-avatar-size
236239
);
237240
}
238241
}

src/lib/list/list.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,13 @@ describe('MatList', () => {
7777
expect(listItems[1].nativeElement.className).toContain('mat-multi-line');
7878
});
7979

80-
it('should apply mat-list-avatar class to list items with avatars', () => {
80+
it('should apply a class to list items with avatars', () => {
8181
let fixture = TestBed.createComponent(ListWithAvatar);
8282
fixture.detectChanges();
8383

8484
let listItems = fixture.debugElement.children[0].queryAll(By.css('mat-list-item'));
85-
expect(listItems[0].nativeElement.className).toContain('mat-list-item-avatar');
86-
expect(listItems[1].nativeElement.className).not.toContain('mat-list-item-avatar');
85+
expect(listItems[0].nativeElement.className).toContain('mat-list-item-with-avatar');
86+
expect(listItems[1].nativeElement.className).not.toContain('mat-list-item-with-avatar');
8787
});
8888

8989
it('should not clear custom classes provided by user', () => {

src/lib/list/list.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ export class MatListSubheaderCssMatStyler {}
9898
exportAs: 'matListItem',
9999
host: {
100100
'class': 'mat-list-item',
101+
// @deletion-target 7.0.0 Remove `mat-list-item-avatar` in favor of `mat-list-item-with-avatar`.
102+
'[class.mat-list-item-avatar]': '_avatar',
103+
'[class.mat-list-item-with-avatar]': '_avatar',
101104
'(focus)': '_handleFocus()',
102105
'(blur)': '_handleBlur()',
103106
},
@@ -112,15 +115,7 @@ export class MatListItem extends _MatListItemMixinBase implements AfterContentIn
112115
private _isNavList: boolean = false;
113116

114117
@ContentChildren(MatLine) _lines: QueryList<MatLine>;
115-
116-
@ContentChild(MatListAvatarCssMatStyler)
117-
set _hasAvatar(avatar: MatListAvatarCssMatStyler) {
118-
if (avatar != null) {
119-
this._element.nativeElement.classList.add('mat-list-item-avatar');
120-
} else {
121-
this._element.nativeElement.classList.remove('mat-list-item-avatar');
122-
}
123-
}
118+
@ContentChild(MatListAvatarCssMatStyler) _avatar: MatListAvatarCssMatStyler;
124119

125120
constructor(private _element: ElementRef,
126121
@Optional() private _navList: MatNavList) {

0 commit comments

Comments
 (0)