Skip to content

Commit

Permalink
Merge pull request #154 from yulinscottkang/popup
Browse files Browse the repository at this point in the history
fix: isPopupVisible logic for AzureMapHtmlMarker
  • Loading branch information
yulinscottkang authored May 4, 2023
2 parents ad7b87f + eaaeda3 commit b29a631
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
1 change: 1 addition & 0 deletions __mocks__/azure-maps-control.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ module.exports = {
isOpen: jest.fn(() => true),
open: jest.fn(() => false),
togglePopup: jest.fn(),
setOptions: jest.fn(),
close: jest.fn()
}
}))
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-azure-maps",
"version": "0.4.6",
"version": "0.4.7",
"description": "React Wrapper for Azure Maps",
"keywords": [
"react",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { render } from '@testing-library/react'
import { Map, Popup } from 'azure-maps-control'
import React from 'react'
import { AzureMapsContext } from '../../../contexts/AzureMapContext'
import AzureMaphtmlMarker from './AzureMapHtmlMarker'
import AzureMapHtmlMarker from './AzureMapHtmlMarker'
import { IAzureMapHtmlMarker } from '../../../types'
import atlas from 'azure-maps-control'

Expand All @@ -23,7 +23,7 @@ const wrapWithAzureMapContext = (props: IAzureMapHtmlMarker) => {
mapRef
}}
>
<AzureMaphtmlMarker {...{ ...props }} />
<AzureMapHtmlMarker {...{ ...props }} />
</AzureMapsContext.Provider>
)
}
Expand Down Expand Up @@ -81,13 +81,13 @@ describe('AzureMaphtmlMarker tests', () => {
expect(markerRef.setOptions).toHaveBeenCalledWith({ htmlContent: '<div></div>' })
})

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

it('should open marker popup', () => {
it('should close marker popup', () => {
render(wrapWithAzureMapContext({ isPopupVisible: false, markerContent: <div /> }))
// Currently we only check if getOptions get called @TODO
expect(markerRef.getOptions).toHaveBeenCalled()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const AzureMapHtmlMarker = memo(
)
const { mapRef } = useContext<IAzureMapsContextProps>(AzureMapsContext)

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

useEffect(() => {
if (markerRef && markerRef.getOptions().popup && mapRef) {
const isMarkerPopupOpen = markerRef.getOptions().popup?.isOpen()
if (isMarkerPopupOpen && isPopupVisible) {
markerRef.getOptions().popup?.close()
} else if (isMarkerPopupOpen !== undefined) {
markerRef.getOptions().popup?.open()
} else if ((isPopupVisible && isMarkerPopupOpen) || isPopupVisible) {
markerRef.togglePopup()
const popupRef = markerRef.getOptions().popup
if (isPopupVisible) {
popupRef?.setOptions({
position: markerRef.getOptions().position
})
popupRef?.open(mapRef)
} else {
popupRef?.close()
}
}
}, [isPopupVisible, options, mapRef])
Expand Down

0 comments on commit b29a631

Please sign in to comment.