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

ancestor's stopPropagation() prevents controlled <select> from working #13451

Closed
jkr2255 opened this issue Aug 21, 2018 · 3 comments
Closed

ancestor's stopPropagation() prevents controlled <select> from working #13451

jkr2255 opened this issue Aug 21, 2018 · 3 comments

Comments

@jkr2255
Copy link

jkr2255 commented Aug 21, 2018

Do you want to request a feature or report a bug? bug

What is the current behavior?

When React component is mounted as a descendent of DOM element which stops propagation of change event, onChange event of <select> in React component does not occur.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem.

HTML structure

<!-- outer div's onchange event contains stopPropagation() -->
<div>
  <div id="react-root"></div>
</div>

React Component (only render())

render() {
  return(
    <select onChange={this.doesNotWork} value={this.state.value}>
      <option value=""></option>
      <option value="another">another option</option>
    </select>
  );
}

Reproduction in CodePen

What is the expected behavior?

<select onChange> works well just like <input> or <textarea>

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?

This issue occurred with React 16.4.2 (not tested for older React), newest Chrome, Firefox, Edge, IE11 on Windows 10.

@gaearon
Copy link
Collaborator

gaearon commented Aug 21, 2018

React binds events at the document level. You're experiencing this for selects specifically because React actually uses the change browser event for selects. For inputs and textarea, it currently uses the input event. So you can see the same exact issue with inputs if you "block" the input event.

I think we can close this as a duplicate of #2043 (which would solve this).

@gaearon gaearon closed this as completed Aug 21, 2018
@gaearon
Copy link
Collaborator

gaearon commented Aug 10, 2020

We're fixing this in React 17.

@gaearon
Copy link
Collaborator

gaearon commented Aug 11, 2020

If you want to try it, we released 17 RC yesterday with this change:
https://reactjs.org/blog/2020/08/10/react-v17-rc.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