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

Skip adding preventDefault to onChange events in React Native #3460

Merged
merged 1 commit into from Oct 6, 2017

Conversation

jkomyno
Copy link
Contributor

@jkomyno jkomyno commented Sep 28, 2017

Bug

When using onChange in React Native, the users are faced with a couple possible error messages, as seen in #3153 and #3238.
This is due to the fact that it doesn't seem to be possible to properly extends React Native's event ( facebook/react-native#5507). My proposal is to skip adding .preventDefault to TextInput's onChange's event.

Tests

No test was broken

Eslint

Linting was respected

Closes #3153, closes #3238

@codecov-io
Copy link

codecov-io commented Sep 28, 2017

Codecov Report

Merging #3460 into master will decrease coverage by 0.06%.
The diff coverage is 80%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3460      +/-   ##
==========================================
- Coverage     100%   99.93%   -0.07%     
==========================================
  Files          68       68              
  Lines        1531     1533       +2     
==========================================
+ Hits         1531     1532       +1     
- Misses          0        1       +1
Impacted Files Coverage Δ
src/ConnectedField.js 98.94% <80%> (-1.06%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0837539...5136938. Read the comment docs.

@gustavohenke gustavohenke changed the title Closes #3153, #3238 Skip adding preventDefault to onChange events in React Native Sep 28, 2017
Copy link
Collaborator

@gustavohenke gustavohenke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading thru facebook/react-native#5507, it seems like the solution is Object.defineProperty.
Only one user claimed to have issues with it. Have you tried using it?

And, even though no tests broke, the coverage decreased, what means at least one test should be written 😄

@jkomyno
Copy link
Contributor Author

jkomyno commented Sep 28, 2017

@gustavohenke Yep, I've already tried it, and with it I only achieved to delay the error: instead of appearing at the first change, it would appear at the second.
Also, I've tried the "lazy" way, described here, but calling event.preventDefault() from the app side wouldn't do anything (double checked with proper console.logs)

@jkomyno
Copy link
Contributor Author

jkomyno commented Sep 28, 2017

As per the tests, you're actually right, here's my plan.
The test should assert that in a RN environment the following snippet would throw:

onChange(
  {
    ...event,
    preventDefault: () => {
      defaultPrevented = true
      return eventPreventDefault(event)
    }
  },
  newValue,
  previousValue
)

My issue is that I have no idea on how to emulate RN's TextInput's event. Would you mind helping me with the test? @gustavohenke

@jkomyno
Copy link
Contributor Author

jkomyno commented Oct 6, 2017

@erikras this PR is used in production by me with no issues whatsoever, but unfortunately I wasn't able to create a test for this PR (to avoid codecov alerts).
Would you please know how to simulate a React Native Event class for a unit test?

@erikras
Copy link
Member

erikras commented Oct 6, 2017

Hmm... I'm seeing 100% code coverage when I run it locally. I'm going to merge and then fix any codecov problems later.

@erikras erikras merged commit bbc071b into redux-form:master Oct 6, 2017
@jkomyno
Copy link
Contributor Author

jkomyno commented Oct 6, 2017

Thanks @erikras!

@AlimovSV the PR has been finally merged!

@AlimovSV
Copy link

AlimovSV commented Oct 6, 2017

Thanks @erikras, @jkomyno!

@erikras
Copy link
Member

erikras commented Oct 6, 2017

Published in v7.1.0.

jkomyno pushed a commit to jkomyno/redux-form that referenced this pull request Oct 9, 2017
erikras pushed a commit that referenced this pull request Oct 9, 2017
* Extends logic of PR #3460 to onFocus and onBlur. Also prevents issue #3489 locking version of immutable

* Removed useless line breaks
@lock
Copy link

lock bot commented Jun 1, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 1, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

onChange, react native, assign throw Error when using onChange in ReactNative
5 participants