fix: Not shaking with autosize of TextArea (#18401)

* fix: Not shaking with autosize of TextArea

* fix ract 15 demo

* fix demo

* add state

* handle event

* try to fix react 15 test case
This commit is contained in:
二货机器人 2019-08-22 11:55:37 +08:00 committed by GitHub
parent 7558273e32
commit b9b9675fe1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 42 additions and 12 deletions

View File

@ -45,7 +45,7 @@ class TextArea extends React.Component<TextAreaProps, TextAreaState> {
componentDidUpdate(prevProps: TextAreaProps) {
// Re-render with the new content then recalculate the height as required.
if (prevProps.value !== this.props.value) {
this.resizeOnNextFrame();
this.resizeTextarea();
}
}

View File

@ -230,6 +230,13 @@ exports[`renders ./components/input/demo/autosize-textarea.md correctly 1`] = `
class="ant-input"
placeholder="Autosize height with minimum and maximum number of lines"
/>
<div
style="margin:24px 0"
/>
<textarea
class="ant-input"
placeholder="Controlled autosize"
/>
</div>
`;

View File

@ -79,6 +79,7 @@ describe('TextArea', () => {
wrapper.setProps({ value: '1111' });
jest.runAllTimers();
expect(mockFunc).toHaveBeenCalledTimes(2);
wrapper.update();
expect(wrapper.find('textarea').props().style.overflow).toBeFalsy();
});

View File

@ -18,15 +18,37 @@ import { Input } from 'antd';
const { TextArea } = Input;
ReactDOM.render(
<div>
<TextArea placeholder="Autosize height based on content lines" autosize />
<div style={{ margin: '24px 0' }} />
<TextArea
placeholder="Autosize height with minimum and maximum number of lines"
autosize={{ minRows: 2, maxRows: 6 }}
/>
</div>,
mountNode,
);
class Demo extends React.Component {
state = {
value: '',
};
onChange = ({ target: { value } }) => {
this.setState({ value });
};
render() {
const { value } = this.state;
return (
<div>
<TextArea placeholder="Autosize height based on content lines" autosize />
<div style={{ margin: '24px 0' }} />
<TextArea
placeholder="Autosize height with minimum and maximum number of lines"
autosize={{ minRows: 2, maxRows: 6 }}
/>
<div style={{ margin: '24px 0' }} />
<TextArea
value={value}
onChange={this.onChange}
placeholder="Controlled autosize"
autosize={{ minRows: 3, maxRows: 5 }}
/>
</div>
);
}
}
ReactDOM.render(<Demo />, mountNode);
```