-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add mixin for disableRipple properties
* Adds a mixin that adds the `disableRipple` getter/setter to Material components. Closes #5586
- Loading branch information
1 parent
804f4c0
commit 097463d
Showing
9 changed files
with
134 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import {mixinDisableRipple} from './disable-ripple'; | ||
|
||
describe('mixinDisableRipple', () => { | ||
|
||
it('should augment an existing class with a disableRipple property', () => { | ||
const classWithMixin = mixinDisableRipple(TestClass); | ||
const instance = new classWithMixin(); | ||
|
||
expect(instance.disableRipple) | ||
.toBe(false, 'Expected the mixed-into class to have a disable-ripple property'); | ||
|
||
instance.disableRipple = true; | ||
|
||
expect(instance.disableRipple) | ||
.toBe(true, 'Expected the mixed-into class to have an updated disable-ripple property'); | ||
}); | ||
|
||
it('should coerce values being passed to the disableRipple property', () => { | ||
const classWithMixin = mixinDisableRipple(TestClass); | ||
const instance = new classWithMixin(); | ||
|
||
expect(instance.disableRipple) | ||
.toBe(false, 'Expected disableRipple to be set to false initially'); | ||
|
||
// Setting string values to the disableRipple property should be prevented by TypeScript's | ||
// type checking, but developers can still set string values from their template bindings. | ||
(instance as any).disableRipple = ''; | ||
|
||
expect(instance.disableRipple) | ||
.toBe(true, 'Expected disableRipple to be set to true if an empty string is set as value'); | ||
}); | ||
|
||
}); | ||
|
||
class TestClass {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* @license | ||
* Copyright Google Inc. All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {coerceBooleanProperty} from '@angular/cdk'; | ||
import {Constructor} from './constructor'; | ||
|
||
/** @docs-private */ | ||
export interface CanDisableRipple { | ||
disableRipple: boolean; | ||
} | ||
|
||
/** Mixin to augment a directive with a `disableRipple` property. */ | ||
export function mixinDisableRipple<T extends Constructor<{}>>(base: T) | ||
: Constructor<CanDisableRipple> & T { | ||
return class extends base { | ||
private _disableRipple: boolean = false; | ||
|
||
/** Whether the ripple effect is disabled or not. */ | ||
get disableRipple() { return this._disableRipple; } | ||
set disableRipple(value: any) { this._disableRipple = coerceBooleanProperty(value); } | ||
|
||
constructor(...args: any[]) { super(...args); } | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.