7

I already try autoFocus or focus(), but seems not work.

<textarea autoFocus />

or

<textarea ref="textarea" />
componentDidMount() {
  findDOMNode(this.refs.textarea).focus();
}

edit

autoFocus seems work in chrome.

Both autoFocus foucs() not work in iOS.

Liu Dongyu
  • 894
  • 1
  • 7
  • 17
  • 1
    Make sur not using [-webkit-user-select property](http://stackoverflow.com/questions/30752250/ios-workaround-for-manually-focusing-on-an-input-textarea) – Damien Leroux Jun 02 '16 at 06:27
  • `` does not work for me in Chrome. The autofocus field does not render in the html. – Mote Zart Jan 19 '22 at 16:55

1 Answers1

1

Calling focus() in componentDidMount seems to work in desktop Chrome and Firefox.

Demo.

It seems that Mobile Safari intentionally suppresses auto-focussing of elements.

Community
  • 1
  • 1
Jonathan
  • 32,202
  • 38
  • 137
  • 208