Skip to content

Commit

Permalink
Adding container ref to try to position the popover
Browse files Browse the repository at this point in the history
  • Loading branch information
ramonjd committed Sep 14, 2021
1 parent d79a1d9 commit 43897bd
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/block-editor/src/components/block-styles/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { useCallback, useMemo, useState } from '@wordpress/element';
import { useCallback, useMemo, useRef, useState } from '@wordpress/element';
import { useSelect, useDispatch } from '@wordpress/data';
import { ENTER, SPACE } from '@wordpress/keycodes';
import { _x } from '@wordpress/i18n';
Expand Down Expand Up @@ -83,6 +83,8 @@ function BlockStyles( {
[ setHoveredStyle ]
);

const stylesContainerRef = useRef();

if ( ! styles || styles.length === 0 ) {
return null;
}
Expand Down Expand Up @@ -113,8 +115,11 @@ function BlockStyles( {
onSwitch();
};

// const getAnchorRect = () =>
// stylesContainerRef?.current?.getBoundingClientRect();

return (
<div className="block-editor-block-styles">
<div className="block-editor-block-styles" ref={ stylesContainerRef }>
<div className="block-editor-block-styles__variants">
{ renderedStyles.map( ( style ) => {
const buttonText = style.label || style.name;
Expand Down Expand Up @@ -155,6 +160,8 @@ function BlockStyles( {
className="block-editor-block-styles__popover"
position="middle left"
focusOnMount={ false }
anchorRef={ stylesContainerRef?.current }
//getAnchorRect={ getAnchorRect }
>
<BlockStylesPreviewPanel
activeStyle={ activeStyle }
Expand Down

0 comments on commit 43897bd

Please sign in to comment.