@@ -36,12 +36,12 @@ const {cssClasses} = MDCTextFieldFoundation;
3636const getFixture = ( ) => {
3737 const wrapper = document . createElement ( 'div' ) ;
3838 wrapper . innerHTML = `
39- <div class="mdc-text-field mdc-text-field--with-leading-icon">
39+ <label class="mdc-text-field mdc-text-field--with-leading-icon">
4040 <i class="material-icons mdc-text-field__icon mdc-text-field__icon--leading" tabindex="0" role="button">event</i>
41- <input type="text" class="mdc-text-field__input" id ="my-text-field ">
42- <label class="mdc-floating-label" for ="my-text-field ">My Label</label >
41+ <input type="text" class="mdc-text-field__input" aria-labelledby ="my-label ">
42+ <span class="mdc-floating-label" id ="my-label ">My Label</span >
4343 <div class="mdc-line-ripple"></div>
44- </div >
44+ </label >
4545 ` ;
4646 const el = wrapper . firstElementChild as HTMLElement ;
4747 wrapper . removeChild ( el ) ;
@@ -674,6 +674,24 @@ describe('MDCTextField', () => {
674674 expect ( lineRipple . setRippleCenter ) . toHaveBeenCalledWith ( 100 ) ;
675675 } ) ;
676676
677+ it ( 'should not focus input when clicking icon' , ( ) => {
678+ const root = getFixture ( ) ;
679+ const icon = root . querySelector ( '.mdc-text-field__icon' ) ;
680+ const component = new MDCTextField ( root ) ;
681+ document . body . appendChild ( root ) ;
682+ component . root_ . click ( ) ;
683+ assert . equal (
684+ component . input_ , document . activeElement , 'input_ should be focused' ) ;
685+ component . input_ . blur ( ) ;
686+ assert . notEqual (
687+ component . input_ , document . activeElement , 'ensure input_ was blurred' ) ;
688+ icon . click ( ) ;
689+ assert . notEqual (
690+ component . input_ , document . activeElement ,
691+ 'input_ should not be focused' ) ;
692+ document . body . removeChild ( root ) ;
693+ } ) ;
694+
677695 function setupMockFoundationTest ( root = getFixture ( ) ) {
678696 const mockFoundation = createMockFoundation ( MDCTextFieldFoundation ) ;
679697 const component = new MDCTextField ( root , mockFoundation ) ;
0 commit comments