admin管理员组文章数量:1425815
I'm creating a Gutenberg block that contains a live map (like Google Maps or OpenStreetMaps). The issue I run into is that clicking on the map doesn't select the block, so that the toolbar and inspector controls never show up. I'm able to capture the click, but I'm not sure what command I should call to select the block that contains the map the user clicked on.
I tried looking through the docs but couldn't find an API for this. I also tried calling click()
on several divs that wrap the block, but no luck.
I also noticed that other blocks that have to deal with this kind of dynamic content use a div that overlays on top of the dynamic content to sidestep this issue. I'm trying to not use this kind of method to give the user a very dynamic editing experience.
The registerBlockType
edit prop returns this:
wp.element.createElement('div', {className: 'map-block-wrapper'},
wp.element.createElement(MapBlock.default, createOptions)
)
You can see that this uses a MapBlock React component. This is the custom component I wrote to display the dynamic map. Instead of posting the entire file I'll just put the relevant parts here.
MapBlock.js:
constructor(props) {
super(props)
this.el = React.createRef()
//Load third party mapping library (like google, etc)
this.map = new google.maps.Map(this.el, mapOptions);
}
render() {
return (<div className="map" ref={this.el} style={{height: '350px'}} />)
}
This displays the map on the editor, but since you can zoom and pan the map with the mouse, the mouse events are captured and they don't bubble to the editor to show the toolbar and the block inspector.
本文标签: How can I programmatically select a Gutenberg block
版权声明:本文标题:How can I programmatically select a Gutenberg block? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745452457a2658950.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论