rili-live / react-native-phone-input

Phone input box for React Native
https://www.npmjs.com/package/react-native-phone-input
MIT License
42 stars 54 forks source link

How would I access focus and blur? #33

Open briannezhad opened 2 years ago

briannezhad commented 2 years ago

I need to set a function when is on blur or focus. But it doesn't work when I do as follow:

<PhoneInput 
initialValue={value}
initialCountry={'us'}
onChangePhoneNumber={setValue}
style={[isFocused ? styles.InputFocused : styles.Input ]}  
useRef='phone' 
textProps={{
    placeholder: placeholder,
}}
ref={(ref)=>{
    ref?.focus(onFocus())
    ref?.blur(onBlur())
}}

autoFormat={true}
/>  

be mindful that this is a child component.

I wish I could access it through the component attribute. for example, like such:

<PhoneInput 
...
focus={...}
blur={...}
/>  

UPDATE:

What I really want, it onFocus to do an action.

3beeepb commented 1 year ago

Hi

<PhoneInput textProps={{ onFocus: () => this.focus(), onBlur: () => this.blur() }} />

Mvbraathen commented 1 year ago

I am trying it this way: textProps={{ onFocus: () => phoneRef.current?.focus() }} Shouldn't that work? Well, it doesn't, but this does: ref={(ref) => { ref?.focus(); }}