7

I want to Highlight not Select part of the value in TextField component

Something like this

enter image description here

I tried having a <span> with a class in the value prop but that showed [object Object] instead.

How can I achieve that?

Ali Elkhateeb
  • 3,413
  • 4
  • 21
  • 39

2 Answers2

1

Material UI Textfield component is basically made up of a html input component.

the Textfield "value" prop will be reflected as html input element's value

HTML in the input field value

HiRenS
  • 89
  • 1
  • 4
0

Yes, it is possible to highlight, but we need to pre-parse the text in to html,

Warning!! Must be careful about the source of the text.

npm install html-react-parser

var parse = require('html-react-parser');
<Typography > {parse(props.text)}</Typography>

Example: props.text = "This should render your html"

Dharman
  • 30,962
  • 25
  • 85
  • 135
  • How is this helping? You do not talk about TextFields nor inputs, and we don't want to parse HTML here, we want to highlight a part of the text in a Mui TextField. – Sereyn Mar 14 '22 at 10:34