@@ -21,6 +21,7 @@ import {
2121import { NG_VALUE_ACCESSOR , ControlValueAccessor , FormsModule } from '@angular/forms' ;
2222import { Observable } from 'rxjs/Observable' ;
2323import {
24+ FocusOriginMonitor ,
2425 UniqueSelectionDispatcher ,
2526 coerceBooleanProperty ,
2627 UNIQUE_SELECTION_DISPATCHER_PROVIDER ,
@@ -286,21 +287,13 @@ export class MdButtonToggleGroupMultiple {
286287 styleUrls : [ 'button-toggle.css' ] ,
287288 encapsulation : ViewEncapsulation . None ,
288289 host : {
289- '[class.mat-button-toggle-focus]' : '_hasFocus' ,
290290 '[class.mat-button-toggle]' : 'true' ,
291- '(mousedown)' : '_setMousedown()' ,
292291 }
293292} )
294293export class MdButtonToggle implements OnInit {
295294 /** Whether or not this button toggle is checked. */
296295 private _checked : boolean = false ;
297296
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-
304297 /** Type of the button toggle. Either 'radio' or 'checkbox'. */
305298 _type : ToggleType ;
306299
@@ -339,7 +332,8 @@ export class MdButtonToggle implements OnInit {
339332 constructor ( @Optional ( ) toggleGroup : MdButtonToggleGroup ,
340333 @Optional ( ) toggleGroupMultiple : MdButtonToggleGroupMultiple ,
341334 public buttonToggleDispatcher : UniqueSelectionDispatcher ,
342- private _renderer : Renderer ) {
335+ private _renderer : Renderer ,
336+ private _focusOriginMonitor : FocusOriginMonitor ) {
343337 this . buttonToggleGroup = toggleGroup ;
344338
345339 this . buttonToggleGroupMultiple = toggleGroupMultiple ;
@@ -370,6 +364,7 @@ export class MdButtonToggle implements OnInit {
370364 if ( this . buttonToggleGroup && this . _value == this . buttonToggleGroup . value ) {
371365 this . _checked = true ;
372366 }
367+ this . _focusOriginMonitor . registerElementForFocusClasses ( this . _inputElement . nativeElement , this . _renderer ) ;
373368 }
374369
375370 /** Unique ID for the underlying `input` element. */
@@ -468,31 +463,10 @@ export class MdButtonToggle implements OnInit {
468463 event . stopPropagation ( ) ;
469464 }
470465
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-
483466 /** Focuses the button. */
484467 focus ( ) {
485468 this . _renderer . invokeElementMethod ( this . _inputElement . nativeElement , 'focus' ) ;
486469 }
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- }
496470}
497471
498472
0 commit comments