mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
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:
committed by
Andrew Seguin
parent
f076390010
commit
5f8615fdbc
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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.`);
|
||||
|
||||
Reference in New Issue
Block a user