Use inputComponent inside InputProps
to achieve customized text field inside the TextField
InputProps={{
inputComponent: () => (
<div style={{ color: "yellow" }}>XXXXXXXXXXXXXXXXX</div>
)
}}
Try it online:
Use inputComponent inside InputProps
to achieve customized text field inside the TextField
InputProps={{
inputComponent: () => (
<div style={{ color: "yellow" }}>XXXXXXXXXXXXXXXXX</div>
)
}}
Try it online:
You don’t have to do use div’s inside value attribute. You want the text to be styled, use InputProps
import React from "react";
import TextField from "@material-ui/core/TextField";
export default function App() {
return (
<>
<TextField
id="outlined-multiline-static"
fullWidth
rows="12"
value="Hi"
variant="outlined"
InputProps={{
style: {
color: "yellow"
}
}}
/>
</>
);
}
I tried below code and while I was expecting to get a yellowish Hi, I got [object Object]
instead.
Is there a way to fix it? maybe using InputProps
helps but unfortunately I couldn’t find any detailed tutorial about it.
<TextField
id="outlined-multiline-static"
label="Multiline"
multiline
fullWidth
rows="22"
value={<div> Hi <div style={{ color: "yellow" }}>There</div></div>}
variant="outlined"
/>
Edit:
I just simplified the problem and don’t want the whole of the text to be yellow.
https://codesandbox.io/s/hopeful-bush-gfi9m?fontsize=14&hidenavigation=1&theme=dark
you want the entire field to be yellow?
No, I just simplifed the problem. sorry I forgot to mention this in the question.
yes, I edit the question. thank you
It destroys rows=”22″ style.
The reason why it’s not multiline is that you customized that field with
I think it just make whole of the text yellow. sorry I forgot to mention I simplified the problem and don’t want whole of the text to be same color please check edit part
Did not get this edit part. Can you be a more specific
lets assume the value is
I mean what if we want to show {black}Hi + {yellow}there.
Codesandbox also edited to this text, sorry for my mistake.