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

Add ref prop support #64

Closed
solo-bog-uptech opened this issue Dec 14, 2023 · 2 comments
Closed

Add ref prop support #64

solo-bog-uptech opened this issue Dec 14, 2023 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@solo-bog-uptech
Copy link

Summary

I use react-hook-form lib for handling forms and it needs ref prop in PhoneInput component.

@solo-bog-uptech solo-bog-uptech added the enhancement New feature or request label Dec 14, 2023
@ArtyomVancyan ArtyomVancyan self-assigned this Dec 14, 2023
@ArtyomVancyan ArtyomVancyan moved this from Todo to In Progress in antd-phone-input Dec 14, 2023
@ArtyomVancyan
Copy link
Member

ArtyomVancyan commented Dec 14, 2023

Hi @solo-bog-uptech, thanks for opening the issue. I have already added support for ref property and tested it with the following demo component. The new library version will be published after covering all your opened issues (meaning #65).

import Button from "antd/es/button";
import PhoneInput from "antd-phone-input";
import {useForm} from "react-hook-form";

const Demo = () => {
    const {register, handleSubmit} = useForm();

    const phoneRegister = register("phone", {
        validate: ({valid = () => false}: any = {}) => valid(),
    });

    const onChange = (value: any) => phoneRegister.onChange({target: {value, name: phoneRegister.name}});

    return (
        <form onSubmit={handleSubmit(console.log)}>
            <PhoneInput
                enableSearch
                {...phoneRegister}
                onChange={onChange}
            />
            <Button htmlType="submit">Submit</Button>
        </form>
    )
}

export default Demo;

@ArtyomVancyan
Copy link
Member

Closing the issue because of inactivity. The changes will be available in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

When branches are created from issues, their pull requests are automatically linked.

2 participants