@@ -44,6 +44,7 @@ import {
44
44
import { MatFormField } from '@angular/material/form-field' ;
45
45
import { Subscription , defer , fromEvent , merge , of as observableOf , Subject , Observable } from 'rxjs' ;
46
46
import { MatAutocomplete } from './autocomplete' ;
47
+ import { coerceBooleanProperty } from '@angular/cdk/coercion' ;
47
48
48
49
49
50
/**
@@ -93,12 +94,12 @@ export function getMatAutocompleteMissingPanelError(): Error {
93
94
@Directive ( {
94
95
selector : `input[matAutocomplete], textarea[matAutocomplete]` ,
95
96
host : {
96
- 'role' : 'combobox' ,
97
97
'autocomplete' : 'off' ,
98
- 'aria-autocomplete' : 'list' ,
98
+ '[attr.role]' : 'autocompleteDisabled ? null : "combobox"' ,
99
+ '[attr.aria-autocomplete]' : 'autocompleteDisabled ? null : "list"' ,
99
100
'[attr.aria-activedescendant]' : 'activeOption?.id' ,
100
- '[attr.aria-expanded]' : 'panelOpen.toString()' ,
101
- '[attr.aria-owns]' : 'autocomplete?.id' ,
101
+ '[attr.aria-expanded]' : 'autocompleteDisabled ? null : panelOpen.toString()' ,
102
+ '[attr.aria-owns]' : 'autocompleteDisabled ? null : autocomplete?.id' ,
102
103
// Note: we use `focusin`, as opposed to `focus`, in order to open the panel
103
104
// a little earlier. This avoids issues where IE delays the focusing of the input.
104
105
'(focusin)' : '_handleFocus()' ,
@@ -113,6 +114,7 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
113
114
private _overlayRef : OverlayRef | null ;
114
115
private _portal : TemplatePortal ;
115
116
private _componentDestroyed = false ;
117
+ private _autocompleteDisabled = false ;
116
118
117
119
/** Old value of the native input. Used to work around issues with the `input` event on IE. */
118
120
private _previousValue : string | number | null ;
@@ -141,6 +143,16 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
141
143
/** The autocomplete panel to be attached to this trigger. */
142
144
@Input ( 'matAutocomplete' ) autocomplete : MatAutocomplete ;
143
145
146
+ /**
147
+ * Whether the autocomplete is disabled. When disabled, the element will
148
+ * act as a regular input and the user won't be able to open the panel.
149
+ */
150
+ @Input ( 'matAutocompleteDisabled' )
151
+ get autocompleteDisabled ( ) : boolean { return this . _autocompleteDisabled ; }
152
+ set autocompleteDisabled ( value : boolean ) {
153
+ this . _autocompleteDisabled = coerceBooleanProperty ( value ) ;
154
+ }
155
+
144
156
constructor ( private _element : ElementRef , private _overlay : Overlay ,
145
157
private _viewContainerRef : ViewContainerRef ,
146
158
private _zone : NgZone ,
@@ -569,7 +581,7 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
569
581
/** Determines whether the panel can be opened. */
570
582
private _canOpen ( ) : boolean {
571
583
const element : HTMLInputElement = this . _element . nativeElement ;
572
- return ! element . readOnly && ! element . disabled ;
584
+ return ! element . readOnly && ! element . disabled && ! this . _autocompleteDisabled ;
573
585
}
574
586
575
587
}
0 commit comments