7
7
*/
8
8
9
9
import { FocusMonitor , FocusOrigin } from '@angular/cdk/a11y' ;
10
+ import { coerceBooleanProperty } from '@angular/cdk/coercion' ;
10
11
import { Platform } from '@angular/cdk/platform' ;
11
12
import {
12
13
AfterViewInit ,
@@ -25,8 +26,8 @@ import {
25
26
mixinColor ,
26
27
mixinDisabled ,
27
28
mixinDisableRipple ,
29
+ MatRippleLoader ,
28
30
} from '@angular/material/core' ;
29
- import { MAT_BUTTON_RIPPLE_UNINITIALIZED , MatButtonLazyLoader } from './button-lazy-loader' ;
30
31
31
32
/** Inputs common to all buttons. */
32
33
export const MAT_BUTTON_INPUTS = [ 'disabled' , 'disableRipple' , 'color' ] ;
@@ -42,8 +43,6 @@ export const MAT_BUTTON_HOST = {
42
43
// Add a class that applies to all buttons. This makes it easier to target if somebody
43
44
// wants to target all Material buttons.
44
45
'[class.mat-mdc-button-base]' : 'true' ,
45
- [ MAT_BUTTON_RIPPLE_UNINITIALIZED ] : '' ,
46
- '[attr.mat-button-disabled]' : '_isRippleDisabled()' ,
47
46
'[attr.mat-button-is-fab]' : '_isFab' ,
48
47
} ;
49
48
@@ -103,29 +102,45 @@ export class MatButtonBase
103
102
* Handles the lazy creation of the MatButton ripple.
104
103
* Used to improve initial load time of large applications.
105
104
*/
106
- _rippleLoader : MatButtonLazyLoader = inject ( MatButtonLazyLoader ) ;
105
+ _rippleLoader : MatRippleLoader = inject ( MatRippleLoader ) ;
107
106
108
107
/** Whether this button is a FAB. Used to apply the correct class on the ripple. */
109
108
_isFab = false ;
110
109
110
+ // We override `disableRipple` and `disabled` so we can hook into
111
+ // their setters and update the ripple disabled state accordingly.
112
+
113
+ /** Whether the ripple effect is disabled or not. */
114
+ override get disableRipple ( ) : boolean {
115
+ return this . _disableRipple ;
116
+ }
117
+ override set disableRipple ( value : any ) {
118
+ this . _disableRipple = coerceBooleanProperty ( value ) ;
119
+ this . _updateRippleDisabled ( ) ;
120
+ }
121
+ private _disableRipple : boolean = false ;
122
+
123
+ override get disabled ( ) : boolean {
124
+ return this . _disabled ;
125
+ }
126
+ override set disabled ( value : any ) {
127
+ this . _disabled = coerceBooleanProperty ( value ) ;
128
+ this . _updateRippleDisabled ( ) ;
129
+ }
130
+ private _disabled : boolean = false ;
131
+
111
132
/**
112
133
* Reference to the MatRipple instance of the button.
113
134
* @deprecated Considered an implementation detail. To be removed.
114
135
* @breaking -change 17.0.0
115
136
*/
116
137
get ripple ( ) : MatRipple {
117
- if ( ! this . _ripple && this . _rippleLoader ) {
118
- this . _ripple = this . _rippleLoader . _createMatRipple ( this . _elementRef . nativeElement ) ;
119
- }
120
- return this . _ripple ! ;
138
+ return this . _rippleLoader ?. getRipple ( this . _elementRef . nativeElement ) ! ;
121
139
}
122
140
set ripple ( v : MatRipple ) {
123
- this . _ripple = v ;
141
+ this . _rippleLoader ?. attachRipple ( this . _elementRef . nativeElement , v ) ;
124
142
}
125
143
126
- /** @docs -private Reference to the MatRipple instance of the button. */
127
- protected _ripple ?: MatRipple ;
128
-
129
144
constructor (
130
145
elementRef : ElementRef ,
131
146
public _platform : Platform ,
@@ -134,6 +149,10 @@ export class MatButtonBase
134
149
) {
135
150
super ( elementRef ) ;
136
151
152
+ this . _rippleLoader ?. configureRipple ( this . _elementRef . nativeElement , {
153
+ className : 'mat-mdc-button-ripple' ,
154
+ } ) ;
155
+
137
156
const classList = ( elementRef . nativeElement as HTMLElement ) . classList ;
138
157
139
158
// For each of the variant selectors that is present in the button's host
@@ -169,10 +188,11 @@ export class MatButtonBase
169
188
return attributes . some ( attribute => this . _elementRef . nativeElement . hasAttribute ( attribute ) ) ;
170
189
}
171
190
172
- _isRippleDisabled ( ) {
173
- if ( this . _ripple ) {
174
- this . _ripple . disabled = this . disableRipple || this . disabled ;
175
- }
191
+ private _updateRippleDisabled ( ) : void {
192
+ this . _rippleLoader ?. setDisabled (
193
+ this . _elementRef . nativeElement ,
194
+ this . disableRipple || this . disabled ,
195
+ ) ;
176
196
}
177
197
}
178
198
@@ -196,8 +216,6 @@ export const MAT_ANCHOR_HOST = {
196
216
// Add a class that applies to all buttons. This makes it easier to target if somebody
197
217
// wants to target all Material buttons.
198
218
'[class.mat-mdc-button-base]' : 'true' ,
199
- [ MAT_BUTTON_RIPPLE_UNINITIALIZED ] : '' ,
200
- '[attr.mat-button-disabled]' : '_isRippleDisabled()' ,
201
219
'[attr.mat-button-is-fab]' : '_isFab' ,
202
220
} ;
203
221
0 commit comments