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

Bug: onChange fires too often when using range sliders #7614

Closed
woutervh- opened this issue Aug 30, 2016 · 1 comment
Closed

Bug: onChange fires too often when using range sliders #7614

woutervh- opened this issue Aug 30, 2016 · 1 comment

Comments

@woutervh-
Copy link

React version 15.3.0
Chrome version 52.0.2743.116 m (64-bit)

Current behavior:
React fires onChange events for <input> with type range even when the browser's input change event does not fire.

Example:

<div id="container"></div>
const container = document.getElementById("container");

class App extends React.Component {
  componentDidMount() {
    this.refs['slider'].addEventListener('change', event => console.log(event.target.value));
  }

  render() {
    return <div>
      <input type="range" onChange={event => console.log(event.target.value)}/>
      <input type="range" ref="slider"/>
    </div>;
  }
}

ReactDOM.render(<App/>, container);

Try it here

Expected behavior
Observe the console output while dragging the sliders. For the first slider, the behavior is incorrect and it fires onChange while dragging the slider. For the second slider, the behavior is correct, and can be seen as a workaround for the incorrect behavior.

Reference:
https://www.impressivewebs.com/onchange-vs-oninput-for-range-sliders/

@aweary
Copy link
Contributor

aweary commented Aug 30, 2016

Hey @woutervh-, thanks for the report. This is expected behavior, as React normalizes the onChange event so it's consistent across browsers. See @spicyj's comment #2454 (comment):

Our plan here is to make onChange consistently fire on every change in all browsers; see #554. You can use onBlur or maybe onMouseUp if that's the behavior you're looking for, but the native onChange event varies widely across browsers even if we don't do anything special in React so that's probably not what you want.

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

No branches or pull requests

2 participants