Javascript material-ui中的文本区域

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46393703/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 03:25:42  来源:igfitidea点击:

Text Area in material-ui

javascriptreactjsmaterial-ui

提问by Johann Gomes

Could someone help me making a TextField personalization into a TextArea, using material-ui library? I am not finding any parameter that should personalize it into a TextArea: https://github.com/callemall/material-ui/blob/v1-beta/src/TextField/TextField.d.ts

有人可以帮助我使用 material-ui 库将 TextField 个性化设置为 TextArea 吗?我没有找到任何应​​该将其个性化为 TextArea 的参数:https: //github.com/callemall/material-ui/blob/v1-beta/src/TextField/TextField.d.ts

This is the TextArea:https://material.io/guidelines/components/text-fields.html#text-fields-field-types(CMD/Ctrl + F 'Text area').

这是文本区域:https: //material.io/guidelines/components/text-fields.html#text-fields-field-types(CMD/Ctrl + F '文本区域')。

Text areas are taller than text fields and wrap overflow text onto a new line. They scroll vertically when the cursor reaches the bottom of the field.

文本区域比文本字段高,并将溢出文本换行到新行。当光标到达字段底部时,它们会垂直滚动。

回答by bennygenel

To make TextFieldwork like a textareayou can use multilineprop. You can read more about TextFiedand its propshere.

为了使TextField工作像一个textarea你可以使用multiline道具。你可以在这里阅读更多关于TextFied它的props信息

Example

例子

<TextField
  placeholder="MultiLine with rows: 2 and rowsMax: 4"
  multiline
  rows={2}
  rowsMax={4}
/>

回答by Rishav Kumar

You should use TextareaAutosizeAPI available in material UI.

您应该使用TextareaAutosizeMaterial UI 中可用的 API。

import TextareaAutosize from '@material-ui/core/TextareaAutosize';
// or
import { TextareaAutosize } from '@material-ui/core';**

The following example has all the attributes of TextareaAutosize: https://material-ui.com/components/textarea-autosize/

以下示例具有 TextareaAutosize 的所有属性:https: //material-ui.com/components/textarea-autosize/