@@ -403,6 +403,65 @@ describe('MatMdcInput without forms', () => {
403
403
expect ( inputEl . disabled ) . toBe ( true ) ;
404
404
} ) ) ;
405
405
406
+ it ( 'should be able to set an input as being disabled and interactive' , fakeAsync ( ( ) => {
407
+ const fixture = createComponent ( MatInputWithDisabled ) ;
408
+ fixture . componentInstance . disabled = true ;
409
+ fixture . detectChanges ( ) ;
410
+
411
+ const input = fixture . nativeElement . querySelector ( 'input' ) as HTMLInputElement ;
412
+ expect ( input . disabled ) . toBe ( true ) ;
413
+ expect ( input . readOnly ) . toBe ( false ) ;
414
+ expect ( input . hasAttribute ( 'aria-disabled' ) ) . toBe ( false ) ;
415
+ expect ( input . classList ) . not . toContain ( 'mat-mdc-input-disabled-interactive' ) ;
416
+
417
+ fixture . componentInstance . disabledInteractive = true ;
418
+ fixture . changeDetectorRef . markForCheck ( ) ;
419
+ fixture . detectChanges ( ) ;
420
+
421
+ expect ( input . disabled ) . toBe ( false ) ;
422
+ expect ( input . readOnly ) . toBe ( true ) ;
423
+ expect ( input . getAttribute ( 'aria-disabled' ) ) . toBe ( 'true' ) ;
424
+ expect ( input . classList ) . toContain ( 'mat-mdc-input-disabled-interactive' ) ;
425
+ } ) ) ;
426
+
427
+ it ( 'should not float the label when disabled and disabledInteractive are set' , fakeAsync ( ( ) => {
428
+ const fixture = createComponent ( MatInputTextTestController ) ;
429
+ fixture . componentInstance . disabled = fixture . componentInstance . disabledInteractive = true ;
430
+ fixture . detectChanges ( ) ;
431
+
432
+ const label = fixture . nativeElement . querySelector ( 'label' ) ;
433
+ const input = fixture . debugElement
434
+ . query ( By . directive ( MatInput ) ) !
435
+ . injector . get < MatInput > ( MatInput ) ;
436
+
437
+ expect ( label . classList ) . not . toContain ( 'mdc-floating-label--float-above' ) ;
438
+
439
+ // Call the focus handler directly to avoid flakyness where
440
+ // browsers don't focus elements if the window is minimized.
441
+ input . _focusChanged ( true ) ;
442
+ fixture . detectChanges ( ) ;
443
+
444
+ expect ( label . classList ) . not . toContain ( 'mdc-floating-label--float-above' ) ;
445
+ } ) ) ;
446
+
447
+ it ( 'should float the label when disabledInteractive is set and the input has a value' , fakeAsync ( ( ) => {
448
+ const fixture = createComponent ( MatInputWithDynamicLabel ) ;
449
+ fixture . componentInstance . shouldFloat = 'auto' ;
450
+ fixture . componentInstance . disabled = fixture . componentInstance . disabledInteractive = true ;
451
+ fixture . detectChanges ( ) ;
452
+
453
+ const input = fixture . nativeElement . querySelector ( 'input' ) ;
454
+ const label = fixture . nativeElement . querySelector ( 'label' ) ;
455
+
456
+ expect ( label . classList ) . not . toContain ( 'mdc-floating-label--float-above' ) ;
457
+
458
+ input . value = 'Text' ;
459
+ dispatchFakeEvent ( input , 'input' ) ;
460
+ fixture . detectChanges ( ) ;
461
+
462
+ expect ( label . classList ) . toContain ( 'mdc-floating-label--float-above' ) ;
463
+ } ) ) ;
464
+
406
465
it ( 'supports the disabled attribute as binding for select' , fakeAsync ( ( ) => {
407
466
const fixture = createComponent ( MatInputSelect ) ;
408
467
fixture . detectChanges ( ) ;
@@ -719,16 +778,13 @@ describe('MatMdcInput without forms', () => {
719
778
expect ( labelEl . classList ) . not . toContain ( 'mdc-floating-label--float-above' ) ;
720
779
} ) ) ;
721
780
722
- it (
723
- 'should not float labels when select has no value, no option label, ' + 'no option innerHtml' ,
724
- fakeAsync ( ( ) => {
725
- const fixture = createComponent ( MatInputSelectWithNoLabelNoValue ) ;
726
- fixture . detectChanges ( ) ;
781
+ it ( 'should not float labels when select has no value, no option label, no option innerHtml' , fakeAsync ( ( ) => {
782
+ const fixture = createComponent ( MatInputSelectWithNoLabelNoValue ) ;
783
+ fixture . detectChanges ( ) ;
727
784
728
- const labelEl = fixture . debugElement . query ( By . css ( 'label' ) ) ! . nativeElement ;
729
- expect ( labelEl . classList ) . not . toContain ( 'mdc-floating-label--float-above' ) ;
730
- } ) ,
731
- ) ;
785
+ const labelEl = fixture . debugElement . query ( By . css ( 'label' ) ) ! . nativeElement ;
786
+ expect ( labelEl . classList ) . not . toContain ( 'mdc-floating-label--float-above' ) ;
787
+ } ) ) ;
732
788
733
789
it ( 'should floating labels when select has no value but has option label' , fakeAsync ( ( ) => {
734
790
const fixture = createComponent ( MatInputSelectWithLabel ) ;
@@ -1532,6 +1588,7 @@ describe('MatFormField default options', () => {
1532
1588
) . toBe ( true ) ;
1533
1589
} ) ;
1534
1590
} ) ;
1591
+
1535
1592
describe ( 'MatFormField without label' , ( ) => {
1536
1593
it ( 'should not float the label when no label is defined.' , ( ) => {
1537
1594
let fixture = createComponent ( MatInputWithoutDefinedLabel ) ;
@@ -1650,10 +1707,15 @@ class MatInputWithId {
1650
1707
}
1651
1708
1652
1709
@Component ( {
1653
- template : `<mat-form-field><input matInput [disabled]="disabled"></mat-form-field>` ,
1710
+ template : `
1711
+ <mat-form-field>
1712
+ <input matInput [disabled]="disabled" [disabledInteractive]="disabledInteractive">
1713
+ </mat-form-field>
1714
+ ` ,
1654
1715
} )
1655
1716
class MatInputWithDisabled {
1656
- disabled : boolean ;
1717
+ disabled = false ;
1718
+ disabledInteractive = false ;
1657
1719
}
1658
1720
1659
1721
@Component ( {
@@ -1783,10 +1845,18 @@ class MatInputDateTestController {}
1783
1845
template : `
1784
1846
<mat-form-field>
1785
1847
<mat-label>Label</mat-label>
1786
- <input matInput type="text" placeholder="Placeholder">
1848
+ <input
1849
+ matInput
1850
+ type="text"
1851
+ placeholder="Placeholder"
1852
+ [disabled]="disabled"
1853
+ [disabledInteractive]="disabledInteractive">
1787
1854
</mat-form-field>` ,
1788
1855
} )
1789
- class MatInputTextTestController { }
1856
+ class MatInputTextTestController {
1857
+ disabled = false ;
1858
+ disabledInteractive = false ;
1859
+ }
1790
1860
1791
1861
@Component ( {
1792
1862
template : `
@@ -1837,11 +1907,17 @@ class MatInputWithStaticLabel {}
1837
1907
template : `
1838
1908
<mat-form-field [floatLabel]="shouldFloat">
1839
1909
<mat-label>Label</mat-label>
1840
- <input matInput placeholder="Placeholder">
1910
+ <input
1911
+ matInput
1912
+ placeholder="Placeholder"
1913
+ [disabled]="disabled"
1914
+ [disabledInteractive]="disabledInteractive">
1841
1915
</mat-form-field>` ,
1842
1916
} )
1843
1917
class MatInputWithDynamicLabel {
1844
1918
shouldFloat : 'always' | 'auto' = 'always' ;
1919
+ disabled = false ;
1920
+ disabledInteractive = false ;
1845
1921
}
1846
1922
1847
1923
@Component ( {
0 commit comments