@@ -276,7 +276,6 @@ export class MdButtonToggleGroupMultiple {
276276 set vertical ( value ) {
277277 this . _vertical = coerceBooleanProperty ( value ) ;
278278 }
279-
280279}
281280
282281/** Single button inside of a toggle group. */
@@ -287,13 +286,21 @@ export class MdButtonToggleGroupMultiple {
287286 styleUrls : [ 'button-toggle.css' ] ,
288287 encapsulation : ViewEncapsulation . None ,
289288 host : {
290- '[class.mat-button-toggle]' : 'true'
289+ '[class.mat-button-toggle-focus]' : '_hasFocus' ,
290+ '[class.mat-button-toggle]' : 'true' ,
291+ '(mousedown)' : '_setMousedown()' ,
291292 }
292293} )
293294export class MdButtonToggle implements OnInit {
294295 /** Whether or not this button toggle is checked. */
295296 private _checked : boolean = false ;
296297
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+
297304 /** Type of the button toggle. Either 'radio' or 'checkbox'. */
298305 _type : ToggleType ;
299306
@@ -461,10 +468,31 @@ export class MdButtonToggle implements OnInit {
461468 event . stopPropagation ( ) ;
462469 }
463470
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+
464483 /** Focuses the button. */
465484 focus ( ) {
466485 this . _renderer . invokeElementMethod ( this . _inputElement . nativeElement , 'focus' ) ;
467486 }
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+ }
468496}
469497
470498
0 commit comments