@@ -21,6 +21,7 @@ import {
21
21
import { NG_VALUE_ACCESSOR , ControlValueAccessor , FormsModule } from '@angular/forms' ;
22
22
import { Observable } from 'rxjs/Observable' ;
23
23
import {
24
+ FocusOriginMonitor ,
24
25
UniqueSelectionDispatcher ,
25
26
coerceBooleanProperty ,
26
27
UNIQUE_SELECTION_DISPATCHER_PROVIDER ,
@@ -286,21 +287,13 @@ export class MdButtonToggleGroupMultiple {
286
287
styleUrls : [ 'button-toggle.css' ] ,
287
288
encapsulation : ViewEncapsulation . None ,
288
289
host : {
289
- '[class.mat-button-toggle-focus]' : '_hasFocus' ,
290
290
'[class.mat-button-toggle]' : 'true' ,
291
- '(mousedown)' : '_setMousedown()' ,
292
291
}
293
292
} )
294
293
export class MdButtonToggle implements OnInit {
295
294
/** Whether or not this button toggle is checked. */
296
295
private _checked : boolean = false ;
297
296
298
- /** Whether the button has focus. Used for class binding. */
299
- _hasFocus : boolean = false ;
300
-
301
- /** Whether a mousedown has occurred on this element in the last 100ms. */
302
- _isMouseDown : boolean = false ;
303
-
304
297
/** Type of the button toggle. Either 'radio' or 'checkbox'. */
305
298
_type : ToggleType ;
306
299
@@ -339,7 +332,8 @@ export class MdButtonToggle implements OnInit {
339
332
constructor ( @Optional ( ) toggleGroup : MdButtonToggleGroup ,
340
333
@Optional ( ) toggleGroupMultiple : MdButtonToggleGroupMultiple ,
341
334
public buttonToggleDispatcher : UniqueSelectionDispatcher ,
342
- private _renderer : Renderer ) {
335
+ private _renderer : Renderer ,
336
+ private _focusOriginMonitor : FocusOriginMonitor ) {
343
337
this . buttonToggleGroup = toggleGroup ;
344
338
345
339
this . buttonToggleGroupMultiple = toggleGroupMultiple ;
@@ -370,6 +364,7 @@ export class MdButtonToggle implements OnInit {
370
364
if ( this . buttonToggleGroup && this . _value == this . buttonToggleGroup . value ) {
371
365
this . _checked = true ;
372
366
}
367
+ this . _focusOriginMonitor . registerElementForFocusClasses ( this . _inputElement . nativeElement , this . _renderer ) ;
373
368
}
374
369
375
370
/** Unique ID for the underlying `input` element. */
@@ -468,31 +463,10 @@ export class MdButtonToggle implements OnInit {
468
463
event . stopPropagation ( ) ;
469
464
}
470
465
471
- _onInputFocus ( ) {
472
- // Only show the focus / ripple indicator when the focus was not triggered by a mouse
473
- // interaction on the component.
474
- if ( ! this . _isMouseDown ) {
475
- this . _hasFocus = true ;
476
- }
477
- }
478
-
479
- _onInputBlur ( ) {
480
- this . _hasFocus = false ;
481
- }
482
-
483
466
/** Focuses the button. */
484
467
focus ( ) {
485
468
this . _renderer . invokeElementMethod ( this . _inputElement . nativeElement , 'focus' ) ;
486
469
}
487
-
488
- _setMousedown ( ) {
489
- // We only *show* the focus style when focus has come to the button via the keyboard.
490
- // The Material Design spec is silent on this topic, and without doing this, the
491
- // button continues to look :active after clicking.
492
- // @see http://marcysutton.com/button-focus-hell/
493
- this . _isMouseDown = true ;
494
- setTimeout ( ( ) => { this . _isMouseDown = false ; } , 100 ) ;
495
- }
496
470
}
497
471
498
472
0 commit comments