Skip to content

Commit 06dd188

Browse files
committed
feat(divider): move divider out of mat-list
- Creates an independent mat-divider component - Adds inset capability with special accomodations for mat-list-item - Adds vertical option - Removed mat-divider from MatListModule with temporary import to prevent breaking changes - Added styling for dividers in cards
1 parent 291a87c commit 06dd188

25 files changed

+408
-39
lines changed

src/demo-app/card/card-demo.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,23 @@
2727
</mat-card-footer>
2828
</mat-card>
2929

30+
<mat-card>
31+
<mat-card-subtitle>Subtitle</mat-card-subtitle>
32+
<mat-card-title>Card with title, footer, and inset-divider</mat-card-title>
33+
<mat-card-content>
34+
<p>This is supporting text.</p>
35+
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
36+
</mat-card-content>
37+
<mat-divider [inset]="true"></mat-divider>
38+
<mat-card-actions>
39+
<button md-button>LIKE</button>
40+
<button md-button>SHARE</button>
41+
</mat-card-actions>
42+
<mat-card-footer>
43+
<mat-progress-bar mode="indeterminate"></mat-progress-bar>
44+
</mat-card-footer>
45+
</mat-card>
46+
3047
<mat-card>
3148
<img mat-card-image src="https://material.angularjs.org/latest/img/washedout.png">
3249
<mat-card-title>Content Title</mat-card-title>

src/demo-app/demo-material-module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
MatChipsModule,
99
MatDatepickerModule,
1010
MatDialogModule,
11+
MatDividerModule,
1112
MatExpansionModule,
1213
MatFormFieldModule,
1314
MatGridListModule,
@@ -54,6 +55,7 @@ import {PortalModule} from '@angular/cdk/portal';
5455
MatTableModule,
5556
MatDatepickerModule,
5657
MatDialogModule,
58+
MatDividerModule,
5759
MatExpansionModule,
5860
MatFormFieldModule,
5961
MatGridListModule,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +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>
3435
</mat-list-item>
3536
<mat-divider></mat-divider>
3637
<mat-list-item *ngFor="let message of messages">

src/demo-app/system-config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ System.config({
5454
'@angular/material/core': 'dist/packages/material/core/index.js',
5555
'@angular/material/datepicker': 'dist/packages/material/datepicker/index.js',
5656
'@angular/material/dialog': 'dist/packages/material/dialog/index.js',
57+
'@angular/material/divider': 'dist/packages/material/divider/index.js',
5758
'@angular/material/expansion': 'dist/packages/material/expansion/index.js',
5859
'@angular/material/form-field': 'dist/packages/material/form-field/index.js',
5960
'@angular/material/grid-list': 'dist/packages/material/grid-list/index.js',

src/e2e-app/e2e-app-module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
MatButtonModule,
2424
MatCheckboxModule,
2525
MatDialogModule,
26+
MatDividerModule,
2627
MatFormFieldModule,
2728
MatGridListModule,
2829
MatIconModule,
@@ -50,6 +51,7 @@ import {ReactiveFormsModule} from '@angular/forms';
5051
MatButtonModule,
5152
MatCheckboxModule,
5253
MatDialogModule,
54+
MatDividerModule,
5355
MatFormFieldModule,
5456
MatGridListModule,
5557
MatIconModule,

src/e2e-app/system-config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ System.config({
5353
'@angular/material/core': 'dist/bundles/material-core.umd.js',
5454
'@angular/material/datepicker': 'dist/bundles/material-datepicker.umd.js',
5555
'@angular/material/dialog': 'dist/bundles/material-dialog.umd.js',
56+
'@angular/material/divider': 'dist/bundles/material-divider.umd.js',
5657
'@angular/material/expansion': 'dist/bundles/material-expansion.umd.js',
5758
'@angular/material/form-field': 'dist/bundles/material-form-field.umd.js',
5859
'@angular/material/grid-list': 'dist/bundles/material-grid-list.umd.js',

src/lib/core/theming/_all-theme.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
@import '../../table/table-theme';
1010
@import '../../datepicker/datepicker-theme';
1111
@import '../../dialog/dialog-theme';
12+
@import '../../divider/divider-theme';
1213
@import '../../expansion/expansion-theme';
1314
@import '../../grid-list/grid-list-theme';
1415
@import '../../icon/icon-theme';
@@ -43,6 +44,7 @@
4344
@include mat-table-theme($theme);
4445
@include mat-datepicker-theme($theme);
4546
@include mat-dialog-theme($theme);
47+
@include mat-divider-theme($theme);
4648
@include mat-expansion-panel-theme($theme);
4749
@include mat-form-field-theme($theme);
4850
@include mat-grid-list-theme($theme);

src/lib/divider/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Please see the official documentation at https://material.angular.io/components/component/divider

src/lib/divider/_divider-theme.scss

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
@import '../core/theming/palette';
2+
@import '../core/theming/theming';
3+
4+
5+
@mixin mat-divider-theme($theme) {
6+
$foreground: map-get($theme, foreground);
7+
8+
.mat-divider {
9+
border-top-color: mat-color($foreground, divider);
10+
}
11+
12+
.mat-divider-vertical {
13+
border-right-color: mat-color($foreground, divider);
14+
}
15+
}

src/lib/divider/divider-module.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {NgModule} from '@angular/core';
10+
import {MatCommonModule} from '@angular/material/core';
11+
import {
12+
MatDivider,
13+
MatDividerCssMatStyler,
14+
} from './divider';
15+
import {CommonModule} from '@angular/common';
16+
17+
18+
@NgModule({
19+
imports: [MatCommonModule, CommonModule],
20+
exports: [
21+
MatDivider,
22+
MatDividerCssMatStyler,
23+
MatCommonModule,
24+
],
25+
declarations: [
26+
MatDivider,
27+
MatDividerCssMatStyler,
28+
],
29+
})
30+
export class MatDividerModule {}

src/lib/divider/divider.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
`<md-divider>` is a container component that wraps and formats a series of line items. As the base
2+
list component, it provides Material Design styling, but no behavior of its own.
3+
4+
<!-- example(divider-overview) -->
5+
6+
7+
### Simple divider
8+
9+
An `<md-divider>` element can be used on its own to create a vertical line styled with a Material theme
10+
11+
```html
12+
<md-divider></md-divider>
13+
```
14+
15+
Here are the available global options:
16+
17+
| Name | Type | Values | Description |
18+
| --------------- | ------- | ----------- | ----------------------------------------- |
19+
| inset | boolean | true, false | Whether the divider is an inset divider |
20+
| vertical | boolean | true, false | Whether the divider is a vertical divider |
21+
22+
23+
### Inset divider
24+
25+
Add the `inset` attribute in order to set whether or not the divider is an inset divider.
26+
27+
```html
28+
<md-divider [inset]="true"></md-divider>
29+
```
30+
31+
### Vertical divider
32+
33+
Add the `vertical` attribute in order to set whether or not the divider is vertically-oriented.
34+
35+
```html
36+
<md-divider [vertical]="true"></md-divider>
37+
```
38+
39+
40+
### Lists with inset dividers
41+
42+
Dividers can be added to lists as a means of separating content into distinct sections.
43+
Inset dividers can also be added to provide the appearance of distinct elements in a list without cluttering content
44+
like avatar images or icons. If combining both, please make sure to avoid adding an inset divider to the last element
45+
in a list, because it will overlap with the section divider.
46+
47+
```html
48+
<md-list>
49+
<h3 md-subheader>Folders</h3>
50+
<md-list-item *ngFor="let folder of folders; last as last">
51+
<md-icon md-list-icon>folder</md-icon>
52+
<h4 md-line>{{folder.name}}</h4>
53+
<p md-line class="demo-2"> {{folder.updated}} </p>
54+
<md-divider [inset]="true" *ngIf="!last"></md-divider>
55+
</md-list-item>
56+
<md-divider></md-divider>
57+
<h3 md-subheader>Notes</h3>
58+
<md-list-item *ngFor="let note of notes">
59+
<md-icon md-list-icon>note</md-icon>
60+
<h4 md-line>{{note.name}}</h4>
61+
<p md-line class="demo-2"> {{note.updated}} </p>
62+
</md-list-item>
63+
</md-list>
64+
```

src/lib/divider/divider.scss

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
.mat-divider {
2+
display: block;
3+
margin: 0;
4+
border-top-width: 1px;
5+
border-top-style: solid;
6+
7+
&.mat-divider-vertical {
8+
border-top: 0;
9+
border-right-width: 1px;
10+
border-right-style: solid;
11+
position: static !important;
12+
width: auto !important;
13+
}
14+
15+
&.mat-divider-inset {
16+
margin-left: 80px;
17+
[dir='rtl'] & {
18+
margin-left: auto;
19+
margin-right: 80px;
20+
}
21+
}
22+
}
23+
24+
.mat-list-item {
25+
.mat-divider {
26+
position: absolute;
27+
bottom: 0;
28+
29+
left: 0;
30+
[dir='rtl'] & {
31+
left: auto;
32+
right: 0;
33+
}
34+
35+
width: 100%;
36+
&.mat-divider-inset {
37+
left: 72px;
38+
[dir='rtl'] & {
39+
left: auto;
40+
right: 72px;
41+
}
42+
43+
width: calc(100% - 72px);
44+
margin: 0 !important;
45+
}
46+
}
47+
}
48+
49+
.mat-card {
50+
.mat-divider {
51+
position: absolute;
52+
53+
left: 0;
54+
[dir='rtl'] & {
55+
left: auto;
56+
right: 0;
57+
}
58+
59+
width: 100%;
60+
61+
&.mat-divider-inset {
62+
position: static;
63+
margin: 0 !important;
64+
}
65+
}
66+
}

src/lib/divider/divider.spec.ts

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import {async, TestBed} from '@angular/core/testing';
2+
import {Component} from '@angular/core';
3+
import {By} from '@angular/platform-browser';
4+
import {MatDividerModule} from './divider-module';
5+
6+
7+
describe('MatDivider', () => {
8+
9+
beforeEach(async(() => {
10+
TestBed.configureTestingModule({
11+
imports: [MatDividerModule],
12+
declarations: [
13+
MatDividerBase,
14+
MatDividerVertical,
15+
MatDividerInset,
16+
MatDividerVerticalInset,
17+
MatDividerWithCssClass,
18+
],
19+
});
20+
21+
TestBed.compileComponents();
22+
}));
23+
24+
it('should not apply any additional class to a list without lines', () => {
25+
let fixture = TestBed.createComponent(MatDividerBase);
26+
let divider = fixture.debugElement.query(By.css('mat-divider'));
27+
fixture.detectChanges();
28+
expect(divider.nativeElement.className).toBe('mat-divider');
29+
});
30+
31+
it('should apply vertical class to vertical divider', () => {
32+
let fixture = TestBed.createComponent(MatDividerVertical);
33+
fixture.detectChanges();
34+
35+
let divider = fixture.debugElement.query(By.css('mat-divider'));
36+
expect(divider.nativeElement.className).toContain('mat-divider');
37+
expect(divider.nativeElement.className).toContain('mat-divider-vertical');
38+
});
39+
40+
it('should apply inset class to inset divider', () => {
41+
let fixture = TestBed.createComponent(MatDividerInset);
42+
fixture.detectChanges();
43+
44+
let divider = fixture.debugElement.query(By.css('mat-divider'));
45+
expect(divider.nativeElement.className).toContain('mat-divider');
46+
expect(divider.nativeElement.className).toContain('mat-divider-inset');
47+
});
48+
49+
it('should apply inset and vertical classes to vertical inset divider', () => {
50+
let fixture = TestBed.createComponent(MatDividerVerticalInset);
51+
fixture.detectChanges();
52+
53+
let divider = fixture.debugElement.query(By.css('mat-divider'));
54+
expect(divider.nativeElement.className).toContain('mat-divider');
55+
expect(divider.nativeElement.className).toContain('mat-divider-inset');
56+
expect(divider.nativeElement.className).toContain('mat-divider-vertical');
57+
});
58+
59+
it('should not clear custom classes provided by user', () => {
60+
let fixture = TestBed.createComponent(MatDividerWithCssClass);
61+
fixture.detectChanges();
62+
63+
let divider = fixture.debugElement.query(By.css('mat-divider'));
64+
expect(divider.nativeElement.classList.contains('test-class')).toBe(true);
65+
});
66+
67+
it('should add aria roles properly', () => {
68+
let fixture = TestBed.createComponent(MatDividerBase);
69+
fixture.detectChanges();
70+
71+
let divider = fixture.debugElement.query(By.css('mat-divider'));
72+
expect(divider.nativeElement.getAttribute('role')).toBe('separator');
73+
});
74+
});
75+
76+
@Component({
77+
template: `<mat-divider></mat-divider>`
78+
})
79+
class MatDividerBase { }
80+
81+
@Component({
82+
template: `<mat-divider [vertical]="true"></mat-divider>`
83+
})
84+
class MatDividerVertical { }
85+
86+
@Component({
87+
template: `<mat-divider [inset]="true"></mat-divider>`
88+
})
89+
class MatDividerInset { }
90+
91+
@Component({
92+
template: `<mat-divider [vertical]="true" [inset]="true"></mat-divider>`
93+
})
94+
class MatDividerVerticalInset { }
95+
96+
@Component({
97+
template: `<mat-divider class="test-class"></mat-divider>`
98+
})
99+
class MatDividerWithCssClass { }

0 commit comments

Comments
 (0)