Browse Source
🐛 Fix Form throw error when using BraftEditor (#21425)
component.props.onChange should not run when it is falsy
close #21415
pull/21446/head
偏右
5 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
29 additions and
7 deletions
-
components/form/FormItem.tsx
-
components/form/__tests__/index.test.js
|
|
@ -279,12 +279,10 @@ function FormItem(props: FormItemProps): React.ReactElement { |
|
|
|
}); |
|
|
|
|
|
|
|
triggers.forEach(eventName => { |
|
|
|
if (eventName in mergedControl && eventName in children.props) { |
|
|
|
childProps[eventName] = (...args: any[]) => { |
|
|
|
mergedControl[eventName](...args); |
|
|
|
children.props[eventName](...args); |
|
|
|
}; |
|
|
|
} |
|
|
|
childProps[eventName] = (...args: any[]) => { |
|
|
|
mergedControl[eventName]?.(...args); |
|
|
|
children.props[eventName]?.(...args); |
|
|
|
}; |
|
|
|
}); |
|
|
|
|
|
|
|
childNode = React.cloneElement(children, childProps); |
|
|
|
|
|
@ -1,4 +1,4 @@ |
|
|
|
import React from 'react'; |
|
|
|
import React, { Component } from 'react'; |
|
|
|
import { mount } from 'enzyme'; |
|
|
|
import scrollIntoView from 'scroll-into-view-if-needed'; |
|
|
|
import Form from '..'; |
|
|
@ -522,4 +522,28 @@ describe('Form', () => { |
|
|
|
'Warning: [antd: Form.Item] `null` is passed as `name` property', |
|
|
|
); |
|
|
|
}); |
|
|
|
|
|
|
|
// https://github.com/ant-design/ant-design/issues/21415
|
|
|
|
it('Component.props.onChange is null', () => { |
|
|
|
// eslint-disable-next-line
|
|
|
|
class CustomComponent extends Component { |
|
|
|
static defaultProps = { |
|
|
|
onChange: null, |
|
|
|
}; |
|
|
|
|
|
|
|
render() { |
|
|
|
return <input {...this.props} />; |
|
|
|
} |
|
|
|
} |
|
|
|
expect(() => { |
|
|
|
const wrapper = mount( |
|
|
|
<Form> |
|
|
|
<Form.Item name="custom"> |
|
|
|
<CustomComponent /> |
|
|
|
</Form.Item> |
|
|
|
</Form>, |
|
|
|
); |
|
|
|
wrapper.find(CustomComponent).simulate('change', { value: '123' }); |
|
|
|
}).not.toThrow(); |
|
|
|
}); |
|
|
|
}); |
|
|
|