Skip to content

Commit bb9a694

Browse files
committed
fix: select parent click function throws error when element is of svg type
1 parent 5c66487 commit bb9a694

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,14 @@ function RemoteFunctions(config = {}) {
295295

296296
const parentElement = element.parentElement;
297297
if (isElementEditable(parentElement)) {
298-
parentElement.click();
298+
// Check if parent element has .click() method (HTML elements)
299+
// SVG elements don't have .click() method, so we use _selectElement for them
300+
if (typeof parentElement.click === 'function') {
301+
parentElement.click();
302+
} else {
303+
activateHoverLock();
304+
_selectElement(parentElement);
305+
}
299306
} else {
300307
console.error("The TagID might be unavailable or the parent element tag is directly body or html");
301308
}
@@ -3439,6 +3446,22 @@ function RemoteFunctions(config = {}) {
34393446
}
34403447
}
34413448

3449+
/**
3450+
* this function activates hover lock to prevent hover events
3451+
* Used when user performs click actions to avoid UI box conflicts
3452+
*/
3453+
function activateHoverLock() {
3454+
if (_hoverLockTimer) {
3455+
clearTimeout(_hoverLockTimer);
3456+
}
3457+
3458+
disableHoverListeners();
3459+
_hoverLockTimer = setTimeout(() => {
3460+
enableHoverListeners();
3461+
_hoverLockTimer = null;
3462+
}, 1500); // 1.5s
3463+
}
3464+
34423465
/**
34433466
* This function handles the click event on the live preview DOM element
34443467
* this just stops the propagation because otherwise users might not be able to edit buttons or hyperlinks etc
@@ -3451,18 +3474,7 @@ function RemoteFunctions(config = {}) {
34513474
event.preventDefault();
34523475
event.stopPropagation();
34533476
event.stopImmediatePropagation();
3454-
3455-
// clear any existing timer before starting new one
3456-
if (_hoverLockTimer) {
3457-
clearTimeout(_hoverLockTimer);
3458-
}
3459-
3460-
// disable hover listeners for 2 seconds to prevent info box conflicts
3461-
disableHoverListeners();
3462-
_hoverLockTimer = setTimeout(() => {
3463-
enableHoverListeners();
3464-
_hoverLockTimer = null;
3465-
}, 1500);
3477+
activateHoverLock();
34663478
}
34673479
}
34683480

0 commit comments

Comments
 (0)