Skip to content

Commit 50f7f40

Browse files
committed
fix(material/list): not working correctly when list item is used as a button
Based on our selector for `mat-list-item`, we allow it to be a `button`, however we don't do the necessary resets for it to be usable.
1 parent 23f3929 commit 50f7f40

File tree

1 file changed

+56
-47
lines changed

1 file changed

+56
-47
lines changed

src/material/list/list.scss

Lines changed: 56 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -36,43 +36,14 @@ $item-inset-divider-offset: 72px;
3636
// based on whether the list is in dense mode.
3737
@mixin item-base($base-height, $height-with-avatar, $two-line-height,
3838
$three-line-height, $multi-line-padding, $icon-size, $avatar-size) {
39-
40-
// Prevents the wrapper `mat-list-item-content` from collapsing due to it
41-
// being `inline` by default.
42-
display: block;
4339
height: $base-height;
44-
-webkit-tap-highlight-color: transparent;
45-
46-
// Override the user agent styling if the list item is a button.
47-
width: 100%;
48-
padding: 0;
4940

5041
.mat-list-item-content {
51-
display: flex;
52-
flex-direction: row;
53-
align-items: center;
54-
box-sizing: border-box;
5542
padding: 0 $side-padding;
56-
position: relative;
57-
height: inherit;
5843
}
5944

6045
.mat-list-item-content-reverse {
61-
display: flex;
62-
align-items: center;
6346
padding: 0 $side-padding;
64-
flex-direction: row-reverse;
65-
justify-content: space-around;
66-
}
67-
68-
.mat-list-item-ripple {
69-
display: block;
70-
@include layout-common.fill;
71-
72-
// Disable pointer events for the ripple container because the container will overlay the
73-
// user content and we don't want to disable mouse events on the user content.
74-
// Pointer events can be safely disabled because the ripple trigger element is the host element.
75-
pointer-events: none;
7647
}
7748

7849
&.mat-list-item-with-avatar {
@@ -83,7 +54,6 @@ $item-inset-divider-offset: 72px;
8354
height: $two-line-height;
8455
}
8556

86-
8757
&.mat-3-line {
8858
height: $three-line-height;
8959
}
@@ -108,6 +78,23 @@ $item-inset-divider-offset: 72px;
10878
padding: 0;
10979
}
11080

81+
.mat-divider {
82+
position: absolute;
83+
bottom: 0;
84+
left: 0;
85+
width: 100%;
86+
margin: 0;
87+
88+
[dir='rtl'] & {
89+
margin-left: auto;
90+
margin-right: 0;
91+
}
92+
93+
&.mat-divider-inset {
94+
position: absolute; // necessary to override card styles
95+
}
96+
}
97+
11198
&.mat-list-item-with-avatar,
11299
&.mat-list-option {
113100
.mat-list-item-content .mat-list-text {
@@ -171,23 +158,6 @@ $item-inset-divider-offset: 72px;
171158
$side-padding);
172159
}
173160
}
174-
175-
.mat-divider {
176-
position: absolute;
177-
bottom: 0;
178-
left: 0;
179-
width: 100%;
180-
margin: 0;
181-
182-
[dir='rtl'] & {
183-
margin-left: auto;
184-
margin-right: 0;
185-
}
186-
187-
&.mat-divider-inset {
188-
position: absolute; // necessary to override card styles
189-
}
190-
}
191161
}
192162

193163
.mat-subheader {
@@ -235,6 +205,45 @@ $item-inset-divider-offset: 72px;
235205
}
236206
}
237207

208+
.mat-list-item,
209+
.mat-list-option {
210+
// Prevents the wrapper `mat-list-item-content` from collapsing due to it
211+
// being `inline` by default.
212+
display: block;
213+
-webkit-tap-highlight-color: transparent;
214+
215+
// Button resets.
216+
border: none;
217+
background: none;
218+
padding: 0;
219+
width: 100%;
220+
}
221+
222+
.mat-list-item-ripple {
223+
display: block;
224+
@include layout-common.fill;
225+
226+
// Disable pointer events for the ripple container because the container will overlay the
227+
// user content and we don't want to disable mouse events on the user content.
228+
// Pointer events can be safely disabled because the ripple trigger element is the host element.
229+
pointer-events: none;
230+
}
231+
232+
.mat-list-item-content {
233+
display: flex;
234+
flex-direction: row;
235+
align-items: center;
236+
box-sizing: border-box;
237+
position: relative;
238+
height: inherit;
239+
}
240+
241+
.mat-list-item-content-reverse {
242+
display: flex;
243+
align-items: center;
244+
flex-direction: row-reverse;
245+
justify-content: space-around;
246+
}
238247

239248
.mat-list-base[dense] {
240249
padding-top: $dense-top-padding;

0 commit comments

Comments
 (0)