Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deselecting block when inspector is opened #32361

Merged
merged 1 commit into from
Jun 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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