File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed
Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -114,6 +114,7 @@ export class Switch extends switchBaseClass {
114114 ?checked =${ this . selected }
115115 ?disabled=${ this . disabled }
116116 ?required=${ this . required }
117+ @input=${ this . handleInput }
117118 @change=${ this . handleChange } />
118119
119120 < md-focus-ring part ="focus-ring " for ="switch "> </ md-focus-ring >
@@ -190,9 +191,14 @@ export class Switch extends switchBaseClass {
190191 return this . icons || this . showOnlySelectedIcon ;
191192 }
192193
193- private handleChange ( event : Event ) {
194+ private handleInput ( event : Event ) {
194195 const target = event . target as HTMLInputElement ;
195196 this . selected = target . checked ;
197+ // <input> 'input' event bubbles and is composed, don't re-dispatch it.
198+ }
199+
200+ private handleChange ( event : Event ) {
201+ // <input> 'change' event is not composed, re-dispatch it.
196202 redispatchEvent ( this , event ) ;
197203 }
198204
Original file line number Diff line number Diff line change @@ -161,6 +161,23 @@ describe('md-switch', () => {
161161 toggle . click ( ) ;
162162 expect ( toggle . selected ) . withContext ( 'should remain false' ) . toBeFalse ( ) ;
163163 } ) ;
164+
165+ it ( 'reflects `selected` state in input events' , ( ) => {
166+ let state = false ;
167+ const inputHandler = jasmine
168+ . createSpy ( 'inputHandler' )
169+ . and . callFake ( ( ) => {
170+ state = toggle . selected ;
171+ } ) ;
172+
173+ toggle . addEventListener ( 'input' , inputHandler ) ;
174+
175+ toggle . click ( ) ;
176+ expect ( inputHandler ) . withContext ( 'input listener' ) . toHaveBeenCalled ( ) ;
177+ expect ( state )
178+ . withContext ( 'switch.selected during input listener' )
179+ . toBeTrue ( ) ;
180+ } ) ;
164181 } ) ;
165182
166183 describe ( 'form submission' , ( ) => {
You can’t perform that action at this time.
0 commit comments