-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(divider): move divider out of mat-list #5862
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,22 @@ $mat-card-header-size: 40px !default; | |
padding: $mat-card-default-padding; | ||
border-radius: $mat-card-border-radius; | ||
|
||
.mat-divider { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you separate the attributes from the rules here? .mat-divider {
position: absolute;
left: 0;
width: 100%;
[dir='rtl'] & {
left: auto;
right: 0;
}
&.mat-divider-inset {
position: static;
margin: 0;
}
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
position: absolute; | ||
left: 0; | ||
width: 100%; | ||
|
||
[dir='rtl'] & { | ||
left: auto; | ||
right: 0; | ||
} | ||
|
||
&.mat-divider-inset { | ||
position: static; | ||
margin: 0; | ||
} | ||
} | ||
|
||
@include cdk-high-contrast { | ||
outline: solid 1px; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Please see the official documentation at https://material.angular.io/components/component/divider |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
@import '../core/theming/palette'; | ||
@import '../core/theming/theming'; | ||
|
||
|
||
@mixin mat-divider-theme($theme) { | ||
$foreground: map-get($theme, foreground); | ||
|
||
.mat-divider { | ||
border-top-color: mat-color($foreground, divider); | ||
} | ||
|
||
.mat-divider-vertical { | ||
border-right-color: mat-color($foreground, divider); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {NgModule} from '@angular/core'; | ||
import {CommonModule} from '@angular/common'; | ||
import {MatCommonModule} from '@angular/material/core'; | ||
import {MatDivider} from './divider'; | ||
|
||
|
||
@NgModule({ | ||
imports: [MatCommonModule, CommonModule], | ||
exports: [ | ||
MatDivider, | ||
MatCommonModule, | ||
], | ||
declarations: [ | ||
MatDivider, | ||
], | ||
}) | ||
export class MatDividerModule {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
`<mat-divider>` is a component that allows for Material styling of a line separator with various orientation options. | ||
|
||
<!-- example(divider-overview) --> | ||
|
||
|
||
### Simple divider | ||
|
||
A `<mat-divider>` element can be used on its own to create a horizontal or vertical line styled with a Material theme | ||
|
||
```html | ||
<mat-divider></mat-divider> | ||
``` | ||
|
||
### Inset divider | ||
|
||
Add the `inset` attribute in order to set whether or not the divider is an inset divider. | ||
|
||
```html | ||
<mat-divider [inset]="true"></mat-divider> | ||
``` | ||
|
||
### Vertical divider | ||
|
||
Add the `vertical` attribute in order to set whether or not the divider is vertically-oriented. | ||
|
||
```html | ||
<mat-divider [vertical]="true"></mat-divider> | ||
``` | ||
|
||
|
||
### Lists with inset dividers | ||
|
||
Dividers can be added to lists as a means of separating content into distinct sections. | ||
Inset dividers can also be added to provide the appearance of distinct elements in a list without cluttering content | ||
like avatar images or icons. Make sure to avoid adding an inset divider to the last element | ||
in a list, because it will overlap with the section divider. | ||
|
||
```html | ||
<mat-list> | ||
<h3 mat-subheader>Folders</h3> | ||
<mat-list-item *ngFor="let folder of folders; last as last"> | ||
<mat-icon mat-list-icon>folder</mat-icon> | ||
<h4 mat-line>{{folder.name}}</h4> | ||
<p mat-line class="demo-2"> {{folder.updated}} </p> | ||
<mat-divider [inset]="true" *ngIf="!last"></mat-divider> | ||
</mat-list-item> | ||
<mat-divider></mat-divider> | ||
<h3 md-subheader>Notes</h3> | ||
<mat-list-item *ngFor="let note of notes"> | ||
<mat-icon md-list-icon>note</mat-icon> | ||
<h4 md-line>{{note.name}}</h4> | ||
<p md-line class="demo-2"> {{note.updated}} </p> | ||
</mat-list-item> | ||
</mat-list> | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
$mat-divider-width: 1px; | ||
$mat-divider-inset-margin: 80px; | ||
|
||
.mat-divider { | ||
display: block; | ||
margin: 0; | ||
border-top-width: $mat-divider-width; | ||
border-top-style: solid; | ||
|
||
&.mat-divider-vertical { | ||
border-top: 0; | ||
border-right-width: $mat-divider-width; | ||
border-right-style: solid; | ||
} | ||
|
||
&.mat-divider-inset { | ||
margin-left: $mat-divider-inset-margin; | ||
[dir='rtl'] & { | ||
margin-left: auto; | ||
margin-right: $mat-divider-inset-margin; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import {async, ComponentFixture, TestBed} from '@angular/core/testing'; | ||
import {Component} from '@angular/core'; | ||
import {By} from '@angular/platform-browser'; | ||
import {MatDividerModule} from './divider-module'; | ||
|
||
|
||
describe('MatDivider', () => { | ||
|
||
let fixture: ComponentFixture<MatDividerTestComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [MatDividerModule], | ||
declarations: [ | ||
MatDividerTestComponent | ||
], | ||
}); | ||
|
||
TestBed.compileComponents(); | ||
fixture = TestBed.createComponent(MatDividerTestComponent); | ||
})); | ||
|
||
it('should apply vertical class to vertical divider', () => { | ||
fixture.componentInstance.vertical = true; | ||
fixture.detectChanges(); | ||
|
||
const divider = fixture.debugElement.query(By.css('mat-divider')); | ||
expect(divider.nativeElement.className).toContain('mat-divider'); | ||
expect(divider.nativeElement.className).toContain('mat-divider-vertical'); | ||
}); | ||
|
||
it('should apply inset class to inset divider', () => { | ||
fixture.componentInstance.inset = true; | ||
fixture.detectChanges(); | ||
|
||
const divider = fixture.debugElement.query(By.css('mat-divider')); | ||
expect(divider.nativeElement.className).toContain('mat-divider'); | ||
expect(divider.nativeElement.className).toContain('mat-divider-inset'); | ||
}); | ||
|
||
it('should apply inset and vertical classes to vertical inset divider', () => { | ||
fixture.componentInstance.vertical = true; | ||
fixture.componentInstance.inset = true; | ||
fixture.detectChanges(); | ||
|
||
const divider = fixture.debugElement.query(By.css('mat-divider')); | ||
expect(divider.nativeElement.className).toContain('mat-divider'); | ||
expect(divider.nativeElement.className).toContain('mat-divider-inset'); | ||
expect(divider.nativeElement.className).toContain('mat-divider-vertical'); | ||
}); | ||
|
||
it('should add aria roles properly', () => { | ||
fixture.detectChanges(); | ||
|
||
const divider = fixture.debugElement.query(By.css('mat-divider')); | ||
expect(divider.nativeElement.getAttribute('role')).toBe('separator'); | ||
}); | ||
}); | ||
|
||
@Component({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rather than creating a number of Components that have to be recompiled on every run, can you create a single Component that is altered through attributes for tests? We have found a bottleneck in our tests comes from having to recompile many components on each test run. @Component({
template: `<mat-divider [inset]="inset" [vertical]="vertical"></mat-divider>`
})
class MatDividerTestComponent {
vertical: boolean;
inset: boolean;
} Then in tests you would do: it('should apply a vertical class', () => {
fixture.componentInstance.vertical = true;
fixture.detechChanges();
expect(divider.nativeElement.className).toContain('mat-divider-vertical');
}); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great suggestions, added |
||
template: `<mat-divider [vertical]="vertical" [inset]="inset"></mat-divider>` | ||
}) | ||
class MatDividerTestComponent { | ||
vertical: boolean; | ||
inset: boolean; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {ChangeDetectionStrategy, Component, Input, ViewEncapsulation} from '@angular/core'; | ||
import {coerceBooleanProperty} from '@angular/cdk/coercion'; | ||
|
||
@Component({ | ||
moduleId: module.id, | ||
selector: 'mat-divider', | ||
host: { | ||
'role': 'separator', | ||
'[attr.aria-orientation]': 'vertical ? "vertical" : "horizontal"', | ||
'[class.mat-divider-vertical]': 'vertical', | ||
'[class.mat-divider-inset]': 'inset', | ||
'class': 'mat-divider' | ||
}, | ||
template: '', | ||
styleUrls: ['divider.css'], | ||
encapsulation: ViewEncapsulation.None, | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
preserveWhitespaces: false, | ||
}) | ||
export class MatDivider { | ||
/** Whether the divider is vertically aligned. */ | ||
@Input() get vertical(): boolean { return this._vertical; } | ||
set vertical(value: boolean) { this._vertical = coerceBooleanProperty(value); } | ||
private _vertical: boolean = false; | ||
|
||
/** Whether the divider is an inset divider. */ | ||
@Input() get inset(): boolean { return this._inset; } | ||
set inset(value: boolean) { this._inset = coerceBooleanProperty(value); } | ||
private _inset: boolean = false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You forgot to bind
last
to a local variable:*ngFor="let message of messages; last as last"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added, this got cut from a previous commit when rebased, good catch