admin管理员组文章数量:1189208
I am developing a site where we want to use Gutenberg's Popover component to show custom options in the Popover when a specific key is entered in the block editor. I have used KeyboardShortcuts component to register a new shortcut, now I am trying to integrate the Popover. For some reason, Popover is not getting positioned relative to the focused element in the block editor and it shows in the left corner of the document.
How could we position it in the block editor just like Blocks popover?
Core Block Popover position:
Custom Popover position:
Here is my code:
const [ popoverAnchor, setPopoverAnchor ] = useState()
const [ isAllSelected, setIsAllSelected ] = useState( false )
const selectAll = ( e ) => {
document.activeElement.setAttribute( 'ref', setPopoverAnchor )
setTimeout( () => {
setIsAllSelected( true )
}, 1000 )
}
return (
<div>
<KeyboardShortcuts
shortcuts={ {
'mod+/': selectAll,
} }
bindGlobal="true"
/>
[cmd/ctrl + A] Combination pressed? { isAllSelected ? 'Yes' : 'No' }
{ isAllSelected && <Popover anchor={ popoverAnchor } yAxis="top" xAxis="right">Popover is toggled!</Popover> }
</div>
)
本文标签: plugin developmentGutenberg39s Popover component position relative to the focused element
版权声明:本文标题:plugin development - Gutenberg's Popover component position relative to the focused element 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738400900a2084774.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论