Skip to content

Commit

Permalink
Update interactive condition and move call inline versus within useEf…
Browse files Browse the repository at this point in the history
…fect
  • Loading branch information
louwie17 committed Sep 16, 2024
1 parent 3eaf30f commit f4349e4
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions packages/block-library/src/embed/embed-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import clsx from 'clsx';
import { __, sprintf } from '@wordpress/i18n';
import { Placeholder, SandBox } from '@wordpress/components';
import { BlockIcon } from '@wordpress/block-editor';
import { useState, useEffect } from '@wordpress/element';
import { useState } from '@wordpress/element';
import { getAuthority } from '@wordpress/url';

/**
Expand All @@ -38,11 +38,12 @@ export default function EmbedPreview( {
} ) {
const [ interactive, setInteractive ] = useState( false );

useEffect( () => {
if ( isSelected && interactive ) {
setInteractive( false );
}
}, [ isSelected ] );
if ( ! isSelected && interactive ) {
// We only want to change this when the block is not selected, because changing it when
// the block becomes selected makes the overlap disappear too early. Hiding the overlay
// happens on mouseup when the overlay is clicked.
setInteractive( false );
}

const hideOverlay = () => {
// This is called onMouseUp on the overlay. We can't respond to the `isSelected` prop
Expand Down

0 comments on commit f4349e4

Please sign in to comment.