Skip to content

Commit 92dcd76

Browse files
crisbetoandrewseguin
authored andcommitted
fix(autocomplete): panelClosingActions emitting when tabbing away from a closed autocomplete (#8774)
Fixes the `MatAutocompleteTrigger.panelClosingActions` emitting when the user tabs away from an autocomplete that was closed already. Fixes #8763.
1 parent bbfec2b commit 92dcd76

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
@@ -1333,6 +1333,23 @@ describe('MatAutocomplete', () => {
13331333
expect(closingActionSpy).toHaveBeenCalled();
13341334
});
13351335

1336+
it('should not emit when tabbing away from a closed panel', () => {
1337+
const tabEvent = createKeyboardEvent('keydown', TAB);
1338+
1339+
input.focus();
1340+
zone.simulateZoneExit();
1341+
1342+
trigger._handleKeydown(tabEvent);
1343+
1344+
// Ensure that it emitted once while the panel was open.
1345+
expect(closingActionSpy).toHaveBeenCalledTimes(1);
1346+
1347+
trigger._handleKeydown(tabEvent);
1348+
1349+
// Ensure that it didn't emit again when tabbing out again.
1350+
expect(closingActionSpy).toHaveBeenCalledTimes(1);
1351+
});
1352+
13361353
it('should emit panel close event when selecting an option', () => {
13371354
const option = overlayContainerElement.querySelector('mat-option') as HTMLElement;
13381355

0 commit comments

Comments
 (0)