mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
fix(list): ensure multi-line lists expand to fill space (#1466)
This commit is contained in:
@@ -30,12 +30,15 @@ export class MdLineSetter {
|
||||
this._resetClasses();
|
||||
if (count === 2 || count === 3) {
|
||||
this._setClass(`md-${count}-line`, true);
|
||||
} else if (count > 3) {
|
||||
this._setClass(`md-multi-line`, true);
|
||||
}
|
||||
}
|
||||
|
||||
private _resetClasses(): void {
|
||||
this._setClass('md-2-line', false);
|
||||
this._setClass('md-3-line', false);
|
||||
this._setClass('md-multi-line', false);
|
||||
}
|
||||
|
||||
private _setClass(className: string, bool: boolean): void {
|
||||
|
||||
@@ -50,10 +50,18 @@ $md-dense-three-line-height: 76px;
|
||||
height: $two-line-height;
|
||||
}
|
||||
|
||||
|
||||
&.md-3-line .md-list-item {
|
||||
height: $three-line-height;
|
||||
}
|
||||
|
||||
// list items with more than 3 lines should expand to match
|
||||
// the height of its contained text
|
||||
&.md-multi-line .md-list-item {
|
||||
height: 100%;
|
||||
padding: 8px $md-list-side-padding;
|
||||
}
|
||||
|
||||
.md-list-text {
|
||||
@include md-line-wrapper-base();
|
||||
padding: 0 $md-list-side-padding;
|
||||
|
||||
@@ -18,6 +18,7 @@ describe('MdList', () => {
|
||||
ListWithItemWithCssClass,
|
||||
ListWithDynamicNumberOfLines,
|
||||
ListWithMultipleItems,
|
||||
ListWithManyLines,
|
||||
],
|
||||
});
|
||||
|
||||
@@ -65,6 +66,15 @@ describe('MdList', () => {
|
||||
expect(listItems[1].nativeElement.className).toBe('md-3-line');
|
||||
});
|
||||
|
||||
it('should apply md-multi-line class to lists with more than 3 lines', () => {
|
||||
let fixture = TestBed.createComponent(ListWithManyLines);
|
||||
fixture.detectChanges();
|
||||
|
||||
let listItems = fixture.debugElement.children[0].queryAll(By.css('md-list-item'));
|
||||
expect(listItems[0].nativeElement.className).toBe('md-multi-line');
|
||||
expect(listItems[1].nativeElement.className).toBe('md-multi-line');
|
||||
});
|
||||
|
||||
it('should apply md-list-avatar class to list items with avatars', () => {
|
||||
let fixture = TestBed.createComponent(ListWithAvatar);
|
||||
fixture.detectChanges();
|
||||
@@ -152,6 +162,17 @@ class ListWithTwoLineItem extends BaseTestList { }
|
||||
</md-list>`})
|
||||
class ListWithThreeLineItem extends BaseTestList { }
|
||||
|
||||
@Component({template: `
|
||||
<md-list>
|
||||
<md-list-item *ngFor="let item of items">
|
||||
<h3 md-line>Line 1</h3>
|
||||
<p md-line>Line 2</p>
|
||||
<p md-line>Line 3</p>
|
||||
<p md-line>Line 4</p>
|
||||
</md-list-item>
|
||||
</md-list>`})
|
||||
class ListWithManyLines extends BaseTestList { }
|
||||
|
||||
@Component({template: `
|
||||
<md-list>
|
||||
<md-list-item>
|
||||
|
||||
Reference in New Issue
Block a user