Skip to content
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

handleClickOutside not called when clicking on a disabled button #352

Open
karl opened this issue Apr 22, 2021 · 4 comments
Open

handleClickOutside not called when clicking on a disabled button #352

karl opened this issue Apr 22, 2021 · 4 comments

Comments

@karl
Copy link

karl commented Apr 22, 2021

I think I've come across a bug in this library where clicking on a disabled button does not trigger handleClickOutside.

See this CodeSandbox for a minimal recreation of the bug:

https://codesandbox.io/s/react-onclickoutside-does-not-work-with-disabled-buttons-mio5q

Let me know if you need any more info!

@Pomax
Copy link
Owner

Pomax commented Apr 22, 2021

The only element I can reproduce this for is the disabled text input, and then only in Firefox - Chrome seems to work correctly on every disabled element for me in Windows. Which OS/browser combination(s) did you find this in?

@karl
Copy link
Author

karl commented Apr 22, 2021 via email

@karl
Copy link
Author

karl commented Apr 22, 2021

Urgh, I just spotted that the Code Sandbox link I sent before wasn't correctly set up (it still contained a work around I was trying for the bug). I've removed the workaround and it should now be demonstrating the problem with clicking on disabled buttons.

@Pomax
Copy link
Owner

Pomax commented Apr 23, 2021

Yep, that's doing what you described. Reduced test case:

import React, { Component } from "react";
import { render } from "react-dom";
import onClickOutside from "react-onclickoutside";

class Clicker extends Component {
  state = { numClicks: 0 }

  render = () => 
    <div style={{background:`lightgrey`}}>
      Num clicks {this.state.numClicks}
    </div>

  handleClickOutside() {
    this.setState({
      numClicks: this.state.numClicks + 1
    });
  };
}

const WrappedClicker = onClickOutside(Clicker);

render([
  <WrappedClicker />,
  <input disabled value="test"/>
], document.getElementsByTagName(`div`)[0]);

with HTML:

<!DOCTYPE html>
<html>
  <head><title>React App</title></head>
  <body><div></div></body>
</html>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants