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

this.refs[myRef] gives only formsy functions, not custom input ones #389

Open
hanbar opened this issue Feb 14, 2020 · 3 comments
Open

this.refs[myRef] gives only formsy functions, not custom input ones #389

hanbar opened this issue Feb 14, 2020 · 3 comments

Comments

@hanbar
Copy link

hanbar commented Feb 14, 2020

Even if I have innerRef prop on my input I cannot call its functions from parent - is the innerRef meant as forwarded ref or how can I forward my ref on the input to call its methods from parent?

@rkuykendall
Copy link
Member

I don't use refs often, so perhaps another user can help me understand the issue here, but here is our test for the innerRef feature if that helps:

it('should expose the users DOM node through an innerRef prop', () => {
class TestForm extends React.Component {
public inputRef: typeof TestInputHoc;
render() {
return (
<Formsy>
<TestInputHoc
name="name"
innerRef={c => {
this.inputRef = c;
}}
/>
</Formsy>
);
}
}
const form = mount(<TestForm />);
const input = (form.instance() as TestForm).inputRef;
expect(input.props.name).toEqual('name');
});

@hanbar
Copy link
Author

hanbar commented Feb 17, 2020

Sorry, I had both ref and innerRef on my input and it didn't work.

@rkuykendall
Copy link
Member

Can you branch off and write a failing test, similar to the one shown above?

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

2 participants