qwik icon indicating copy to clipboard operation
qwik copied to clipboard

Unexpected call of `onClick$` event on `button` element when `disabled={true}` [🐞]

Open MiguelValdez-mv opened this issue 3 years ago • 3 comments

Which component is affected?

Qwik Runtime

Describe the bug

Starting from the following example:

export const CustomText = component$(() => (
   <span>
     <Slot />
   <span>
))

export default component$(() => (
   <>
     <button disabled onClick$={() => console.log("Test 1")}>
       Test 1
     </button>

     <button disabled onClick$={() => console.log("Test 2")}>
       <CustomText> Test 2 <CustomText>
     </button>
   </>
))

You have that when pressing the Test 1 button the onClick$ event does not occur, because disabled={true}, which is fine. However, pressing the Test 2 button displays the Test 2 console because that button's onClick$ event is called despite disabled={true} which should not happen.

Reproduction

https://stackblitz.com/edit/qwik-starter-e5zbny?file=src/root.tsx

Steps to reproduce

Execute npm run start

System Info

System:
    OS: Linux 5.11 elementary OS 6.1 Jólnir
    CPU: (12) x64 AMD Ryzen 5 5500U with Radeon Graphics
    Memory: 2.81 GB / 7.12 GB
    Container: Yes
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 16.18.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/bin/yarn
    npm: 8.19.2 - /usr/local/bin/npm
  Browsers:
    Chrome: 107.0.5304.87
    Chromium: 107.0.5304.110

Additional Information

No response

MiguelValdez-mv avatar Nov 24 '22 00:11 MiguelValdez-mv

Just tried to reproduce this on the playground and it seems to work correctly. This may already be fixed in latest?

Playground example

nnelgxorz avatar Dec 03 '22 23:12 nnelgxorz

@nnelgxorz I just checked and still the error is still there in the latest version.

Here is a 20 second video showing the error:

https://www.loom.com/share/0589e14c271a4c22bee0733051684ab6

MiguelValdez-mv avatar Dec 07 '22 14:12 MiguelValdez-mv

Hi everyone,

just accidentally faced the same problem. Clicking on subnode of disabled button is not prevented. Found one fast crutch-solution, maybe it helps someone:

const btnHandler = $((event: MouseEvent) => {
    if (!(event.target as Element)?.closest("button")?.disabled) {
      // do something
    }
  });

deadenddeveloper avatar Feb 08 '23 15:02 deadenddeveloper

this works as expected in v1.3.5.

hamatoyogi avatar Jan 18 '24 13:01 hamatoyogi