Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(autocomplete): panelClosingActions emitting when tabbing away from a closed autocomplete #8774

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/autocomplete/autocomplete-trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
get panelClosingActions(): Observable<MatOptionSelectionChange> {
return merge(
this.optionSelections,
this.autocomplete._keyManager.tabOut,
this.autocomplete._keyManager.tabOut.pipe(filter(() => this._panelOpen)),
this._escapeEventStream,
this._outsideClickStream
);
Expand Down
17 changes: 17 additions & 0 deletions src/lib/autocomplete/autocomplete.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1333,6 +1333,23 @@ describe('MatAutocomplete', () => {
expect(closingActionSpy).toHaveBeenCalled();
});

it('should not emit when tabbing away from a closed panel', () => {
const tabEvent = createKeyboardEvent('keydown', TAB);

input.focus();
zone.simulateZoneExit();

trigger._handleKeydown(tabEvent);

// Ensure that it emitted once while the panel was open.
expect(closingActionSpy).toHaveBeenCalledTimes(1);

trigger._handleKeydown(tabEvent);

// Ensure that it didn't emit again when tabbing out again.
expect(closingActionSpy).toHaveBeenCalledTimes(1);
});

it('should emit panel close event when selecting an option', () => {
const option = overlayContainerElement.querySelector('mat-option') as HTMLElement;

Expand Down