Skip to content

Commit

Permalink
fix(list): ensure multi-line lists expand to fill space (#1466)
Browse files Browse the repository at this point in the history
  • Loading branch information
kara authored Oct 11, 2016
1 parent 0b5b6f2 commit e7b872a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/lib/core/line/line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions src/lib/list/list.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
21 changes: 21 additions & 0 deletions src/lib/list/list.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe('MdList', () => {
ListWithItemWithCssClass,
ListWithDynamicNumberOfLines,
ListWithMultipleItems,
ListWithManyLines,
],
});

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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>
Expand Down

0 comments on commit e7b872a

Please sign in to comment.