Skip to content

Commit

Permalink
fix(selection-list): proper style for disabled options (#6829)
Browse files Browse the repository at this point in the history
* No longer shows ripples if md-list-option is disabled
* Properly shows disabled style for disabled md-list-option (the `mat-list-item-disabled` class has been already added as part of the selection list PR)
  • Loading branch information
devversion authored and tinayuangao committed Sep 6, 2017
1 parent c564df6 commit 547d11f
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
55 changes: 55 additions & 0 deletions src/lib/list/selection-list.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,52 @@ describe('MdSelectionList', () => {
});
});

describe('with option disabled', () => {
let fixture: ComponentFixture<SelectionListWithDisabledOption>;
let listOptionEl: HTMLElement;
let listOption: MdListOption;

beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [MdListModule],
declarations: [SelectionListWithDisabledOption]
});

TestBed.compileComponents();
}));

beforeEach(async(() => {
fixture = TestBed.createComponent(SelectionListWithDisabledOption);

const listOptionDebug = fixture.debugElement.query(By.directive(MdListOption));

listOption = listOptionDebug.componentInstance;
listOptionEl = listOptionDebug.nativeElement;

fixture.detectChanges();
}));

it('should disable ripples for disabled option', () => {
expect(listOption._isRippleDisabled())
.toBe(false, 'Expected ripples to be enabled by default');

fixture.componentInstance.disableItem = true;
fixture.detectChanges();

expect(listOption._isRippleDisabled())
.toBe(true, 'Expected ripples to be disabled if option is disabled');
});

it('should apply the "mat-list-item-disabled" class properly', () => {
expect(listOptionEl.classList).not.toContain('mat-list-item-disabled');

fixture.componentInstance.disableItem = true;
fixture.detectChanges();

expect(listOptionEl.classList).toContain('mat-list-item-disabled');
});
});

describe('with list disabled', () => {
let fixture: ComponentFixture<SelectionListWithListDisabled>;
let listOption: DebugElement[];
Expand Down Expand Up @@ -363,6 +409,15 @@ class SelectionListWithCheckboxPositionAfter {
class SelectionListWithListDisabled {
}

@Component({template: `
<mat-selection-list>
<md-list-option [disabled]="disableItem">Item</md-list-option>
</mat-selection-list>
`})
class SelectionListWithDisabledOption {
disableItem: boolean = false;
}

@Component({template: `
<mat-selection-list id = "selection-list-4">
<md-list-option checkboxPosition = "after" class="test-focus" id="123">
Expand Down
3 changes: 2 additions & 1 deletion src/lib/list/selection-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const FOCUSED_STYLE: string = 'mat-list-item-focus';
'(blur)': '_handleBlur()',
'(click)': '_handleClick()',
'tabindex': '-1',
'[class.mat-list-item-disabled]': 'disabled',
'[attr.aria-selected]': 'selected.toString()',
'[attr.aria-disabled]': 'disabled.toString()',
},
Expand Down Expand Up @@ -148,7 +149,7 @@ export class MdListOption extends _MdListOptionMixinBase

/** Whether this list item should show a ripple effect when clicked. */
_isRippleDisabled() {
return this.disableRipple || this.selectionList.disableRipple;
return this.disabled || this.disableRipple || this.selectionList.disableRipple;
}

_handleClick() {
Expand Down

0 comments on commit 547d11f

Please sign in to comment.