Skip to content

Commit

Permalink
fix(google-maps): info window not opening if no anchor is passed in (#…
Browse files Browse the repository at this point in the history
…21014)

Some time ago we added logic to prevent the info window from reopening if the same
anchor is passed in. This ended up breaking the use case where a window is opened
without an anchor, because the window always starts off without one.

Fixes #21013.

(cherry picked from commit 17c357f)
  • Loading branch information
crisbeto authored and wagnermaciel committed Nov 17, 2020
1 parent c1a65c3 commit 36cb325
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/google-maps/map-info-window/map-info-window.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,20 @@ describe('MapInfoWindow', () => {
expect(addSpy).toHaveBeenCalledWith('zindex_changed', jasmine.any(Function));
subscription.unsubscribe();
});

it('should be able to open an info window without passing in an anchor', () => {
const infoWindowSpy = createInfoWindowSpy({});
createInfoWindowConstructorSpy(infoWindowSpy).and.callThrough();

const fixture = TestBed.createComponent(TestApp);
const infoWindowComponent = fixture.debugElement.query(By.directive(
MapInfoWindow))!.injector.get<MapInfoWindow>(MapInfoWindow);
fixture.detectChanges();

infoWindowComponent.open();
expect(infoWindowSpy.open).toHaveBeenCalledTimes(1);
});

});

@Component({
Expand Down
7 changes: 5 additions & 2 deletions src/google-maps/map-info-window/map-info-window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,11 @@ export class MapInfoWindow implements OnInit, OnDestroy {
this._assertInitialized();
const anchorObject = anchor ? anchor.getAnchor() : undefined;

// Prevent the info window from initializing if trying to reopen on the same anchor.
if (this.infoWindow.get('anchor') !== anchorObject) {
// Prevent the info window from initializing when trying to reopen on the same anchor.
// Note that when the window is opened for the first time, the anchor will always be
// undefined. If that's the case, we have to allow it to open in order to handle the
// case where the window doesn't have an anchor, but is placed at a particular position.
if (this.infoWindow.get('anchor') !== anchorObject || !anchorObject) {
this._elementRef.nativeElement.style.display = '';
this.infoWindow.open(this._googleMap.googleMap, anchorObject);
}
Expand Down

0 comments on commit 36cb325

Please sign in to comment.