Skip to content

Commit 5f8615f

Browse files
crisbetoandrewseguin
authored andcommitted
fix(autocomplete): don't open panel for readonly inputs (#7271)
Prevents the autocomplete panel from opening if the associated input is readonly. Fixes #7269.
1 parent f076390 commit 5f8615f

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/lib/autocomplete/autocomplete-trigger.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,10 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
296296
}
297297

298298
_handleFocus(): void {
299-
this._attachOverlay();
300-
this._floatPlaceholder(true);
299+
if (!this._element.nativeElement.readOnly) {
300+
this._attachOverlay();
301+
this._floatPlaceholder(true);
302+
}
301303
}
302304

303305
/**

src/lib/autocomplete/autocomplete.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,20 @@ describe('MatAutocomplete', () => {
118118
});
119119
}));
120120

121+
it('should not open the panel on focus if the input is readonly', async(() => {
122+
const trigger = fixture.componentInstance.trigger;
123+
input.readOnly = true;
124+
fixture.detectChanges();
125+
126+
expect(trigger.panelOpen).toBe(false, 'Expected panel state to start out closed.');
127+
dispatchFakeEvent(input, 'focusin');
128+
129+
fixture.whenStable().then(() => {
130+
fixture.detectChanges();
131+
expect(trigger.panelOpen).toBe(false, 'Expected panel to stay closed.');
132+
});
133+
}));
134+
121135
it('should open the panel programmatically', async(() => {
122136
expect(fixture.componentInstance.trigger.panelOpen)
123137
.toBe(false, `Expected panel state to start out closed.`);

0 commit comments

Comments
 (0)