Skip to content
Closed
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
20 changes: 16 additions & 4 deletions packages/core/src/components/_utils/web-view/WebView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,23 @@ export const WebView: FC<WebViewProps> = forwardRef<HTMLIFrameElement>(({ source
};
}, [focus, hovered]);

const onMouseOver = () => {
const onMouseEnter = () => {
setHovered(true);
};

const onMouseOut = () => {
const onMouseLeave = (e: React.MouseEvent<HTMLDivElement>) => {
// In Firefox, entering an iframe triggers a mouseleave event because it's a different document.
// We verify if the mouse is still within the bounds of the WebView to prevent losing hover state.
const rect = e.currentTarget.getBoundingClientRect();
if (
e.clientX > rect.left &&
e.clientX < rect.right &&
e.clientY > rect.top &&
e.clientY < rect.bottom
) {
return;
}

window.focus();
setHovered(false);
};
Expand All @@ -47,7 +59,7 @@ export const WebView: FC<WebViewProps> = forwardRef<HTMLIFrameElement>(({ source
delete iframeProps.setIconUrl;
delete iframeProps.standalone;

return <div className={styles.WebView} onMouseOver={onMouseOver} onMouseOut={onMouseOut}>
return <div className={styles.WebView} onMouseEnter={onMouseEnter} onMouseLeave={onMouseLeave}>
<iframe
ref={ref}
src={source}
Expand All @@ -56,4 +68,4 @@ export const WebView: FC<WebViewProps> = forwardRef<HTMLIFrameElement>(({ source
{...iframeProps}
/>
</div>;
}) as FC;
}) as FC;