Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/list/list-item.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="md-list-item">
<div class="md-list-item" [class.md-list-item-focus]="hasFocus">
<ng-content select="[md-list-avatar],[md-list-icon]"></ng-content>
<div class="md-list-text"><ng-content select="[md-line]"></ng-content></div>
<ng-content></ng-content>
</div>
</div>
10 changes: 5 additions & 5 deletions src/components/list/list.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ $md-dense-avatar-height: 48px;
$md-dense-two-line-height: 60px;
$md-dense-three-line-height: 76px;

/*
/*
This mixin provides all list-item styles, changing font size and height
based on whether the list is in dense mode.
*/
@mixin md-list-item-base($font-size, $base-height, $avatar-height,
@mixin md-list-item-base($font-size, $base-height, $avatar-height,
$two-line-height, $three-line-height) {

.md-list-item {
Expand Down Expand Up @@ -94,7 +94,7 @@ based on whether the list is in dense mode.
}

/*
This mixin provides all md-line styles, changing secondary font size
This mixin provides all md-line styles, changing secondary font size
based on whether the list is in dense mode.
*/
@mixin md-line-base($secondary-font-size) {
Expand Down Expand Up @@ -201,8 +201,8 @@ md-nav-list {
.md-list-item {
cursor: pointer;

&:hover {
&:hover, &.md-list-item-focus {
background: md-color($md-background, 'hover');
}
}
}
}
27 changes: 26 additions & 1 deletion src/components/list/list.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {TestComponentBuilder} from '@angular/compiler/testing';
import {Component} from '@angular/core';
import {By} from '@angular/platform-browser';

import {MD_LIST_DIRECTIVES} from './list';
import {MD_LIST_DIRECTIVES, MdListItem} from './list';

describe('MdList', () => {
let builder: TestComponentBuilder;
Expand All @@ -18,6 +18,31 @@ describe('MdList', () => {
builder = tcb;
}));

it('should add and remove focus class on focus/blur', () => {
var template = `
<md-list>
<a md-list-item>
Paprika
</a>
</md-list>
`;
return builder.overrideTemplate(TestList, template)
.createAsync(TestList).then((fixture) => {
let listItem = fixture.debugElement.query(By.directive(MdListItem));
let listItemDiv = fixture.debugElement.query(By.css('.md-list-item'));
fixture.detectChanges();
expect(listItemDiv.nativeElement.classList).not.toContain('md-list-item-focus');

listItem.componentInstance.handleFocus();
fixture.detectChanges();
expect(listItemDiv.nativeElement.classList).toContain('md-list-item-focus');

listItem.componentInstance.handleBlur();
fixture.detectChanges();
expect(listItemDiv.nativeElement.classList).not.toContain('md-list-item-focus');
});
});

it('should not apply any class to a list without lines', (done: () => void) => {
var template = `
<md-list>
Expand Down
19 changes: 18 additions & 1 deletion src/components/list/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,20 @@ export class MdListAvatar {}
@Component({
moduleId: module.id,
selector: 'md-list-item, a[md-list-item]',
host: {'role': 'listitem'},
host: {
'role': 'listitem',
'(focus)': 'handleFocus()',
'(blur)': 'handleBlur()',
},
templateUrl: 'list-item.html',
encapsulation: ViewEncapsulation.None
})
export class MdListItem implements AfterContentInit {
@ContentChildren(MdLine) _lines: QueryList<MdLine>;

/** @internal */
hasFocus: boolean = false;

/** @internal */
ngAfterContentInit() {
this._setLineClass(this._lines.length);
Expand All @@ -56,6 +63,16 @@ export class MdListItem implements AfterContentInit {

constructor(private _renderer: Renderer, private _element: ElementRef) {}

/** @internal */
handleFocus() {
this.hasFocus = true;
}

/** @internal */
handleBlur() {
this.hasFocus = false;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unit test for focus class?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

On Mon, May 23, 2016 at 3:42 PM, Jeremy Elbourn [email protected]
wrote:

In src/components/list/list.ts
#502 (comment):

@@ -56,6 +63,16 @@ export class MdListItem implements AfterContentInit {

constructor(private _renderer: Renderer, private _element: ElementRef) {}

  • /** @internal */
  • handleFocus() {
  • this.hasFocus = true;
  • }
  • /** @internal */
  • handleBlur() {
  • this.hasFocus = false;
  • }

Unit test for focus class?


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub
https://github.com/angular/material2/pull/502/files/bbda787d2d2385175e953d24ba093c5ca3dd51ed#r64302059

private _setLineClass(count: number): void {
this._resetClasses();
if (count === 2 || count === 3) {
Expand Down