fix(autocomplete): don't open panel for readonly inputs (#7271)

Prevents the autocomplete panel from opening if the associated input is readonly.

Fixes #7269.
This commit is contained in:
Kristiyan Kostadinov
2017-09-29 22:05:49 +02:00
committed by Andrew Seguin
parent f076390010
commit 5f8615fdbc
2 changed files with 18 additions and 2 deletions
+4 -2
View File
@@ -296,8 +296,10 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
}
_handleFocus(): void {
this._attachOverlay();
this._floatPlaceholder(true);
if (!this._element.nativeElement.readOnly) {
this._attachOverlay();
this._floatPlaceholder(true);
}
}
/**
+14
View File
@@ -118,6 +118,20 @@ describe('MatAutocomplete', () => {
});
}));
it('should not open the panel on focus if the input is readonly', async(() => {
const trigger = fixture.componentInstance.trigger;
input.readOnly = true;
fixture.detectChanges();
expect(trigger.panelOpen).toBe(false, 'Expected panel state to start out closed.');
dispatchFakeEvent(input, 'focusin');
fixture.whenStable().then(() => {
fixture.detectChanges();
expect(trigger.panelOpen).toBe(false, 'Expected panel to stay closed.');
});
}));
it('should open the panel programmatically', async(() => {
expect(fixture.componentInstance.trigger.panelOpen)
.toBe(false, `Expected panel state to start out closed.`);