Skip to content

[core] Add React.createRef support #11757

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

Merged
merged 5 commits into from
Jun 7, 2018

Conversation

t49tran
Copy link
Contributor

@t49tran t49tran commented Jun 7, 2018

This PR resolve the issue with <Input>, <TextField> and <TextArea> components don't accept React.createRef as inputRef or textareaRef.

Issues raised in #11709 #11486.

The idea for the solution is partly from #11293 and #11486.

Closes #11709

@oliviertassinari oliviertassinari changed the title Feat/allow React.createRef as [Input], [Textarea] inputRef and textareaRef [core] Add React.createRef support Jun 7, 2018
@oliviertassinari oliviertassinari self-assigned this Jun 7, 2018
@oliviertassinari oliviertassinari added new feature New feature or request core labels Jun 7, 2018
@oliviertassinari oliviertassinari force-pushed the feat/allow-createRef-input branch 3 times, most recently from 758ca0f to f3a3f6a Compare June 7, 2018 21:15
@oliviertassinari oliviertassinari force-pushed the feat/allow-createRef-input branch from f3a3f6a to f9bb9ec Compare June 7, 2018 21:33
@oliviertassinari oliviertassinari merged commit 30edbc8 into mui:master Jun 7, 2018
@oliviertassinari
Copy link
Member

@t49tran Thank you!

@@ -11,7 +11,7 @@ export interface TextareaProps
disabled?: boolean;
rows?: string | number;
rowsMax?: string | number;
textareaRef?: React.Ref<any>;
textareaRef?: React.Ref<any> | React.RefObject<any>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed. React.Ref<> includes React.RefObject<>

type Ref<T> = string | { bivarianceHack(instance: T | null): any }["bivarianceHack"] | RefObject<T>;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, feel free to make another PR to remove it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

React.Ref<any> | React.RefObject<any> can also be found in couple of other places, do you want to work on it @franklixuefei ? Otherwise I can make a PR to replace them.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@t49tran Sorry I was busy working on something else lately. Please go ahead! Thanks! 😄

acroyear pushed a commit to acroyear/material-ui that referenced this pull request Jul 14, 2018
* feat: make input accept both ref callback and ref from React.createRef

* feat: update [TextArea] to accept React.createRef object as inputRef

* feat: update typescript and proptypes declaration for inputRef

* test: add inputRef test for input

* simpler logic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature New feature or request typescript
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants