Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Text Area in material-ui

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

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

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.

like image 834
Johann Gomes Avatar asked Sep 24 '17 18:09

Johann Gomes


People also ask

How do you make a text field mandatory in material UI?

We can use TextField component in Material UI to show input textbox. import TextField from "@material-ui/core/TextField"; When using the TextField component, we can pass the required attribute to mark the component as required.

How do I increase the TextField size in material UI?

Set MUI Width and Height with 'InputProps' Another method for setting Material-UI TextField width and height is a combination of sx at the TextField root and passing sx styling values to the composing Input component via InputProps . The width is set with TextField prop sx={{width: 300}} .

How do I get TextField value MUI?

MUI TextField Default Value The MUI TextField can display a default value on render by using the defaultValue prop. This is useful if you don't need to externally get or set the TextField value, or if you are using a form. A form will automatically extract a TextField child components value on submit of the form.


2 Answers

To make TextField work like a textarea you can use multiline prop. You can read more about TextFied and its props here.

Example

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

You can set maxRows={Infinity} if you want to scale your multiline input box with your content (regardless of the content length).

like image 180
bennygenel Avatar answered Oct 10 '22 05:10

bennygenel


We can use outlined multiline <TextField> for text area
and it could be implemented by creating a theme to apply globally anywhere inside <App/>

theme.js

import { createMuiTheme} from '@material-ui/core/styles'; const theme = createMuiTheme({  overrides: {     MuiOutlinedInput: {         multiline: {             fontWeight: 'bold',             fontSize: '20px',             color: 'purple',             width: '50vw'         }     } }    }); export default theme; 

app.js

... import { ThemeProvider } from '@material-ui/core/styles'; import Theme from './relevant-path-where-the-above-theme.js-file-is-saved/Theme'; ... ... render() {          return (       <ThemeProvider theme={Theme}>         <div className="App">              <Routes/>         </div>       </ThemeProvider>              );   } 

SomeComponent.js

... <TextField   id="outlined-multiline-static"   label="Multiline"   multiline   rows={10}   variant="outlined" /> ... 

Now the style for outlined multiline <TextField> will be applied globally enter image description here

like image 44
Sampath kumar Avatar answered Oct 10 '22 05:10

Sampath kumar