-
Notifications
You must be signed in to change notification settings - Fork 47k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[bug] click not disabled on <fieldset disabled><button onClick={() => alert('clicked')}><span>click me</span></button></fieldset> #7711
Comments
Thanks for the report @brillout, and for the great test case. I was able to reproduce using a build of the current master branch http://jsfiddle.net/jxx65yhy/ |
I'm fixing this issue |
1.I fixed this issue, but Is this way is correct? if click span, onClick will not fire
but in this case, if click span, onClick will fire
and more, if click span, onClick will fire
2.This issue didnt occuered in firefox.But Chrome, Safari has this issue. 3.I have question in the test.
|
Seems to be fixed in latest master. |
@acdlite have there been changes merged to master since |
I'm seeing this in 16.2.0, can we reopen? |
Still reproducible, makes |
This is still present in 16.8.0 |
I suppose React should use something like But this would probably be an expensive operation to perform on every button each time it's clicked. Is the core team working on a solution or should the community send a PR? For anyone looking for a quick workaround, you can change your <button
onClick={evt => !evt.currentTarget.matches(':disabled') ? handleOnClick(evt) : undefined}
/> |
Here's a codesandbox illustrating the bug. You can easily toggle between the React versions to troubleshoot. I have also confirmed that @FezVrasta's suggestion ☝️ does patch the bug for anyone looking for an interim solution.
|
@brillout can you update the title of this issue so that it might get more exposure? I am thinking it has been ignored due to its cryptic title. |
Hey! We are seeing this issue being reported in Headless UI, (tailwindlabs/headlessui#194).
I noticed that there was a PR for this (#17909), but the PR got closed because it had been reported as a bug for Mozilla #17909 (comment) However, I am seeing this issue in the following browsers (all tested on macOS Big Sur):
What would be the next steps? Is there anything you want me to do (re-open that PR for example)? |
Thanks for the repos @RobinMalfait. Looks like the browser is firing the click event for the span in both the React and Vanilla examples. The difference is, React bubbles that click up to the button, which it shouldn't do according to the spec:
I've added a test for this in #20612 which should be failing. Unfortunately, a bug in JSDOM prevents click events from firing on any child of a disabled fieldset (see here), so the test passes in our test suite. I believe the handling should be added somewhere around here but @gaearon @trueadm or @sophiebits may have more context. |
I'm not sure how performant this is, but one workaround is to add a check somewhere of whether the target element is disabled. For example, I forked @RobinMalfait 's repo to share an example of the workaround. |
bug
In the following
clicking on
click me here and
will not triggeralert('clicked by React')
whereas clicking on the redhere
will triggeralert('clicked by React')
.Demo: https://jsfiddle.net/ropbvL3y/
Thanks for React, it's an incredibly well designed tool.
The text was updated successfully, but these errors were encountered: