File tree Expand file tree Collapse file tree 2 files changed +20
-3
lines changed Expand file tree Collapse file tree 2 files changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -671,6 +671,11 @@ describe('MatInput without forms', () => {
671
671
expect ( formFieldEl . classList ) . toContain ( 'mat-form-field-should-float' ) ;
672
672
} ) ) ;
673
673
674
+ it ( 'should not throw if a native select does not have options' , fakeAsync ( ( ) => {
675
+ const fixture = createComponent ( MatInputSelectWithoutOptions ) ;
676
+ expect ( ( ) => fixture . detectChanges ( ) ) . not . toThrow ( ) ;
677
+ } ) ) ;
678
+
674
679
it ( 'should never float the label when floatLabel is set to false' , fakeAsync ( ( ) => {
675
680
let fixture = createComponent ( MatInputWithDynamicLabel ) ;
676
681
@@ -1933,6 +1938,15 @@ class MatInputSelectWithInnerHtml {}
1933
1938
} )
1934
1939
class MatInputWithCustomAccessor { }
1935
1940
1941
+ @Component ( {
1942
+ template : `
1943
+ <mat-form-field>
1944
+ <select matNativeControl>
1945
+ </select>
1946
+ </mat-form-field>`
1947
+ } )
1948
+ class MatInputSelectWithoutOptions { }
1949
+
1936
1950
1937
1951
/** Custom component that never has a value. Used for testing the `MAT_INPUT_VALUE_ACCESSOR`. */
1938
1952
@Directive ( {
Original file line number Diff line number Diff line change @@ -383,9 +383,10 @@ export class MatInput extends _MatInputMixinBase implements MatFormFieldControl<
383
383
// a non-empty display value. For a `<select multiple>`, the label *always* floats to avoid
384
384
// overlapping the label with the options.
385
385
const selectElement = this . _elementRef . nativeElement as HTMLSelectElement ;
386
+ const firstOption : HTMLOptionElement | undefined = selectElement . options [ 0 ] ;
386
387
387
- return selectElement . multiple || ! this . empty || ! ! selectElement . options [ 0 ] . label ||
388
- this . focused ;
388
+ return selectElement . multiple || ! this . empty || this . focused ||
389
+ ! ! ( firstOption && firstOption . label ) ;
389
390
} else {
390
391
return this . focused || ! this . empty ;
391
392
}
@@ -395,7 +396,9 @@ export class MatInput extends _MatInputMixinBase implements MatFormFieldControl<
395
396
* Implemented as part of MatFormFieldControl.
396
397
* @docs -private
397
398
*/
398
- setDescribedByIds ( ids : string [ ] ) { this . _ariaDescribedby = ids . join ( ' ' ) ; }
399
+ setDescribedByIds ( ids : string [ ] ) {
400
+ this . _ariaDescribedby = ids . join ( ' ' ) ;
401
+ }
399
402
400
403
/**
401
404
* Implemented as part of MatFormFieldControl.
You can’t perform that action at this time.
0 commit comments