Skip to content

Commit

Permalink
fix(field): use onChange return as preventDefault only in RN (#4596)
Browse files Browse the repository at this point in the history
Issue #4309 adds a way to cancel dispatches from RN. However, the method
added also impacts React Web. This leads to a regression in React Web
due to application of RN behavior.

The current change locks the change from #4309 to RN, and maintains
existing behavior otherwise.

Related:
- #4391 outlines a case where this regression may cause problems. While
  the issue mentions RN, this can easily occur outside RN as well.
- #4401 describes a similar issue and a user-end fix.
  • Loading branch information
timhwang21 authored and iamandrewluca committed Jan 13, 2020
1 parent cddbc2c commit 12ad4ec
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/ConnectedField.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,12 @@ const createConnectedField = (structure: Structure<*, *>) => {
name
)
} else {
defaultPrevented = onChange(event, newValue, previousValue, name)
const onChangeResult = onChange(event, newValue, previousValue, name)
// Return value of change handler affecting preventDefault is RN
// specific behavior.
if (isReactNative) {
defaultPrevented = onChangeResult
}
}
}
if (!defaultPrevented) {
Expand Down

0 comments on commit 12ad4ec

Please sign in to comment.