React-number-format: Set Focus

Created on 3 Oct 2017  路  2Comments  路  Source: s-yadav/react-number-format

Hi, i need to know how can i set the focus on the component inside blur event of another component.
It's possible?

All 2 comments

You can try with giving tabIndex
Or if that does not work add a ref to NumberFormat

<NumberFormat ref={(numFormatInstance) => {this.numFormatInstance = numFormatInstance}/>

and use ReactDOM.findDOMNode(this.numberFormatInst) to get the element. You may need to traverse even deeper if using any custom input component. After getting element, you can call the focus method of it.

Note: Using findDOMNode, in general, is not a good practice. So avoid it in other places.

If you're using custom Input, There is an easy way without using findDOMNode

customInput={props => <Input ref={el => {
   this.inputRefNew = el;
}} {...props} />}

https://codesandbox.io/s/n4pw697pr4

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rioarray picture rioarray  路  6Comments

sezarthiago picture sezarthiago  路  7Comments

erasmo-marin picture erasmo-marin  路  3Comments

nourahassan picture nourahassan  路  5Comments

ddmedeiros picture ddmedeiros  路  6Comments