2016-06-10 16:44:01 +08:00
|
|
|
---
|
|
|
|
order: 6
|
2016-08-22 09:53:39 +08:00
|
|
|
title:
|
2016-08-22 10:27:43 +08:00
|
|
|
zh-CN: 适应文本高度的文本域
|
2016-08-22 09:53:39 +08:00
|
|
|
en-US: Autosizing the height to fit the content
|
2016-06-10 16:44:01 +08:00
|
|
|
---
|
|
|
|
|
2016-08-22 09:53:39 +08:00
|
|
|
## zh-CN
|
|
|
|
|
2016-06-10 16:44:01 +08:00
|
|
|
`autosize` 属性适用于 `textarea` 节点,并且只有高度会自动变化。另外 `autosize` 可以设定为一个对象,指定最小行数和最大行数。
|
|
|
|
|
2016-08-22 09:53:39 +08:00
|
|
|
## en-US
|
|
|
|
|
|
|
|
`autosize` prop for a `textarea` type of `Input` makes the height to automatically adjust based on the content.
|
|
|
|
An options object can be provided to `autosize` to specify the minimum and maximum number of lines the textarea will automatically adjust.
|
|
|
|
|
2017-02-13 10:55:53 +08:00
|
|
|
````jsx
|
2016-06-10 16:44:01 +08:00
|
|
|
import { Input } from 'antd';
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2017-05-22 14:44:58 +08:00
|
|
|
const { TextArea } = Input;
|
2016-06-10 16:44:01 +08:00
|
|
|
|
|
|
|
ReactDOM.render(
|
|
|
|
<div>
|
2017-05-22 14:44:58 +08:00
|
|
|
<TextArea placeholder="Autosize height based on content lines" autosize />
|
2016-06-10 16:44:01 +08:00
|
|
|
<div style={{ margin: '24px 0' }} />
|
2017-05-22 14:44:58 +08:00
|
|
|
<TextArea placeholder="Autosize height with minimum and maximum number of lines" autosize={{ minRows: 2, maxRows: 6 }} />
|
2018-06-27 15:55:04 +08:00
|
|
|
</div>,
|
2018-11-28 15:00:03 +08:00
|
|
|
mountNode
|
|
|
|
);
|
2016-06-10 16:44:01 +08:00
|
|
|
````
|