Skip to content

fix(material/autocomplete): Add a boolean field to update the native … #29690

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
[(ngModel)]="currentFruit"
[matChipInputFor]="chipGrid"
[matAutocomplete]="auto"
updateNativeInput
[matChipInputSeparatorKeyCodes]="separatorKeysCodes"
(matChipInputTokenEnd)="add($event)"
/>
Expand Down
8 changes: 7 additions & 1 deletion src/material/autocomplete/autocomplete-trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,12 @@ export class MatAutocompleteTrigger
@Input({alias: 'matAutocompleteDisabled', transform: booleanAttribute})
autocompleteDisabled: boolean;

/**
* Whether the autocomplete should update the native input element only.
* When true the autocomplete will not update the value via the form field control.
*/
@Input({transform: booleanAttribute}) updateNativeInput: boolean;

private _initialized = new Subject();

private _injector = inject(Injector);
Expand Down Expand Up @@ -709,7 +715,7 @@ export class MatAutocompleteTrigger
private _updateNativeInputValue(value: string): void {
// If it's used within a `MatFormField`, we should set it through the property so it can go
// through change detection.
if (this._formField) {
if (this._formField && !this.updateNativeInput) {
this._formField._control.value = value;
} else {
this._element.nativeElement.value = value;
Expand Down
5 changes: 4 additions & 1 deletion tools/public_api_guard/material/autocomplete.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, AfterViewIn
// (undocumented)
static ngAcceptInputType_autocompleteDisabled: unknown;
// (undocumented)
static ngAcceptInputType_updateNativeInput: unknown;
// (undocumented)
ngAfterViewInit(): void;
// (undocumented)
ngOnChanges(changes: SimpleChanges): void;
Expand All @@ -210,11 +212,12 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, AfterViewIn
registerOnTouched(fn: () => {}): void;
// (undocumented)
setDisabledState(isDisabled: boolean): void;
updateNativeInput: boolean;
updatePosition(): void;
// (undocumented)
writeValue(value: any): void;
// (undocumented)
static ɵdir: i0.ɵɵDirectiveDeclaration<MatAutocompleteTrigger, "input[matAutocomplete], textarea[matAutocomplete]", ["matAutocompleteTrigger"], { "autocomplete": { "alias": "matAutocomplete"; "required": false; }; "position": { "alias": "matAutocompletePosition"; "required": false; }; "connectedTo": { "alias": "matAutocompleteConnectedTo"; "required": false; }; "autocompleteAttribute": { "alias": "autocomplete"; "required": false; }; "autocompleteDisabled": { "alias": "matAutocompleteDisabled"; "required": false; }; }, {}, never, never, true, never>;
static ɵdir: i0.ɵɵDirectiveDeclaration<MatAutocompleteTrigger, "input[matAutocomplete], textarea[matAutocomplete]", ["matAutocompleteTrigger"], { "autocomplete": { "alias": "matAutocomplete"; "required": false; }; "position": { "alias": "matAutocompletePosition"; "required": false; }; "connectedTo": { "alias": "matAutocompleteConnectedTo"; "required": false; }; "autocompleteAttribute": { "alias": "autocomplete"; "required": false; }; "autocompleteDisabled": { "alias": "matAutocompleteDisabled"; "required": false; }; "updateNativeInput": { "alias": "updateNativeInput"; "required": false; }; }, {}, never, never, true, never>;
// (undocumented)
static ɵfac: i0.ɵɵFactoryDeclaration<MatAutocompleteTrigger, [null, null, null, null, null, null, { optional: true; }, { optional: true; host: true; }, { optional: true; }, null, { optional: true; }]>;
}
Expand Down
Loading