Skip to content
Merged
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
8 changes: 7 additions & 1 deletion src/lib/autocomplete/autocomplete-trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export function getMatAutocompleteMissingPanelError(): Error {
@Directive({
selector: `input[matAutocomplete], textarea[matAutocomplete]`,
host: {
'autocomplete': 'off',
'[attr.autocomplete]': 'autocompleteAttribute',
'[attr.role]': 'autocompleteDisabled ? null : "combobox"',
'[attr.aria-autocomplete]': 'autocompleteDisabled ? null : "list"',
'[attr.aria-activedescendant]': 'activeOption?.id',
Expand Down Expand Up @@ -153,6 +153,12 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
*/
@Input('matAutocompleteConnectedTo') connectedTo: MatAutocompleteOrigin;

/**
* `autocomplete` attribute to be set on the input element.
* @docs-private
*/
@Input('autocomplete') autocompleteAttribute: string = 'off';

/**
* Whether the autocomplete is disabled. When disabled, the element will
* act as a regular input and the user won't be able to open the panel.
Expand Down
20 changes: 20 additions & 0 deletions src/lib/autocomplete/autocomplete.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,15 @@ describe('MatAutocomplete', () => {
expect(boundingBox.getAttribute('dir')).toEqual('ltr');
});

it('should be able to set a custom value for the `autocomplete` attribute', () => {
const fixture = createComponent(AutocompleteWithNativeAutocompleteAttribute);
const input = fixture.nativeElement.querySelector('input');

fixture.detectChanges();

expect(input.getAttribute('autocomplete')).toBe('changed');
});

describe('forms integration', () => {
let fixture: ComponentFixture<SimpleAutocomplete>;
let input: HTMLInputElement;
Expand Down Expand Up @@ -2377,3 +2386,14 @@ class AutocompleteWithDifferentOrigin {
selectedValue: string;
values = ['one', 'two', 'three'];
}


@Component({
template: `
<input autocomplete="changed" [(ngModel)]="value" [matAutocomplete]="auto"/>
<mat-autocomplete #auto="matAutocomplete"></mat-autocomplete>
`
})
class AutocompleteWithNativeAutocompleteAttribute {
value: string;
}