Skip to content

Commit f9e6be6

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 f9e6be6

File tree

3 files changed

+31
-19
lines changed

3 files changed

+31
-19
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ <h4 mat-line>{{message.from}}</h4>
3131
<span>{{message.subject}} -- </span>
3232
<span class="demo-secondary-text">{{message.message}}</span>
3333
</p>
34-
<mat-divider [inset]="true" *ngIf="!last"></mat-divider>
34+
<mat-divider inset *ngIf="!last"></mat-divider>
3535
</mat-list-item>
3636
<mat-divider></mat-divider>
3737
<mat-list-item *ngFor="let message of messages">
@@ -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 *ngIf="!last"></mat-divider>
9495
</a>
9596
</mat-nav-list>
9697
<mat-nav-list dense>

src/lib/divider/divider.scss

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
$mat-divider-width: 1px;
22
$mat-divider-inset-margin: 80px;
33

4+
// This mixin provides the correct offset for an inset divider based on the
5+
// size of the parent class (e.g. avatar vs icon)
6+
@mixin mat-inset-divider-offset($offset) {
7+
$mat-list-item-inset-divider-offset: #{(2 * $mat-list-side-padding) + $offset};
8+
margin-left: $mat-list-item-inset-divider-offset;
9+
width: calc(100% - #{$mat-list-item-inset-divider-offset});
10+
11+
[dir='rtl'] & {
12+
margin-left: auto;
13+
margin-right: $mat-list-item-inset-divider-offset;
14+
}
15+
}
16+
417
.mat-divider {
518
display: block;
619
margin: 0;

src/lib/list/list.scss

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
@import '../core/style/variables';
22
@import '../core/style/list-common';
33
@import '../core/style/layout-common';
4+
@import '../divider/divider';
45

56

67
$mat-list-side-padding: 16px;
8+
$mat-list-icon-padding: 4px;
79
$mat-list-avatar-size: 40px;
810

911
// Normal list variables
@@ -27,8 +29,6 @@ $mat-dense-three-line-height: 76px;
2729
$mat-dense-multi-line-padding: 16px;
2830
$mat-dense-list-icon-size: 20px;
2931

30-
$mat-list-item-inset-divider-offset: 72px;
31-
3232
// This mixin provides all list-item styles, changing font size and height
3333
// based on whether the list is in dense mode.
3434
@mixin mat-list-item-base($base-height, $avatar-height, $two-line-height,
@@ -108,6 +108,10 @@ $mat-list-item-inset-divider-offset: 72px;
108108
width: $mat-list-avatar-size;
109109
height: $mat-list-avatar-size;
110110
border-radius: 50%;
111+
112+
~ .mat-divider-inset {
113+
@include mat-inset-divider-offset($mat-list-avatar-size);
114+
}
111115
}
112116

113117
.mat-list-icon {
@@ -116,29 +120,23 @@ $mat-list-item-inset-divider-offset: 72px;
116120
font-size: $icon-size;
117121
box-sizing: content-box;
118122
border-radius: 50%;
119-
padding: 4px;
123+
padding: $mat-list-icon-padding;
124+
125+
~ .mat-divider-inset {
126+
@include mat-inset-divider-offset($icon-size + (2 * $mat-list-icon-padding));
127+
}
120128
}
121129

122130
.mat-divider {
123-
position: absolute;
131+
position: absolute !important; // this is done to override card inset styles
124132
bottom: 0;
125133
left: 0;
126134
width: 100%;
135+
margin: 0;
127136

128137
[dir='rtl'] & {
129-
left: auto;
130-
right: 0;
131-
}
132-
133-
&.mat-divider-inset {
134-
left: $mat-list-item-inset-divider-offset;
135-
width: calc(100% - #{$mat-list-item-inset-divider-offset});
136-
margin: 0;
137-
138-
[dir='rtl'] & {
139-
left: auto;
140-
right: $mat-list-item-inset-divider-offset;
141-
}
138+
margin-left: auto;
139+
margin-right: 0;
142140
}
143141
}
144142
}

0 commit comments

Comments
 (0)