React — inline onfocus placeholder = ''
Asked Answered
G

1

10

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.

Genovera answered 13/6, 2016 at 21:20 Comment(0)
Q
28

You still can do it inline with React:

<input 
  type="text" 
  placeholder="Name" 
  onFocus={(e) => e.target.placeholder = ""} 
  onBlur={(e) => e.target.placeholder = "Name"} />
Quita answered 13/6, 2016 at 21:26 Comment(1)
it's not working for me? it's because i use redux-form? maybe redux-form overwrite my handlers?Faustinafaustine

© 2022 - 2024 — McMap. All rights reserved.