Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How would I access focus and blur? #33

Open
briannezhad opened this issue Mar 23, 2022 · 2 comments
Open

How would I access focus and blur? #33

briannezhad opened this issue Mar 23, 2022 · 2 comments

Comments

@briannezhad
Copy link

briannezhad commented Mar 23, 2022

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
Copy link

3beeepb commented Jul 13, 2022

Hi

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

@Mvbraathen
Copy link

Mvbraathen commented Sep 8, 2022

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(); }}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants