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

React Input component crashes when inputRef is used #310

Open
download13 opened this issue Oct 16, 2019 · 9 comments
Open

React Input component crashes when inputRef is used #310

download13 opened this issue Oct 16, 2019 · 9 comments

Comments

@download13
Copy link

If you use an Input element with inputRef, it clobbers the inputRef passed here resulting in an error being thrown here because this.controlEl is undefined.

I think there might be a workaround here: facebook/react#13029

@amorey
Copy link
Member

amorey commented Oct 17, 2019

Thanks for creating this issue. Are you currently running into this problem? Can you provide an example snippet?

@download13
Copy link
Author

download13 commented Oct 17, 2019

import React from "react";
import ReactDOM from "react-dom";
import { Input } from "muicss/react";

function App() {
  return <Input inputRef={() => console.log("hi")} />;
}

const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);

You should see an error in the console to the effect of TypeError: this.controlEl is undefined or Cannot set property _muiTextfield on undefined

https://codesandbox.io/s/quirky-wilbur-je6eg
The sandbox generates a lot of extra error output that's not helpful but the real error should be in there somewhere.

@tianhuil
Copy link

tianhuil commented Mar 5, 2020

@amorey, @download13: I encountered this issue as well. Proposed solution in #315

@amorey
Copy link
Member

amorey commented Mar 5, 2020

Have you tried using the ref attribute to access the control element instead? Here's an example in the documentation for uncontrolled components:
https://www.muicss.com/docs/v1/react/input

@tianhuil
Copy link

tianhuil commented Mar 5, 2020

Thanks @amorey: that works as well but could we then add controlEl to the typescript definition for Input?

@amorey
Copy link
Member

amorey commented Mar 6, 2020

Sure, though I'm not familiar with typescript. Can you submit a PR or show me how to add it?

@tianhuil
Copy link

Hi @amorey: sorry for the delayed response. I'll try to add it.

@tianhuil
Copy link

Added PR to DefinitelyTyped: DefinitelyTyped/DefinitelyTyped#43079

@amorey
Copy link
Member

amorey commented Mar 12, 2020

Awesome! Thanks! Let me know when it gets merged and then we'll close this issue.

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