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

fix: send an event-like object into Field onChange when no event (#4548) #4604

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 21 additions & 16 deletions src/ConnectedField.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,16 @@ const createConnectedField = (structure: Structure<*, *>) => {
return !!(
this.props.children ||
nextProps.children ||
(nextPropsKeys.length !== thisPropsKeys.length ||
nextPropsKeys.some(prop => {
if (~(nextProps.immutableProps || []).indexOf(prop)) {
return this.props[prop] !== nextProps[prop]
}
return (
!~propsToNotUpdateFor.indexOf(prop) &&
!deepEqual(this.props[prop], nextProps[prop])
)
}))
nextPropsKeys.length !== thisPropsKeys.length ||
nextPropsKeys.some(prop => {
if (~(nextProps.immutableProps || []).indexOf(prop)) {
return this.props[prop] !== nextProps[prop]
}
return (
!~propsToNotUpdateFor.indexOf(prop) &&
!deepEqual(this.props[prop], nextProps[prop])
)
})
)
}

Expand All @@ -93,7 +93,7 @@ const createConnectedField = (structure: Structure<*, *>) => {
return this.ref.current
}

handleChange = (event: any) => {
handleChange = (eventOrValue: any) => {
const {
name,
dispatch,
Expand All @@ -103,7 +103,7 @@ const createConnectedField = (structure: Structure<*, *>) => {
_reduxForm,
value: previousValue
} = this.props
const newValue = onChangeValue(event, { name, parse, normalize })
const newValue = onChangeValue(eventOrValue, { name, parse, normalize })

let defaultPrevented = false
if (onChange) {
Expand All @@ -112,21 +112,26 @@ const createConnectedField = (structure: Structure<*, *>) => {
// to prevent the following error:
// `One of the sources for assign has an enumerable key on the prototype chain`
// Reference: https://github.com/facebook/react-native/issues/5507
if (!isReactNative && isEvent(event)) {
if (!isReactNative) {
onChange(
{
...event,
...(isEvent(eventOrValue) ? eventOrValue : (undefined: any)),
preventDefault: () => {
defaultPrevented = true
return eventPreventDefault(event)
return eventPreventDefault(eventOrValue)
}
},
newValue,
previousValue,
name
)
} else {
const onChangeResult = onChange(event, newValue, previousValue, name)
const onChangeResult = onChange(
eventOrValue,
newValue,
previousValue,
name
)
// Return value of change handler affecting preventDefault is RN
// specific behavior.
if (isReactNative) {
Expand Down