Skip to content

Commit

Permalink
Customize Widgets: Fix block toolbar deselection when clicking scroll…
Browse files Browse the repository at this point in the history
…bar (#32762)

* Remove overflow inherit style

* Switch to using mousedown instead of focusin

* Revert style change
  • Loading branch information
talldan authored and youknowriad committed Jun 21, 2021
1 parent 8157317 commit de2ac25
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
transition: border-color 0.1s linear, box-shadow 0.1s linear;
@include reduce-motion("transition");

// Allow overflow on desktop.
@include break-small() {
overflow: inherit;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,23 @@ export default function useClearSelectedBlock( sidebarControl, popoverRef ) {
}
}

// Handle focusing in the same document.
function handleFocus( event ) {
// Handle mouse down in the same document.
function handleMouseDown( event ) {
handleClearSelectedBlock( event.target );
}
// Handle focusing outside the current document, like to iframes.
function handleBlur() {
handleClearSelectedBlock( ownerDocument.activeElement );
}

ownerDocument.addEventListener( 'focusin', handleFocus );
ownerDocument.addEventListener( 'mousedown', handleMouseDown );
ownerWindow.addEventListener( 'blur', handleBlur );

return () => {
ownerDocument.removeEventListener( 'focusin', handleFocus );
ownerDocument.removeEventListener(
'mousedown',
handleMouseDown
);
ownerWindow.removeEventListener( 'blur', handleBlur );
};
}
Expand Down

0 comments on commit de2ac25

Please sign in to comment.