Skip to content

Commit 6267ea5

Browse files
committed
fix(autocomplete): panelClosingActions emitting when tabbing away from a closed autocomplete
Fixes the `MatAutocompleteTrigger.panelClosingActions` emitting when the user tabs away from an autocomplete that was closed already. Fixes #8763.
1 parent 5210b3e commit 6267ea5

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/lib/autocomplete/autocomplete-trigger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
193193
get panelClosingActions(): Observable<MatOptionSelectionChange> {
194194
return merge(
195195
this.optionSelections,
196-
this.autocomplete._keyManager.tabOut,
196+
this.autocomplete._keyManager.tabOut.pipe(filter(() => this._panelOpen)),
197197
this._escapeEventStream,
198198
this._outsideClickStream
199199
);

src/lib/autocomplete/autocomplete.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,6 +1370,23 @@ describe('MatAutocomplete', () => {
13701370
});
13711371
}));
13721372

1373+
it('should not emit if tabbing away from a closed pabel', async(() => {
1374+
const tabEvent = createKeyboardEvent('keydown', TAB);
1375+
input.focus();
1376+
1377+
fixture.whenStable().then(() => {
1378+
trigger._handleKeydown(tabEvent);
1379+
1380+
// Ensure that it emitted once while the panel was open.
1381+
expect(closingActionSpy).toHaveBeenCalledTimes(1);
1382+
1383+
trigger._handleKeydown(tabEvent);
1384+
1385+
// Ensure that it didn't emit again when tabbing out again.
1386+
expect(closingActionSpy).toHaveBeenCalledTimes(1);
1387+
});
1388+
}));
1389+
13731390
it('should emit panel close event when selecting an option', async(() => {
13741391
fixture.whenStable().then(() => {
13751392
const option = overlayContainerElement.querySelector('mat-option') as HTMLElement;

0 commit comments

Comments
 (0)