Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

Fix hover outline (#689)

Bogdan Chadkin57bc857fe3c5
diff --git a/apps/designer/app/canvas/hovered-instance-connector.ts b/apps/designer/app/canvas/hovered-instance-connector.ts
index e4c0955dc4..f57645b4b5 100644
--- a/apps/designer/app/canvas/hovered-instance-connector.ts
+++ b/apps/designer/app/canvas/hovered-instance-connector.ts
@@ -32,21 +32,28 @@ const startHoveredInstanceConnection = (rootInstance: Instance) => {
});
}, 50);
+ let mouseOutTimeoutId: undefined | ReturnType<typeof setTimeout> = undefined;
+
const handleMouseOver = (event: MouseEvent) => {
- const element = event.target;
- if (element instanceof Element) {
- // store hovered element locally to update outline when scroll ends
- hoveredElement = element;
- publishHover(element);
+ if (event.target instanceof Element) {
+ const element = event.target.closest(`[${idAttribute}]`) ?? undefined;
+ if (element !== undefined) {
+ clearTimeout(mouseOutTimeoutId);
+ // store hovered element locally to update outline when scroll ends
+ hoveredElement = element;
+ publishHover(element);
+ }
}
};
const handleMouseOut = () => {
- hoveredElement = undefined;
- publish({
- type: "hoverInstance",
- payload: undefined,
- });
+ mouseOutTimeoutId = setTimeout(() => {
+ hoveredElement = undefined;
+ publish({
+ type: "hoverInstance",
+ payload: undefined,
+ });
+ }, 100);
};
const eventOptions = { passive: true };
@@ -90,6 +97,7 @@ const startHoveredInstanceConnection = (rootInstance: Instance) => {
window.removeEventListener("mouseout", handleMouseOut);
unsubscribeNavigatorHoveredInstance();
unsubscribeScrollState();
+ clearTimeout(mouseOutTimeoutId);
};
};