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

Add event that behaves similar to the native change event #4126

Closed
dantman opened this issue Jun 15, 2015 · 5 comments
Closed

Add event that behaves similar to the native change event #4126

dantman opened this issue Jun 15, 2015 · 5 comments
Labels

Comments

@dantman
Copy link
Contributor

dantman commented Jun 15, 2015

Because React has repurposed onChange to behave like onInput there is no way to get actual change event behaviour without binding a non-delegated native event in lifecycle events.

change event behaviour is sometimes important to have. input-like behaviour does make sense for what React uses onChange for (live updating of state associated with value="" and anything derived from it). But other use cases, like triggering an ajax post once a user has finished with an input, require the standard behaviour of change for text inputs where it is only fired after a user is finished with the input.

These use cases are reasonable to support within React. If onChange is going to be changed to behave in a non-standard way. Then we should add another custom non-standard event name that lets React elements bind to behaviour that is closer to how change behaves (with React's event delegation handling).

Event name ideas:

  • onChangeCommit(ted)
  • onCommit(ted)Change
  • onValueCommit(ted)
  • onCommitValue
  • onCommit?

The idea of using "commit" in the name comes from the HTML spec.

The change event fires when the value is committed, [...]

~ Section 4.10.5.5 Common event behaviours

@sophiebits
Copy link
Collaborator

We've suggested in the past binding to onBlur if that's the semantics you want. Does that work for you?

@dantman
Copy link
Contributor Author

dantman commented Jun 15, 2015

onBlur fires on every blur even if nothing has changed.

Why should developers have to fake an event behaviour when a native standard event has that exact behaviour?

@Andreyco
Copy link

I am in this situation too very often.
Standard events offer perfect control over reading value of input.

Very good example is Range input. onInput is triggered continuously, while dragging handle.
https://jsfiddle.net/69dqhmcc/1/. onChange on blur or drag end.
In React, both events are triggered at very same time. https://jsfiddle.net/69z2wepo/25123/

I understand React's way of handling input/change events simplifies things. With only onChange handler you are subscribed to live updates.

What's the reason behind this decision? Is it even possible to move closer to standard behaviour at this stage?

@stale
Copy link

stale bot commented Jan 10, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution.

@stale stale bot added the Resolution: Stale Automatically closed due to inactivity label Jan 10, 2020
@stale
Copy link

stale bot commented Jan 19, 2020

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please create a new issue with up-to-date information. Thank you!

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

No branches or pull requests

4 participants