Jordi Jordi - 1 month ago 18
HTML Question

ReactJS handle tab character in textarea

How can I handle tab key pressed events in ReactJS so I'm able to indent text inside a textarea?

onChange event does not get fired when tab is pressed on the textarea, so I guess there might be a higher level handler I can use to detect this event.

Answer

you can try onKeyDown and get the keycode for tab.

add: function(event){
    console.log(event.keyCode); //press TAB and get the keyCode
},
render: function(){
    return(
        <div>
            <input type="text" id="one" onKeyDown={this.add} />    
        </div>
    );
}
Comments