Skip to content

Commit

Permalink
Assembler: Fix the action bar stuck (#83452)
Browse files Browse the repository at this point in the history
* Assembler: Fix the action bar stuck

* Fix type errors

* Fix overflow
  • Loading branch information
arthur791004 authored Oct 25, 2023
1 parent e74a900 commit 4d1bc0f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

.pattern-action-bar__action {
height: 40px;
white-space: nowrap;

&.has-icon {
min-width: 40px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ const PatternLargePreview = ( {
};

const handleMouseLeave = ( event: React.MouseEvent< HTMLElement > ) => {
if ( ! frameRef.current?.contains( event.relatedTarget as Node ) ) {
const hasNextActiveElement =
event.relatedTarget instanceof Node &&
! frameRef.current?.contains( event.relatedTarget as Node );
if ( ! hasNextActiveElement ) {
setActiveElement( null );
}
};
Expand Down Expand Up @@ -213,16 +216,23 @@ const PatternLargePreview = ( {
useEffect( () => {
const handleMouseLeave = ( event: MouseEvent ) => {
const relatedTarget = event.relatedTarget as HTMLElement | null;
if ( ! relatedTarget?.closest( '.pattern-assembler__pattern-action-bar' ) ) {
if ( ! relatedTarget?.closest?.( '.pattern-assembler__pattern-action-bar' ) ) {
setActiveElement( null );
}
};

// When the value of the `hasSelectedPattern` changes, it will append/remove the
// frame to the DOM. Hence, we need to check the value to bind the event again
// after the frame is removed and then appended to the DOM.
if ( ! hasSelectedPattern ) {
return;
}

frameRef.current?.addEventListener( 'mouseleave', handleMouseLeave );
return () => {
frameRef.current?.removeEventListener( 'mouseleave', handleMouseLeave );
};
}, [ frameRef, setActiveElement ] );
}, [ frameRef, hasSelectedPattern, setActiveElement ] );

return (
<DeviceSwitcher
Expand Down

0 comments on commit 4d1bc0f

Please sign in to comment.