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

Assembler: Fix the action bar stuck #83452

Merged
merged 3 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
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 @@ -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
Loading