Skip to content

Commit

Permalink
fix(autocomplete): don't override native autocomplete attribute (#11926)
Browse files Browse the repository at this point in the history
  • Loading branch information
crisbeto authored and josephperrott committed Jun 27, 2018
1 parent 5aac678 commit ee9ddfb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
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;
}

0 comments on commit ee9ddfb

Please sign in to comment.