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): not resetting completely when overlay is detached externally #8515

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
6 changes: 3 additions & 3 deletions src/lib/autocomplete/autocomplete-trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
OverlayRef,
OverlayConfig,
PositionStrategy,
RepositionScrollStrategy,
ScrollStrategy,
} from '@angular/cdk/overlay';
import {TemplatePortal} from '@angular/cdk/portal';
Expand Down Expand Up @@ -67,7 +66,7 @@ export const MAT_AUTOCOMPLETE_SCROLL_STRATEGY =

/** @docs-private */
export function MAT_AUTOCOMPLETE_SCROLL_STRATEGY_PROVIDER_FACTORY(overlay: Overlay):
() => RepositionScrollStrategy {
() => ScrollStrategy {
return () => overlay.scrollStrategies.reposition();
}

Expand Down Expand Up @@ -195,7 +194,8 @@ export class MatAutocompleteTrigger implements ControlValueAccessor, OnDestroy {
this.optionSelections,
this.autocomplete._keyManager.tabOut,
this._escapeEventStream,
this._outsideClickStream
this._outsideClickStream,
this._overlayRef ? this._overlayRef.detachments() : observableOf()
);
}

Expand Down
26 changes: 25 additions & 1 deletion src/lib/autocomplete/autocomplete.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Direction, Directionality} from '@angular/cdk/bidi';
import {DOWN_ARROW, ENTER, ESCAPE, SPACE, UP_ARROW, TAB} from '@angular/cdk/keycodes';
import {OverlayContainer} from '@angular/cdk/overlay';
import {OverlayContainer, Overlay} from '@angular/cdk/overlay';
import {map} from 'rxjs/operators/map';
import {startWith} from 'rxjs/operators/startWith';
import {ScrollDispatcher} from '@angular/cdk/scrolling';
Expand Down Expand Up @@ -35,6 +35,7 @@ import {
MatAutocompleteModule,
MatAutocompleteSelectedEvent,
MatAutocompleteTrigger,
MAT_AUTOCOMPLETE_SCROLL_STRATEGY,
} from './index';


Expand Down Expand Up @@ -1534,6 +1535,29 @@ describe('MatAutocomplete', () => {
}));


it('should reset correctly when closed programmatically', async(() => {
TestBed.overrideProvider(MAT_AUTOCOMPLETE_SCROLL_STRATEGY, {
useFactory: (overlay: Overlay) => () => overlay.scrollStrategies.close(),
deps: [Overlay]
});

const fixture = TestBed.createComponent(SimpleAutocomplete);
fixture.detectChanges();
const trigger = fixture.componentInstance.trigger;

trigger.openPanel();
fixture.detectChanges();

fixture.whenStable().then(() => {
expect(trigger.panelOpen).toBe(true, 'Expected panel to be open.');

scrolledSubject.next();
fixture.detectChanges();

expect(trigger.panelOpen).toBe(false, 'Expected panel to be closed.');
});
}));

});

it('should have correct width when opened', () => {
Expand Down