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
fix: expose ref in text input #1218
Conversation
fb1939b
to
5821a30
Compare
@@ -395,7 +397,8 @@ class TextInput extends React.Component<TextInputProps, State> { | |||
} | |||
|
|||
render() { | |||
const { mode, padding, ...rest } = this.props; | |||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | |||
const { mode, padding, ref: outerRef, ...rest } = this.props; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where do you use outerRef
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nowhere but we need to remove it from rest
since we cannot pass it on to the inner components.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But then how we are able to pass our own ref to TextInput
and use it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ref
will be passed to TextInput
and React will take care of it so you can access the methods of it, e.g.
react-native-paper/src/components/TextInput/TextInput.tsx
Lines 388 to 390 in 29f3ffc
focus() { | |
return this._root && this._root.focus(); | |
} |
_root
again will be set by these piece of codes:
react-native-paper/src/components/TextInput/TextInput.tsx
Lines 407 to 409 in 29f3ffc
innerRef={ref => { | |
this._root = ref; | |
}} |
react-native-paper/src/components/TextInput/TextInput.tsx
Lines 419 to 421 in 29f3ffc
innerRef={ref => { | |
this._root = ref; | |
}} |
I didn't want to break anything with the innerRef
so that was the simplest solution I think.
@jaulz Can you describe what do you want to achieve? Why do you need ref to the React-Native's |
@Trancever at the moment you will see the following error in case you use TypeScript:
You can of course still pass a This PR will expose the Since this means that |
Ahh so it's only to fix typescript right? I think we can accept that |
Sorry for the confusion 😇 |
[fix] added good close icon [fix] runned yarn and regenerated snapshots Delete ActivityIndicator.test.tsx Delete AppbarHeader.test.tsx fix: only start/stop progressBar animation if visible prop changes (callstack#1294) docs: fix Surface component docs (callstack#1253) fix: fix typescript error when setting ref on textinput (callstack#1218) fix: FAB - always display activity indicator if loading property is set to true (#11570) feat: (title|description)numberOfLines props to ListItem and ListAccordion (callstack#1245)
Motivation
Currently, it is not possible to pass a
ref
prop to theTextInput
.Test plan
Use
TextInput
withref
prop.