-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BlockPopover: Remove __unstableCoverTarget and __unstableRefreshSize …
…in favour of BlockPopoverCover (#59228) * BlockPopover: Remove __unstableRefreshSize prop and improve how __unstableCoverTarget works * BlockPopover: Remove __unstableCoverTarget in favour of BlockPopoverCover Co-authored-by: noisysocks <noisysocks@git.wordpress.org> Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
- Loading branch information
1 parent
27dbbe6
commit b8cc4b8
Showing
8 changed files
with
80 additions
and
61 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
packages/block-editor/src/components/block-popover/cover.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useEffect, useState, useMemo, forwardRef } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { __unstableUseBlockElement as useBlockElement } from '../block-list/use-block-props/use-block-refs'; | ||
import BlockPopover from '.'; | ||
|
||
function BlockPopoverCover( | ||
{ clientId, bottomClientId, children, shift = false, ...props }, | ||
ref | ||
) { | ||
bottomClientId ??= clientId; | ||
|
||
const selectedElement = useBlockElement( clientId ); | ||
|
||
return ( | ||
<BlockPopover | ||
ref={ ref } | ||
clientId={ clientId } | ||
bottomClientId={ bottomClientId } | ||
shift={ shift } | ||
{ ...props } | ||
> | ||
{ selectedElement && clientId === bottomClientId ? ( | ||
<CoverContainer selectedElement={ selectedElement }> | ||
{ children } | ||
</CoverContainer> | ||
) : ( | ||
children | ||
) } | ||
</BlockPopover> | ||
); | ||
} | ||
|
||
function CoverContainer( { selectedElement, children } ) { | ||
const [ width, setWidth ] = useState( selectedElement.offsetWidth ); | ||
const [ height, setHeight ] = useState( selectedElement.offsetHeight ); | ||
|
||
useEffect( () => { | ||
const observer = new window.ResizeObserver( () => { | ||
setWidth( selectedElement.offsetWidth ); | ||
setHeight( selectedElement.offsetHeight ); | ||
} ); | ||
observer.observe( selectedElement, { box: 'border-box' } ); | ||
return () => observer.disconnect(); | ||
}, [ selectedElement ] ); | ||
|
||
const style = useMemo( () => { | ||
return { | ||
position: 'absolute', | ||
width, | ||
height, | ||
}; | ||
}, [ width, height ] ); | ||
|
||
return <div style={ style }>{ children }</div>; | ||
} | ||
|
||
export default forwardRef( BlockPopoverCover ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
b8cc4b8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flaky tests detected in b8cc4b8.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.
🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7999467658
📝 Reported issues:
/test/e2e/specs/editor/blocks/navigation.spec.js
/test/e2e/specs/editor/blocks/navigation.spec.js