mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-25 11:40:04 +08:00
6776bb8916
* docs: update demo * chore: add script * test: fix demo test * docs: convert demos * chore: move script * test: remove react-dom import * chore: update deps * docs: update riddle js * test: fix image test * docs: fix riddle demo
55 lines
1.4 KiB
Markdown
55 lines
1.4 KiB
Markdown
---
|
|
order: 6
|
|
title:
|
|
zh-CN: 适应文本高度的文本域
|
|
en-US: Autosizing the height to fit the content
|
|
---
|
|
|
|
## zh-CN
|
|
|
|
`autoSize` 属性适用于 `textarea` 节点,并且只有高度会自动变化。另外 `autoSize` 可以设定为一个对象,指定最小行数和最大行数。
|
|
|
|
## en-US
|
|
|
|
`autoSize` prop for a `textarea` type of `Input` makes the height to automatically adjust based on the content. An option object can be provided to `autoSize` to specify the minimum and maximum number of lines the textarea will automatically adjust.
|
|
|
|
```jsx
|
|
import { Input } from 'antd';
|
|
|
|
const { TextArea } = Input;
|
|
|
|
class Demo extends React.Component {
|
|
state = {
|
|
value: '',
|
|
};
|
|
|
|
onChange = ({ target: { value } }) => {
|
|
this.setState({ value });
|
|
};
|
|
|
|
render() {
|
|
const { value } = this.state;
|
|
|
|
return (
|
|
<>
|
|
<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 }}
|
|
/>
|
|
</>
|
|
);
|
|
}
|
|
}
|
|
|
|
export default () => <Demo />;
|
|
```
|