react-currency-input icon indicating copy to clipboard operation
react-currency-input copied to clipboard

how to trigger focus() on <CurrencyInput />

Open tgoldenberg opened this issue 8 years ago • 2 comments

I would like to trigger the focus() event on the <CurrencyInput /> when a button is pressed. However, I'm not sure how to do so.

When I use ref={el => this.input = el}, I don't get access to the component.

Can we expose a way to add a ref to the component so that we can call focus() and other triggers? Thank you.

tgoldenberg avatar Sep 08 '17 14:09 tgoldenberg

Any update to this? @tgoldenberg did you ever find a solution?

cavaloni avatar Feb 06 '18 17:02 cavaloni

@cavaloni you can access the actual element like this:

ref={el => this.currencyInput = el} and then later reference the actual input via theInput property. e.g. this.currencyInput.theInput.focus(). I wasn't able to reference theInput in the actual ref callback because sometimes el was null. Perhaps you could do a truthy check but I didn't test that myself

joeyparis avatar Mar 27 '18 17:03 joeyparis