From b112948130e9251af947b3b1743df61f4e484d3e Mon Sep 17 00:00:00 2001 From: afc163 Date: Sun, 16 Jul 2017 15:39:21 +0800 Subject: [PATCH] TextArea should be resetable in form, close #6776 --- components/input/TextArea.tsx | 5 ++++ components/input/__tests__/index.test.js | 34 ++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/components/input/TextArea.tsx b/components/input/TextArea.tsx index 02c5624c77..eb12b0678e 100644 --- a/components/input/TextArea.tsx +++ b/components/input/TextArea.tsx @@ -110,6 +110,11 @@ export default class TextArea extends React.Component { expect(mockFunc).toHaveBeenCalledTimes(2); }); }); + +describe('As Form Control', () => { + it('should be reset when wrapped in form.getFieldDecorator without initialValue', async () => { + class Demo extends React.Component { + reset = () => { + this.props.form.resetFields(); + } + render() { + const { getFieldDecorator } = this.props.form; + return ( +
+ + {getFieldDecorator('input')()} + + + {getFieldDecorator('textarea')()} + + +
+ ); + } + } + const DemoForm = Form.create()(Demo); + const wrapper = mount(); + wrapper.find('input').simulate('change', { target: { value: '111' } }); + wrapper.find('textarea').simulate('change', { target: { value: '222' } }); + expect(wrapper.find('input').prop('value')).toBe('111'); + expect(wrapper.find('textarea').prop('value')).toBe('222'); + wrapper.find('button').simulate('click'); + expect(wrapper.find('input').prop('value')).toBe(''); + expect(wrapper.find('textarea').prop('value')).toBe(''); + }); +});