diff --git a/src/google-maps/map-info-window/map-info-window.spec.ts b/src/google-maps/map-info-window/map-info-window.spec.ts index c13c1741c8ca..3b14834cf611 100644 --- a/src/google-maps/map-info-window/map-info-window.spec.ts +++ b/src/google-maps/map-info-window/map-info-window.spec.ts @@ -129,7 +129,13 @@ describe('MapInfoWindow', () => { expect(infoWindowSpy.close).toHaveBeenCalled(); infoWindowComponent.open(fakeMarkerComponent); - expect(infoWindowSpy.open).toHaveBeenCalledWith(mapSpy, fakeMarker); + expect(infoWindowSpy.open).toHaveBeenCalledWith( + jasmine.objectContaining({ + map: mapSpy, + anchor: fakeMarker, + shouldFocus: undefined, + }), + ); }); it('should not try to reopen info window multiple times for the same marker', () => { @@ -224,6 +230,29 @@ describe('MapInfoWindow', () => { infoWindowComponent.open(); expect(infoWindowSpy.open).toHaveBeenCalledTimes(1); }); + + it('should allow for the focus behavior to be changed when opening the info window', () => { + const fakeMarker = {} as unknown as google.maps.Marker; + const fakeMarkerComponent = { + marker: fakeMarker, + getAnchor: () => fakeMarker, + } as unknown as MapMarker; + const infoWindowSpy = createInfoWindowSpy({}); + createInfoWindowConstructorSpy(infoWindowSpy).and.callThrough(); + + const fixture = TestBed.createComponent(TestApp); + const infoWindowComponent = fixture.debugElement + .query(By.directive(MapInfoWindow))! + .injector.get(MapInfoWindow); + fixture.detectChanges(); + + infoWindowComponent.open(fakeMarkerComponent, false); + expect(infoWindowSpy.open).toHaveBeenCalledWith( + jasmine.objectContaining({ + shouldFocus: false, + }), + ); + }); }); @Component({ diff --git a/src/google-maps/map-info-window/map-info-window.ts b/src/google-maps/map-info-window/map-info-window.ts index 85d014bb9c70..faf84b6e51c1 100644 --- a/src/google-maps/map-info-window/map-info-window.ts +++ b/src/google-maps/map-info-window/map-info-window.ts @@ -168,7 +168,7 @@ export class MapInfoWindow implements OnInit, OnDestroy { * Opens the MapInfoWindow using the provided anchor. If the anchor is not set, * then the position property of the options input is used instead. */ - open(anchor?: MapAnchorPoint) { + open(anchor?: MapAnchorPoint, shouldFocus?: boolean) { this._assertInitialized(); const anchorObject = anchor ? anchor.getAnchor() : undefined; @@ -178,7 +178,13 @@ export class MapInfoWindow implements OnInit, OnDestroy { // 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); + + // The config is cast to `any`, because the internal typings are out of date. + this.infoWindow.open({ + map: this._googleMap.googleMap, + anchor: anchorObject, + shouldFocus, + } as any); } } diff --git a/src/google-maps/testing/fake-google-map-utils.ts b/src/google-maps/testing/fake-google-map-utils.ts index 57c8d79b507f..a1bf7bc58c45 100644 --- a/src/google-maps/testing/fake-google-map-utils.ts +++ b/src/google-maps/testing/fake-google-map-utils.ts @@ -148,7 +148,7 @@ export function createInfoWindowSpy( 'get', ]); infoWindowSpy.addListener.and.returnValue({remove: () => {}}); - infoWindowSpy.open.and.callFake((_map: any, target: any) => (anchor = target)); + infoWindowSpy.open.and.callFake((config: any) => (anchor = config.anchor)); infoWindowSpy.close.and.callFake(() => (anchor = null)); infoWindowSpy.get.and.callFake((key: string) => (key === 'anchor' ? anchor : null)); return infoWindowSpy; diff --git a/tools/public_api_guard/google-maps/google-maps.md b/tools/public_api_guard/google-maps/google-maps.md index a58e189075c3..3fa90123c9df 100644 --- a/tools/public_api_guard/google-maps/google-maps.md +++ b/tools/public_api_guard/google-maps/google-maps.md @@ -329,7 +329,7 @@ export class MapInfoWindow implements OnInit, OnDestroy { ngOnDestroy(): void; // (undocumented) ngOnInit(): void; - open(anchor?: MapAnchorPoint): void; + open(anchor?: MapAnchorPoint, shouldFocus?: boolean): void; // (undocumented) set options(options: google.maps.InfoWindowOptions); // (undocumented)