Skip to content

Commit ffe5912

Browse files
author
Scott Kang
committed
fix: isPopupVisible logic for AzureMapHtmlMarker
1 parent 89d656c commit ffe5912

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

__mocks__/azure-maps-control.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ module.exports = {
6767
isOpen: jest.fn(() => true),
6868
open: jest.fn(() => false),
6969
togglePopup: jest.fn(),
70+
setOptions: jest.fn(),
7071
close: jest.fn()
7172
}
7273
}))

src/components/AzureMapMarkers/AzureMapHtmlMarker/AzureMapHtmlMarker.test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { render } from '@testing-library/react'
22
import { Map, Popup } from 'azure-maps-control'
33
import React from 'react'
44
import { AzureMapsContext } from '../../../contexts/AzureMapContext'
5-
import AzureMaphtmlMarker from './AzureMapHtmlMarker'
5+
import AzureMapHtmlMarker from './AzureMapHtmlMarker'
66
import { IAzureMapHtmlMarker } from '../../../types'
77
import atlas from 'azure-maps-control'
88

@@ -23,7 +23,7 @@ const wrapWithAzureMapContext = (props: IAzureMapHtmlMarker) => {
2323
mapRef
2424
}}
2525
>
26-
<AzureMaphtmlMarker {...{ ...props }} />
26+
<AzureMapHtmlMarker {...{ ...props }} />
2727
</AzureMapsContext.Provider>
2828
)
2929
}
@@ -81,13 +81,13 @@ describe('AzureMaphtmlMarker tests', () => {
8181
expect(markerRef.setOptions).toHaveBeenCalledWith({ htmlContent: '<div></div>' })
8282
})
8383

84-
it('should close marker popup', () => {
84+
it('should open marker popup', () => {
8585
render(wrapWithAzureMapContext({ isPopupVisible: true, markerContent: <div /> }))
8686
// Currently we only check if getOptions get called @TODO
8787
expect(markerRef.getOptions).toHaveBeenCalled()
8888
})
8989

90-
it('should open marker popup', () => {
90+
it('should close marker popup', () => {
9191
render(wrapWithAzureMapContext({ isPopupVisible: false, markerContent: <div /> }))
9292
// Currently we only check if getOptions get called @TODO
9393
expect(markerRef.getOptions).toHaveBeenCalled()

src/components/AzureMapMarkers/AzureMapHtmlMarker/AzureMapHtmlMarker.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const AzureMapHtmlMarker = memo(
1616
)
1717
const { mapRef } = useContext<IAzureMapsContextProps>(AzureMapsContext)
1818

19-
useCheckRefMount<MapType, boolean>(mapRef, true, mref => {
19+
useCheckRefMount<MapType, boolean>(mapRef, true, (mref) => {
2020
mref.markers.add(markerRef)
2121
events &&
2222
events.forEach(({ eventName, callback }) => {
@@ -38,13 +38,14 @@ const AzureMapHtmlMarker = memo(
3838

3939
useEffect(() => {
4040
if (markerRef && markerRef.getOptions().popup && mapRef) {
41-
const isMarkerPopupOpen = markerRef.getOptions().popup?.isOpen()
42-
if (isMarkerPopupOpen && isPopupVisible) {
43-
markerRef.getOptions().popup?.close()
44-
} else if (isMarkerPopupOpen !== undefined) {
45-
markerRef.getOptions().popup?.open()
46-
} else if ((isPopupVisible && isMarkerPopupOpen) || isPopupVisible) {
47-
markerRef.togglePopup()
41+
const popupRef = markerRef.getOptions().popup
42+
if (isPopupVisible) {
43+
popupRef?.setOptions({
44+
position: markerRef.getOptions().position
45+
})
46+
popupRef?.open(mapRef)
47+
} else {
48+
popupRef?.close()
4849
}
4950
}
5051
}, [isPopupVisible, options, mapRef])

0 commit comments

Comments
 (0)