Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React - Draggable components with inputs lose the ability to focus when clicking that input

<Draggable axis="y"
      grid={[135,135]}
      onStop={this.handleStop}
      defaultPosition={{x: this.props.task.positionX, y: this.props.task.positionY,}}>
    <div id="edit-task-component">
      <form onSubmit={this.handleSubmit} id="edit-task-form" className="edit-task-form">
        <input type="text" name="name" onChange={this.handleChange} placeholder="Name" value={this.state.name} required/>
        <input type="text" name="description" onChange={this.handleChange} placeholder="Description" value={this.state.description} required/>
        <button className="btn submit-btn" type="submit">Save </button>
      </form>
    </div>
 </Draggable>

What happens is I will click on the input and it will focus for a split second then loses focus -- so i cant type in the input. I have to click on it a few times for it to actually focus, therefore allowing me to type in the input. How can I get it to stay focused after clicking once? I have tried setting autofocus to true after clicking the input but that didnt work either. Any ideas ?

like image 560
rgc998 Avatar asked Sep 18 '25 21:09

rgc998


1 Answers

  1. Use enableUserSelectHack, this will not interfere with existing style

    eg <Draggable enableUserSelectHack={false}>

  2. Use cancel prop

    eg: give any class name, it doesn't matter

    <Draggable cancel=".just-name"> <input className="just-name" placeholder="Add text here" /> </Draggable>

like image 155
Saahithyan Vigneswaran Avatar answered Sep 20 '25 09:09

Saahithyan Vigneswaran