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

VerificationInput uses forwardRef but TS defs don't expose that #46

Closed
legraphista opened this issue Jun 9, 2021 · 6 comments · Fixed by #47
Closed

VerificationInput uses forwardRef but TS defs don't expose that #46

legraphista opened this issue Jun 9, 2021 · 6 comments · Fixed by #47
Labels

Comments

@legraphista
Copy link

legraphista commented Jun 9, 2021

Hi,

Thanks for the awesome component 😄!

Unfortunately, I hit a little snag:

In your code, you expose the ref passthrough 🎉

const VerificationInput = forwardRef(

But the definitions declare just a plain functional component

declare const VerificationInput: React.FC<VerificationInputProps>;

Could you please add the missing ref prop? or maybe make use of PropsWithoutRef<P> & RefAttributes<T> like here?
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/9cc04052f7e17abbfb2a8a1636ff9fa456b01552/types/react/index.d.ts#L805

I'm using the ref to listen to paste events so that I can remove dashes from the clipboard text since I want to ignore them.
For now, it's ok since I can // @ts-ignore it

@andreaswilli
Copy link
Owner

Thanks for the feedback.

I am not too familiar with React typings, but it seems like PropsWithoutRef<P> & RefAttributes<T> would be a good solution. I will take a closer look.

@legraphista
Copy link
Author

legraphista commented Jun 9, 2021

Thanks for looking at it!

Since the props don't contain ref I think you can just append & RefAttributes<HTMLInputElement> to them

@andreaswilli andreaswilli linked a pull request Jun 10, 2021 that will close this issue
@andreaswilli
Copy link
Owner

I decided to go with ForwardRefExoticComponent since this is how the forwardRef function is typed.

The change is released as version 2.0.1. Let me know if it works for you.

Btw, do you think it would be a good idea to introduce a prop like:

delimiterChars=" -_"

I'm asking since the component by default already ignores blanks when pasting a value.

@legraphista
Copy link
Author

Btw, do you think it would be a good idea to introduce a prop like:

delimiterChars=" -_"

I'm asking since the component by default already ignores blanks when pasting a value.

Yes please, if you can!

@andreaswilli
Copy link
Owner

Another option would be to ignore everything that is not a valid character. I'm gonna give this some more thought.

@legraphista
Copy link
Author

That might be a good option as well

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

Successfully merging a pull request may close this issue.

2 participants