Skip to content

Commit

Permalink
Fix deselecting block when inspector is opened (#32361)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin940726 authored and youknowriad committed Jun 7, 2021
1 parent cde3a5a commit 29c3626
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ export default function useClearSelectedBlock( sidebarControl, popoverRef ) {

useEffect( () => {
if ( popoverRef.current && sidebarControl ) {
const inspectorContainer =
sidebarControl.inspector.contentContainer[ 0 ];
const inspector = sidebarControl.inspector;
const container = sidebarControl.container[ 0 ];
const ownerDocument = container.ownerDocument;
const ownerWindow = ownerDocument.defaultView;
Expand All @@ -42,11 +41,12 @@ export default function useClearSelectedBlock( sidebarControl, popoverRef ) {
// 2. The element should exist in the DOM (not deleted).
element &&
ownerDocument.contains( element ) &&
// 3. It should also not exist in the container, inspector, nor the popover.
// 3. It should also not exist in the container, the popover, nor the dialog.
! container.contains( element ) &&
! popoverRef.current.contains( element ) &&
! inspectorContainer.contains( element ) &&
! element.closest( '[role="dialog"]' )
! element.closest( '[role="dialog"]' ) &&
// 4. The inspector should not be opened.
! inspector.expanded()
) {
clearSelectedBlock();
}
Expand Down

0 comments on commit 29c3626

Please sign in to comment.