Skip to content

Commit fbce67d

Browse files
devversionjelbourn
authored andcommitted
refactor(selection-list): use disable-ripple mixin (#6692)
* Switches the `disableRipple` getter/setter with the `disableRipple` mixin from core. * Prefixes the `isRippleEnabled` method with an underscore to hide it from the API docs. * Switch `isRippleEnabled` to `_isRippleDisabled`
1 parent 82e14f8 commit fbce67d

File tree

5 files changed

+25
-35
lines changed

5 files changed

+25
-35
lines changed

src/lib/list/list-item.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div class="mat-list-item-content">
22
<div class="mat-list-item-ripple" md-ripple
33
[mdRippleTrigger]="_getHostElement()"
4-
[mdRippleDisabled]="!isRippleEnabled()">
4+
[mdRippleDisabled]="_isRippleDisabled()">
55
</div>
66

77
<ng-content

src/lib/list/list-option.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div class="mat-list-item-content" [class.mat-list-item-content-reverse]="checkboxPosition == 'after'" [class.mat-list-item-disabled]="disabled">
22
<div class="mat-list-item-ripple" md-ripple
33
[mdRippleTrigger]="_getHostElement()"
4-
[mdRippleDisabled]="!isRippleEnabled()">
4+
[mdRippleDisabled]="_isRippleDisabled()">
55
</div>
66

77
<md-pseudo-checkbox [state]="selected ? 'checked' : 'unchecked'" #autocheckbox [disabled]="disabled"></md-pseudo-checkbox>

src/lib/list/list.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ describe('MdList', () => {
125125

126126
const items: QueryList<MdListItem> = fixture.debugElement.componentInstance.listItems;
127127
expect(items.length).toBeGreaterThan(0);
128-
items.forEach(item => expect(item.isRippleEnabled()).toBe(false));
128+
items.forEach(item => expect(item._isRippleDisabled()).toBe(true));
129129
});
130130

131131
it('should allow disabling ripples for specific nav-list items', () => {
@@ -136,12 +136,12 @@ describe('MdList', () => {
136136
expect(items.length).toBeGreaterThan(0);
137137

138138
// Ripples should be enabled by default, and can be disabled with a binding.
139-
items.forEach(item => expect(item.isRippleEnabled()).toBe(true));
139+
items.forEach(item => expect(item._isRippleDisabled()).toBe(false));
140140

141141
fixture.componentInstance.disableItemRipple = true;
142142
fixture.detectChanges();
143143

144-
items.forEach(item => expect(item.isRippleEnabled()).toBe(false));
144+
items.forEach(item => expect(item._isRippleDisabled()).toBe(true));
145145
});
146146

147147
it('should allow disabling ripples for the whole nav-list', () => {
@@ -152,12 +152,12 @@ describe('MdList', () => {
152152
expect(items.length).toBeGreaterThan(0);
153153

154154
// Ripples should be enabled by default, and can be disabled with a binding.
155-
items.forEach(item => expect(item.isRippleEnabled()).toBe(true));
155+
items.forEach(item => expect(item._isRippleDisabled()).toBe(false));
156156

157157
fixture.componentInstance.disableListRipple = true;
158158
fixture.detectChanges();
159159

160-
items.forEach(item => expect(item.isRippleEnabled()).toBe(false));
160+
items.forEach(item => expect(item._isRippleDisabled()).toBe(true));
161161
});
162162
});
163163

src/lib/list/list.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ export class MdListItem extends _MdListItemMixinBase implements AfterContentInit
156156
}
157157

158158
/** Whether this list item should show a ripple effect when clicked. */
159-
isRippleEnabled() {
160-
return !this.disableRipple && this._isNavList && !this._list.disableRipple;
159+
_isRippleDisabled() {
160+
return !this._isNavList || this.disableRipple || this._list.disableRipple;
161161
}
162162

163163
_handleFocus() {

src/lib/list/selection-list.ts

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,13 @@ import {FocusableOption} from '../core/a11y/focus-key-manager';
3232
import {CanDisable, mixinDisabled} from '../core/common-behaviors/disabled';
3333
import {RxChain, switchMap, startWith} from '../core/rxjs/index';
3434
import {merge} from 'rxjs/observable/merge';
35+
import {CanDisableRipple, mixinDisableRipple} from '../core/common-behaviors/disable-ripple';
3536

3637
export class MdSelectionListBase {}
37-
export const _MdSelectionListMixinBase = mixinDisabled(MdSelectionListBase);
38+
export const _MdSelectionListMixinBase = mixinDisableRipple(mixinDisabled(MdSelectionListBase));
39+
40+
export class MdListOptionBase {}
41+
export const _MdListOptionMixinBase = mixinDisableRipple(MdListOptionBase);
3842

3943

4044
export interface MdSelectionListOptionEvent {
@@ -51,6 +55,7 @@ const FOCUSED_STYLE: string = 'mat-list-item-focus';
5155
@Component({
5256
moduleId: module.id,
5357
selector: 'md-list-option, mat-list-option',
58+
inputs: ['disableRipple'],
5459
host: {
5560
'role': 'option',
5661
'class': 'mat-list-item mat-list-option',
@@ -65,9 +70,10 @@ const FOCUSED_STYLE: string = 'mat-list-item-focus';
6570
encapsulation: ViewEncapsulation.None,
6671
changeDetection: ChangeDetectionStrategy.OnPush
6772
})
68-
export class MdListOption implements AfterContentInit, OnDestroy, FocusableOption {
73+
export class MdListOption extends _MdListOptionMixinBase
74+
implements AfterContentInit, OnDestroy, FocusableOption, CanDisableRipple {
75+
6976
private _lineSetter: MdLineSetter;
70-
private _disableRipple: boolean = false;
7177
private _selected: boolean = false;
7278
/** Whether the checkbox is disabled. */
7379
private _disabled: boolean = false;
@@ -76,15 +82,6 @@ export class MdListOption implements AfterContentInit, OnDestroy, FocusableOptio
7682
/** Whether the option has focus. */
7783
_hasFocus: boolean = false;
7884

79-
/**
80-
* Whether the ripple effect on click should be disabled. This applies only to list items that are
81-
* part of a selection list. The value of `disableRipple` on the `md-selection-list` overrides
82-
* this flag
83-
*/
84-
@Input()
85-
get disableRipple() { return this._disableRipple; }
86-
set disableRipple(value: boolean) { this._disableRipple = coerceBooleanProperty(value); }
87-
8885
@ContentChildren(MdLine) _lines: QueryList<MdLine>;
8986

9087
/** Whether the label should appear before or after the checkbox. Defaults to 'after' */
@@ -119,7 +116,9 @@ export class MdListOption implements AfterContentInit, OnDestroy, FocusableOptio
119116
private _element: ElementRef,
120117
private _changeDetector: ChangeDetectorRef,
121118
@Optional() @Inject(forwardRef(() => MdSelectionList))
122-
public selectionList: MdSelectionList) {}
119+
public selectionList: MdSelectionList) {
120+
super();
121+
}
123122

124123
ngAfterContentInit() {
125124
this._lineSetter = new MdLineSetter(this._lines, this._renderer, this._element);
@@ -146,8 +145,8 @@ export class MdListOption implements AfterContentInit, OnDestroy, FocusableOptio
146145
}
147146

148147
/** Whether this list item should show a ripple effect when clicked. */
149-
isRippleEnabled() {
150-
return !this.disableRipple && !this.selectionList.disableRipple;
148+
_isRippleDisabled() {
149+
return this.disableRipple || this.selectionList.disableRipple;
151150
}
152151

153152
_handleClick() {
@@ -175,7 +174,7 @@ export class MdListOption implements AfterContentInit, OnDestroy, FocusableOptio
175174
@Component({
176175
moduleId: module.id,
177176
selector: 'md-selection-list, mat-selection-list',
178-
inputs: ['disabled'],
177+
inputs: ['disabled', 'disableRipple'],
179178
host: {
180179
'role': 'listbox',
181180
'[attr.tabindex]': '_tabIndex',
@@ -189,8 +188,7 @@ export class MdListOption implements AfterContentInit, OnDestroy, FocusableOptio
189188
changeDetection: ChangeDetectionStrategy.OnPush
190189
})
191190
export class MdSelectionList extends _MdSelectionListMixinBase
192-
implements FocusableOption, CanDisable, AfterContentInit, OnDestroy {
193-
private _disableRipple: boolean = false;
191+
implements FocusableOption, CanDisable, CanDisableRipple, AfterContentInit, OnDestroy {
194192

195193
/** Tab index for the selection-list. */
196194
_tabIndex = 0;
@@ -210,14 +208,6 @@ export class MdSelectionList extends _MdSelectionListMixinBase
210208
/** options which are selected. */
211209
selectedOptions: SelectionModel<MdListOption> = new SelectionModel<MdListOption>(true);
212210

213-
/**
214-
* Whether the ripple effect should be disabled on the list-items or not.
215-
* This flag only has an effect for `mat-selection-list` components.
216-
*/
217-
@Input()
218-
get disableRipple() { return this._disableRipple; }
219-
set disableRipple(value: boolean) { this._disableRipple = coerceBooleanProperty(value); }
220-
221211
constructor(private _element: ElementRef) {
222212
super();
223213
}

0 commit comments

Comments
 (0)