I cannot get IE11 to focus the input element after inserting it into the DOM. The item will not receive text input after focusing, but its placeholder text is no longer displayed. The element is created by React, and I access it through the React refs object in componentDidMount :
componentDidMount() { this.refs.input.getDOMNode().focus(); }
I tried to add a little delay using setTimeout :
componentDidMount() { setTimeout(() => this.refs.input.getDOMNode().focus(), 10); }
I also tried adding tabIndex of "1" to the tab.
In case this is useful, here is the JSX rendering:
<div style={style}> <div style={labelStyle}>Enter a name to begin.</div> <form onSubmit={this.submit} style={formStyle}> <input tabIndex="1" ref="input" value={this.state.username} onChange={this.updateUsername} placeholder="New User Name" style={inputStyle} /> <button {...this.getBrowserStateEvents()} style={this.buildStyles(buttonStyle)}>Create</button> </form> </div>
Is there any trick to focus on IE11 that I don't know about?
source share