Skip to content

Commit 99b5bab

Browse files
crisbetovictoriaaa234
authored andcommitted
fix(autocomplete): don't override native autocomplete attribute (#11926)
1 parent 2321cb1 commit 99b5bab

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/lib/autocomplete/autocomplete-trigger.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export function getMatAutocompleteMissingPanelError(): Error {
9898
@Directive({
9999
selector: `input[matAutocomplete], textarea[matAutocomplete]`,
100100
host: {
101-
'autocomplete': 'off',
101+
'[attr.autocomplete]': 'autocompleteAttribute',
102102
'[attr.role]': 'autocompleteDisabled ? null : "combobox"',
103103
'[attr.aria-autocomplete]': 'autocompleteDisabled ? null : "list"',
104104
'[attr.aria-activedescendant]': 'activeOption?.id',
@@ -153,6 +153,12 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
153153
*/
154154
@Input('matAutocompleteConnectedTo') connectedTo: MatAutocompleteOrigin;
155155

156+
/**
157+
* `autocomplete` attribute to be set on the input element.
158+
* @docs-private
159+
*/
160+
@Input('autocomplete') autocompleteAttribute: string = 'off';
161+
156162
/**
157163
* Whether the autocomplete is disabled. When disabled, the element will
158164
* act as a regular input and the user won't be able to open the panel.

src/lib/autocomplete/autocomplete.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,15 @@ describe('MatAutocomplete', () => {
522522
expect(boundingBox.getAttribute('dir')).toEqual('ltr');
523523
});
524524

525+
it('should be able to set a custom value for the `autocomplete` attribute', () => {
526+
const fixture = createComponent(AutocompleteWithNativeAutocompleteAttribute);
527+
const input = fixture.nativeElement.querySelector('input');
528+
529+
fixture.detectChanges();
530+
531+
expect(input.getAttribute('autocomplete')).toBe('changed');
532+
});
533+
525534
describe('forms integration', () => {
526535
let fixture: ComponentFixture<SimpleAutocomplete>;
527536
let input: HTMLInputElement;
@@ -2377,3 +2386,14 @@ class AutocompleteWithDifferentOrigin {
23772386
selectedValue: string;
23782387
values = ['one', 'two', 'three'];
23792388
}
2389+
2390+
2391+
@Component({
2392+
template: `
2393+
<input autocomplete="changed" [(ngModel)]="value" [matAutocomplete]="auto"/>
2394+
<mat-autocomplete #auto="matAutocomplete"></mat-autocomplete>
2395+
`
2396+
})
2397+
class AutocompleteWithNativeAutocompleteAttribute {
2398+
value: string;
2399+
}

0 commit comments

Comments
 (0)