@@ -1607,6 +1607,36 @@ describe('MatAutocomplete', () => {
16071607 } ) ;
16081608 } ) ;
16091609
1610+ describe ( 'form control with initial value' , ( ) => {
1611+ let fixture : ComponentFixture < FormControlWithInitialValue > ;
1612+ let input : HTMLInputElement ;
1613+
1614+ beforeEach ( waitForAsync ( async ( ) => {
1615+ fixture = createComponent ( FormControlWithInitialValue ) ;
1616+ fixture . detectChanges ( ) ;
1617+
1618+ input = fixture . debugElement . query ( By . css ( 'input' ) ) ! . nativeElement ;
1619+
1620+ fixture . componentInstance . trigger . openPanel ( ) ;
1621+ fixture . detectChanges ( ) ;
1622+ await new Promise ( r => setTimeout ( r ) ) ;
1623+ } ) ) ;
1624+
1625+ it ( 'should mark the initial value as selected if its present' , fakeAsync ( ( ) => {
1626+ const trigger = fixture . componentInstance . trigger ;
1627+ trigger . openPanel ( ) ;
1628+ fixture . detectChanges ( ) ;
1629+
1630+ const options = overlayContainerElement . querySelectorAll (
1631+ 'mat-option' ,
1632+ ) as NodeListOf < HTMLElement > ;
1633+
1634+ expect ( input . value ) . toBe ( 'Three' ) ;
1635+ expect ( options . length ) . toBe ( 3 ) ;
1636+ expect ( options [ 2 ] . classList ) . toContain ( 'mdc-list-item--selected' ) ;
1637+ } ) ) ;
1638+ } ) ;
1639+
16101640 describe ( 'option groups' , ( ) => {
16111641 let DOWN_ARROW_EVENT : KeyboardEvent ;
16121642 let UP_ARROW_EVENT : KeyboardEvent ;
@@ -4406,6 +4436,31 @@ class PlainAutocompleteInputWithFormControl {
44064436 formControl = new FormControl ( '' ) ;
44074437}
44084438
4439+ @Component ( {
4440+ template : `
4441+ <mat-form-field>
4442+ <input matInput placeholder="Choose" [matAutocomplete]="auto" [formControl]="optionCtrl">
4443+ </mat-form-field>
4444+ <mat-autocomplete #auto="matAutocomplete" >
4445+ @for (option of options; track option) {
4446+ <mat-option [value]="option">
4447+ {{option}}
4448+ </mat-option>
4449+ }
4450+ </mat-autocomplete>
4451+ ` ,
4452+ standalone : false ,
4453+ } )
4454+ class FormControlWithInitialValue {
4455+ optionCtrl = new FormControl ( 'Three' ) ;
4456+ filteredOptions : Observable < any > ;
4457+ options = [ 'One' , 'Two' , 'Three' ] ;
4458+
4459+ @ViewChild ( MatAutocompleteTrigger ) trigger : MatAutocompleteTrigger ;
4460+
4461+ constructor ( ) { }
4462+ }
4463+
44094464@Component ( {
44104465 template : `
44114466 <mat-form-field>
0 commit comments