File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -688,6 +688,27 @@ describe('MatInput without forms', () => {
688
688
expect ( container . classList ) . toContain ( 'mat-focused' ) ;
689
689
} ) ) ;
690
690
691
+ it ( 'should remove the focused class if the input becomes disabled while focused' ,
692
+ fakeAsync ( ( ) => {
693
+ const fixture = TestBed . createComponent ( MatInputTextTestController ) ;
694
+ fixture . detectChanges ( ) ;
695
+
696
+ const input = fixture . debugElement . query ( By . directive ( MatInput ) ) . injector . get ( MatInput ) ;
697
+ const container = fixture . debugElement . query ( By . css ( 'mat-form-field' ) ) . nativeElement ;
698
+
699
+ // Call the focus handler directly to avoid flakyness where
700
+ // browsers don't focus elements if the window is minimized.
701
+ input . _focusChanged ( true ) ;
702
+ fixture . detectChanges ( ) ;
703
+
704
+ expect ( container . classList ) . toContain ( 'mat-focused' ) ;
705
+
706
+ input . disabled = true ;
707
+ fixture . detectChanges ( ) ;
708
+
709
+ expect ( container . classList ) . not . toContain ( 'mat-focused' ) ;
710
+ } ) ) ;
711
+
691
712
it ( 'should be able to animate the label up and lock it in position' , fakeAsync ( ( ) => {
692
713
let fixture = TestBed . createComponent ( MatInputTextTestController ) ;
693
714
fixture . detectChanges ( ) ;
Original file line number Diff line number Diff line change @@ -109,7 +109,16 @@ export class MatInput extends _MatInputMixinBase implements MatFormFieldControl<
109
109
/** Whether the element is disabled. */
110
110
@Input ( )
111
111
get disabled ( ) { return this . ngControl ? this . ngControl . disabled : this . _disabled ; }
112
- set disabled ( value : any ) { this . _disabled = coerceBooleanProperty ( value ) ; }
112
+ set disabled ( value : any ) {
113
+ this . _disabled = coerceBooleanProperty ( value ) ;
114
+
115
+ // Browsers may not fire the blur event if the input is disabled too quickly.
116
+ // Reset from here to ensure that the element doesn't become stuck.
117
+ if ( this . focused ) {
118
+ this . focused = false ;
119
+ this . stateChanges . next ( ) ;
120
+ }
121
+ }
113
122
114
123
/** Unique id of the element. */
115
124
@Input ( )
You can’t perform that action at this time.
0 commit comments