Skip to content

Commit 21296e0

Browse files
committed
docs(material/autocomplete): reset template driven autocomplete example (#27656)
Make a bug fix to the template-driven autocomplete example. Fix demo issue where clicking the reset button doesn't reset the autocomplete options and the value in the input to the original state. Reset the form field by resetting the value of the input and the tdStates to the value when the demo is first rendered. (cherry picked from commit 5fca612)
1 parent 58dd802 commit 21296e0

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/dev-app/autocomplete/autocomplete-demo.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
</mat-form-field>
8484

8585
<p>
86-
<button mat-button (click)="modelDir.reset()">RESET</button>
86+
<button mat-button (click)="clearTemplateState()">RESET</button>
8787
<button mat-button (click)="currentState='California'">SET VALUE</button>
8888
<button mat-button (click)="tdDisabled=!tdDisabled">
8989
TOGGLE DISABLED

src/dev-app/autocomplete/autocomplete-demo.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,12 @@ export class AutocompleteDemo {
187187
return this._isStateDisabled(index, this.templateDisableStateOption);
188188
}
189189

190+
clearTemplateState() {
191+
this.modelDir.reset();
192+
this.currentState = '';
193+
this.tdStates = this.states.slice();
194+
}
195+
190196
private _isStateDisabled(stateIndex: number, disableStateOption: DisableStateOption) {
191197
if (disableStateOption === 'all') {
192198
return true;

0 commit comments

Comments
 (0)