6
6
* found in the LICENSE file at https://angular.io/license
7
7
*/
8
8
9
- import { FocusMonitor , FocusOrigin } from '@angular/cdk/a11y' ;
9
+ import { FocusMonitor } from '@angular/cdk/a11y' ;
10
10
import { Directionality } from '@angular/cdk/bidi' ;
11
11
import { coerceBooleanProperty } from '@angular/cdk/coercion' ;
12
12
import { Platform } from '@angular/cdk/platform' ;
@@ -35,12 +35,10 @@ import {
35
35
CanDisableRipple ,
36
36
HammerInput ,
37
37
HasTabIndex ,
38
- MatRipple ,
39
38
mixinColor ,
40
39
mixinDisabled ,
41
40
mixinDisableRipple ,
42
41
mixinTabIndex ,
43
- RippleRef ,
44
42
} from '@angular/material/core' ;
45
43
import { ANIMATION_MODULE_TYPE } from '@angular/platform-browser/animations' ;
46
44
import {
@@ -104,9 +102,6 @@ export class MatSlideToggle extends _MatSlideToggleMixinBase implements OnDestro
104
102
private _required : boolean = false ;
105
103
private _checked : boolean = false ;
106
104
107
- /** Reference to the focus state ripple. */
108
- private _focusRipple : RippleRef | null ;
109
-
110
105
/** Whether the thumb is currently being dragged. */
111
106
private _dragging = false ;
112
107
@@ -179,9 +174,6 @@ export class MatSlideToggle extends _MatSlideToggleMixinBase implements OnDestro
179
174
/** Reference to the underlying input element. */
180
175
@ViewChild ( 'input' ) _inputElement : ElementRef ;
181
176
182
- /** Reference to the ripple directive on the thumb container. */
183
- @ViewChild ( MatRipple ) _ripple : MatRipple ;
184
-
185
177
constructor ( elementRef : ElementRef ,
186
178
/**
187
179
* @deprecated The `_platform` parameter to be removed.
@@ -202,12 +194,21 @@ export class MatSlideToggle extends _MatSlideToggleMixinBase implements OnDestro
202
194
203
195
ngAfterContentInit ( ) {
204
196
this . _focusMonitor
205
- . monitor ( this . _inputElement . nativeElement )
206
- . subscribe ( focusOrigin => this . _onInputFocusChange ( focusOrigin ) ) ;
197
+ . monitor ( this . _elementRef . nativeElement , true )
198
+ . subscribe ( focusOrigin => {
199
+ if ( ! focusOrigin ) {
200
+ // When a focused element becomes disabled, the browser *immediately* fires a blur event.
201
+ // Angular does not expect events to be raised during change detection, so any state
202
+ // change (such as a form control's 'ng-touched') will cause a changed-after-checked
203
+ // error. See https://github.com/angular/angular/issues/17793. To work around this,
204
+ // we defer telling the form control it has been touched until the next tick.
205
+ Promise . resolve ( ) . then ( ( ) => this . onTouched ( ) ) ;
206
+ }
207
+ } ) ;
207
208
}
208
209
209
210
ngOnDestroy ( ) {
210
- this . _focusMonitor . stopMonitoring ( this . _inputElement . nativeElement ) ;
211
+ this . _focusMonitor . stopMonitoring ( this . _elementRef . nativeElement ) ;
211
212
}
212
213
213
214
/** Method being called whenever the underlying input emits a change event. */
@@ -282,28 +283,6 @@ export class MatSlideToggle extends _MatSlideToggleMixinBase implements OnDestro
282
283
this . onChange ( this . checked ) ;
283
284
}
284
285
285
- /** Function is called whenever the focus changes for the input element. */
286
- private _onInputFocusChange ( focusOrigin : FocusOrigin ) {
287
- // TODO(paul): support `program`. See https://github.com/angular/material2/issues/9889
288
- if ( ! this . _focusRipple && focusOrigin === 'keyboard' ) {
289
- // For keyboard focus show a persistent ripple as focus indicator.
290
- this . _focusRipple = this . _ripple . launch ( 0 , 0 , { persistent : true } ) ;
291
- } else if ( ! focusOrigin ) {
292
- // When a focused element becomes disabled, the browser *immediately* fires a blur event.
293
- // Angular does not expect events to be raised during change detection, so any state change
294
- // (such as a form control's 'ng-touched') will cause a changed-after-checked error.
295
- // See https://github.com/angular/angular/issues/17793. To work around this, we defer telling
296
- // the form control it has been touched until the next tick.
297
- Promise . resolve ( ) . then ( ( ) => this . onTouched ( ) ) ;
298
-
299
- // Fade out and clear the focus ripple if one is currently present.
300
- if ( this . _focusRipple ) {
301
- this . _focusRipple . fadeOut ( ) ;
302
- this . _focusRipple = null ;
303
- }
304
- }
305
- }
306
-
307
286
/**
308
287
* Emits a change event on the `change` output. Also notifies the FormControl about the change.
309
288
*/
0 commit comments