@@ -30,7 +30,10 @@ let nextId = 0;
3030 host : {
3131 '[class.md-checked]' : 'checked' ,
3232 '[class.md-disabled]' : 'disabled' ,
33- '(click)' : 'onTouched()'
33+ // This md-slide-toggle prefix will change, once the temporary ripple is removed.
34+ '[class.md-slide-toggle-focused]' : '_hasFocus' ,
35+ '(click)' : 'onTouched()' ,
36+ '(mousedown)' : 'setMousedown()'
3437 } ,
3538 templateUrl : 'slide-toggle.html' ,
3639 styleUrls : [ 'slide-toggle.css' ] ,
@@ -46,6 +49,8 @@ export class MdSlideToggle implements ControlValueAccessor {
4649 private _uniqueId = `md-slide-toggle-${ ++ nextId } ` ;
4750 private _checked : boolean = false ;
4851 private _color : string ;
52+ private _hasFocus : boolean = false ;
53+ private _isMousedown : boolean = false ;
4954
5055 @Input ( ) @BooleanFieldValue ( ) disabled : boolean = false ;
5156 @Input ( ) name : string = null ;
@@ -76,6 +81,31 @@ export class MdSlideToggle implements ControlValueAccessor {
7681 }
7782 }
7883
84+ /** @internal */
85+ setMousedown ( ) {
86+ // We only *show* the focus style when focus has come to the button via the keyboard.
87+ // The Material Design spec is silent on this topic, and without doing this, the
88+ // button continues to look :active after clicking.
89+ // @see http://marcysutton.com/button-focus-hell/
90+ this . _isMousedown = true ;
91+ setTimeout ( ( ) => this . _isMousedown = false , 100 ) ;
92+ }
93+
94+ /** @internal */
95+ onInputFocus ( ) {
96+ // Only show the focus / ripple indicator when the focus was not triggered by a mouse
97+ // interaction on the component.
98+ if ( ! this . _isMousedown ) {
99+ this . _hasFocus = true ;
100+ }
101+ }
102+
103+ /** @internal */
104+ onInputBlur ( ) {
105+ this . _hasFocus = false ;
106+ this . onTouched ( ) ;
107+ }
108+
79109 /**
80110 * Implemented as part of ControlValueAccessor.
81111 * @internal
0 commit comments