question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

onClick firing for disabled buttons in v15.4.0

See original GitHub issue

With the latest 15.4.0 ReactJS release, onClick is now firing for disabled button elements which have child HTML elements:

https://jsfiddle.net/rcataldo/69z2wepo/62589/

In the previous ReactJS version, the onClick handler would not be called.

Note that onClick is not called if I remove the <span> from the button.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:11
  • Comments:19 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
RoccoCcommented, Nov 16, 2016

The target is the button element:

<button disabled onClick={() => { alert("Click!"); }}>
  <span>My Button</span>
</button>

The same but without the span works as expected and does not dispatch the event on the button:

<button disabled onClick={() => { alert("Click!"); }}>
  My Button
</button>
0reactions
bryantobing12commented, Jun 30, 2022

not sure if this is related.

In react when we set button props disabled, the onClick event will not fire. When the user enables the button from devtool/inspect-element by removing the disabled attribute from html. the onClick still will not fire. I have tried this and that’s work and this is my expected behavior. because I want to prevent users from clicking by role access to the button.

I’m just still not certain that this is correct.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Disabled button still fires using ".click()" - Stack Overflow
The attribute only disables user interaction, the button is still usable programmatically. So yeah, you gotta check
Read more >
react disable onclick conditional - You.com | The AI Search ...
onClick firing for disabled buttons in v15.4.0 · Issue #8308 ... ... Nov 16, 2016 ... In the previous ReactJS version, the onClick...
Read more >
disabled button on a page does not fires click event - MSDN
I am using a button on my page which is having onclick and onclienclick event both.on clientclick i disable that button but after...
Read more >
How to disable a button in JavaScript - Educative.io
In the code above, we created two buttons. We click the second button to disable or enable the first button, as follows: Lines...
Read more >
how to disable button(onclick javascript) after clicking that once?
If the button is placed on Standard Record Detail page then this button will always be available and cannot be disabled.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found