Skip to content

fix(material/autocomplete): not closing when clicking outside using auxiliary button #21397

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

Merged
merged 1 commit into from
Jan 9, 2021
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
12 changes: 12 additions & 0 deletions src/material-experimental/mdc-autocomplete/autocomplete.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,18 @@ describe('MDC-based MatAutocomplete', () => {
.toEqual('', `Expected clicking outside the panel to close the panel.`);
}));

it('should close the panel when the user clicks away via auxilliary button', fakeAsync(() => {
dispatchFakeEvent(input, 'focusin');
fixture.detectChanges();
zone.simulateZoneExit();
dispatchFakeEvent(document, 'auxclick');

expect(fixture.componentInstance.trigger.panelOpen)
.toBe(false, `Expected clicking outside the panel to set its state to closed.`);
expect(overlayContainerElement.textContent)
.toEqual('', `Expected clicking outside the panel to close the panel.`);
}));

it('should close the panel when the user taps away on a touch device', fakeAsync(() => {
dispatchFakeEvent(input, 'focus');
fixture.detectChanges();
Expand Down
1 change: 1 addition & 0 deletions src/material/autocomplete/autocomplete-trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ export abstract class _MatAutocompleteTriggerBase implements ControlValueAccesso
private _getOutsideClickStream(): Observable<any> {
return merge(
fromEvent(this._document, 'click') as Observable<MouseEvent>,
fromEvent(this._document, 'auxclick') as Observable<MouseEvent>,
fromEvent(this._document, 'touchend') as Observable<TouchEvent>)
.pipe(filter(event => {
// If we're in the Shadow DOM, the event target will be the shadow root, so we have to
Expand Down
12 changes: 12 additions & 0 deletions src/material/autocomplete/autocomplete.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,18 @@ describe('MatAutocomplete', () => {
.toEqual('', `Expected clicking outside the panel to close the panel.`);
}));

it('should close the panel when the user clicks away via auxilliary button', fakeAsync(() => {
dispatchFakeEvent(input, 'focusin');
fixture.detectChanges();
zone.simulateZoneExit();
dispatchFakeEvent(document, 'auxclick');

expect(fixture.componentInstance.trigger.panelOpen)
.toBe(false, `Expected clicking outside the panel to set its state to closed.`);
expect(overlayContainerElement.textContent)
.toEqual('', `Expected clicking outside the panel to close the panel.`);
}));

it('should close the panel when the user taps away on a touch device', fakeAsync(() => {
dispatchFakeEvent(input, 'focus');
fixture.detectChanges();
Expand Down