Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React — inline onfocus placeholder = ''

I typically use an inline onfocus / blur to toggle placeholder text in inputs. Like this:

<input type="text" placeholder="Name" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Name'"/>

This doesn't seem to work in React and I'm wondering what is the "correct" way of handling placeholder toggles in React.

like image 403
Kirk Ross Avatar asked Jun 13 '16 21:06

Kirk Ross


1 Answers

You still can do it inline with React:

<input 
  type="text" 
  placeholder="Name" 
  onFocus={(e) => e.target.placeholder = ""} 
  onBlur={(e) => e.target.placeholder = "Name"} />
like image 73
Rafael Quintanilha Avatar answered Oct 13 '22 09:10

Rafael Quintanilha