Skip to content

Commit 564efe0

Browse files
authored
fix: Prevent focus when selecting form label in builder (#4516)
## Description Prevent forwarding the click event on an input element when the associated label has a "for" attribute In real browser emulates click event on input when label is clicked. closes #4513 ## Steps for reproduction 1. click button 2. expect xyz ## Code Review - [ ] hi @kof, I need you to do - conceptual review (architecture, feature-correctness) - detailed review (read every line) - test it on preview ## Before requesting a review - [ ] made a self-review - [ ] added inline comments where things may be not obvious (the "why", not "what") ## Before merging - [ ] tested locally and on preview environment (preview dev login: 0000) - [ ] updated [test cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md) document - [ ] added tests - [ ] if any new env variables are added, added them to `.env` file
1 parent 7975fce commit 564efe0

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

apps/builder/app/canvas/interceptor.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,15 @@ const switchPageAndUpdateSystem = (href: string, formData?: FormData) => {
7070

7171
export const subscribeInterceptedEvents = () => {
7272
const handleClick = (event: MouseEvent) => {
73+
// Prevent forwarding the click event on an input element when the associated label has a "for" attribute
74+
if (
75+
event.target instanceof Element &&
76+
event.target.closest("label[for]") &&
77+
!$isPreviewMode.get()
78+
) {
79+
event.preventDefault();
80+
}
81+
7382
if (
7483
event.target instanceof HTMLElement ||
7584
event.target instanceof SVGElement

0 commit comments

Comments
 (0)