mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-02 12:09:14 +08:00
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:
parent
7558273e32
commit
b9b9675fe1
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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>
|
||||
`;
|
||||
|
||||
|
@ -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();
|
||||
});
|
||||
|
||||
|
@ -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);
|
||||
```
|
||||
|
Loading…
Reference in New Issue
Block a user