diff --git a/projects/plugins/jetpack/changelog/fix-map-block-selection b/projects/plugins/jetpack/changelog/fix-map-block-selection new file mode 100644 index 0000000000000..989aae81cfcda --- /dev/null +++ b/projects/plugins/jetpack/changelog/fix-map-block-selection @@ -0,0 +1,4 @@ +Significance: patch +Type: enhancement + +Map block: Allow maps on WordPress.com to be selectable. diff --git a/projects/plugins/jetpack/extensions/blocks/map/component/mapkit.js b/projects/plugins/jetpack/extensions/blocks/map/component/mapkit.js index 0d70b9f2a7e11..37f6a44c57cac 100644 --- a/projects/plugins/jetpack/extensions/blocks/map/component/mapkit.js +++ b/projects/plugins/jetpack/extensions/blocks/map/component/mapkit.js @@ -1,4 +1,12 @@ -import { Children, forwardRef, memo, useCallback, useEffect, useRef } from '@wordpress/element'; +import { + Children, + forwardRef, + memo, + useCallback, + useEffect, + useRef, + useState, +} from '@wordpress/element'; import { get } from 'lodash'; import { MapkitProvider } from '../mapkit/context'; import { @@ -45,6 +53,7 @@ const MapkitComponent = forwardRef( return child; } } ); + const [ isSelected, setIsSelected ] = useState( false ); useEffect( () => { if ( error ) { @@ -52,6 +61,23 @@ const MapkitComponent = forwardRef( } }, [ error, onError ] ); + const handleBlockClick = () => { + setIsSelected( true ); + }; + + useEffect( () => { + const handleClickOutside = event => { + if ( ! mapRef.current.contains( event.target ) ) { + setIsSelected( false ); + } + }; + + document.addEventListener( 'mousedown', handleClickOutside ); + return () => { + document.removeEventListener( 'mousedown', handleClickOutside ); + }; + }, [ mapRef ] ); + return ( ) : null } + + { /* eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions */ }
+ onClick={ handleBlockClick } + > + { ! isSelected &&
} + { /* Map container */ } +
+
+ { addPoint } diff --git a/projects/plugins/jetpack/extensions/blocks/map/editor.scss b/projects/plugins/jetpack/extensions/blocks/map/editor.scss index 810a5c9c0f8ca..e482a2e52bb77 100644 --- a/projects/plugins/jetpack/extensions/blocks/map/editor.scss +++ b/projects/plugins/jetpack/extensions/blocks/map/editor.scss @@ -42,6 +42,21 @@ // This matches the color that MapBox uses as a placeholder before map tiles have loaded. background-color: #e4e2de; } + + .wp-block-jetpack-map__gm-container { + position: absolute; + inset: 0; + z-index: 0; + } + + /* Overlay for block selection */ + .wp-block-jetpack-map__select-overlay { + position: absolute; + inset: 0; + z-index: 2; + background-color: transparent; + pointer-events: auto; + } } .wp-block-jetpack-map__height_input {