Skip to content

Commit 0ca0bed

Browse files
committed
fix(divider): add inset styles for icons and lists in cards
* Add mixin to dynamically apply inset divider offset based on the precursor in the list item * Add inset divider example using icons as precursor
1 parent d85c44b commit 0ca0bed

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,11 @@ <h2>Nav lists</h2>
8787
</mat-list-item>
8888
</mat-nav-list>
8989
<mat-nav-list>
90-
<a mat-list-item *ngFor="let link of links" href="http://www.google.com">
90+
<a mat-list-item *ngFor="let link of links; last as last" href="http://www.google.com">
9191
<mat-icon mat-list-icon>folder</mat-icon>
9292
<span mat-line>{{ link.name }}</span>
9393
<span mat-line class="demo-secondary-text"> Description </span>
94+
<mat-divider [inset]="true" *ngIf="!last"></mat-divider>
9495
</a>
9596
</mat-nav-list>
9697
<mat-nav-list dense>

src/lib/list/list.scss

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55

66
$mat-list-side-padding: 16px;
7+
$mat-list-icon-padding: 4px;
78
$mat-list-avatar-size: 40px;
89

910
// Normal list variables
@@ -27,7 +28,18 @@ $mat-dense-three-line-height: 76px;
2728
$mat-dense-multi-line-padding: 16px;
2829
$mat-dense-list-icon-size: 20px;
2930

30-
$mat-list-item-inset-divider-offset: 72px;
31+
// This mixin provides the correct offset for an inset divider based on the
32+
// size of the parent class (e.g. avatar vs icon)
33+
@mixin mat-inset-divider-offset($offset) {
34+
$mat-list-item-inset-divider-offset: #{(2 * $mat-list-side-padding) + $offset};
35+
left: $mat-list-item-inset-divider-offset;
36+
width: calc(100% - #{$mat-list-item-inset-divider-offset});
37+
38+
[dir='rtl'] & {
39+
left: auto;
40+
right: $mat-list-item-inset-divider-offset;
41+
}
42+
}
3143

3244
// This mixin provides all list-item styles, changing font size and height
3345
// based on whether the list is in dense mode.
@@ -108,6 +120,10 @@ $mat-list-item-inset-divider-offset: 72px;
108120
width: $mat-list-avatar-size;
109121
height: $mat-list-avatar-size;
110122
border-radius: 50%;
123+
124+
~ .mat-divider-inset {
125+
@include mat-inset-divider-offset($mat-list-avatar-size);
126+
}
111127
}
112128

113129
.mat-list-icon {
@@ -116,7 +132,11 @@ $mat-list-item-inset-divider-offset: 72px;
116132
font-size: $icon-size;
117133
box-sizing: content-box;
118134
border-radius: 50%;
119-
padding: 4px;
135+
padding: $mat-list-icon-padding;
136+
137+
~ .mat-divider-inset {
138+
@include mat-inset-divider-offset($icon-size + (2 * $mat-list-icon-padding));
139+
}
120140
}
121141

122142
.mat-divider {
@@ -131,14 +151,8 @@ $mat-list-item-inset-divider-offset: 72px;
131151
}
132152

133153
&.mat-divider-inset {
134-
left: $mat-list-item-inset-divider-offset;
135-
width: calc(100% - #{$mat-list-item-inset-divider-offset});
136154
margin: 0;
137-
138-
[dir='rtl'] & {
139-
left: auto;
140-
right: $mat-list-item-inset-divider-offset;
141-
}
155+
position: absolute;
142156
}
143157
}
144158
}

0 commit comments

Comments
 (0)