Skip to content

Commit

Permalink
useBlockProps: fix selection scroll into view ref (#31835)
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix authored May 15, 2021
1 parent 98644ea commit 8c5f86e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,20 @@ export function useScrollIntoView( clientId ) {
[ clientId ]
);

// Note that we can't use `useRefEffect` here, since an element change does
// not mean we can scroll. `isSelectionEnd` should be the sole dependency,
// while with `useRefEffect`, the element is a dependency as well.
useEffect( () => {
if ( ! isSelectionEnd ) {
return;
}

const extentNode = ref.current;

if ( ! extentNode ) {
return;
}

// If the block is focused, the browser will already have scrolled into
// view if necessary.
if ( extentNode.contains( extentNode.ownerDocument.activeElement ) ) {
Expand Down
8 changes: 2 additions & 6 deletions packages/block-library/src/post-featured-image/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,10 @@ function PostFeaturedImageDisplay( {

const PostFeaturedImageWithNotices = withNotices( PostFeaturedImageDisplay );

const OutofContextPlaceholder = () => {
const blockProps = useBlockProps();
return <div { ...blockProps }>{ placeholderChip }</div>;
};

export default function PostFeaturedImageEdit( props ) {
const blockProps = useBlockProps();
if ( ! props.context?.postId ) {
return <OutofContextPlaceholder />;
return <div { ...blockProps }>{ placeholderChip }</div>;
}
return <PostFeaturedImageWithNotices { ...props } />;
}

0 comments on commit 8c5f86e

Please sign in to comment.