fix attempting to focus disabled textinputs#30695
Conversation
There was a problem hiding this comment.
this links to https://github.com/facebook/react-native/blob/0.64-stable/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js#L3895
without using Object.getPrototypeOf, we'd end up in a recursive call
There was a problem hiding this comment.
@yungsters had some feedback:
I think a better fix would be for the platform to return a boolean — true if the focus is successful, and false otherwise.
But for now, this logic should live in TextInputState.focusTextInput.
function focusTextInput(textField: ?ComponentRef) {
// …
if (currentlyFocusedInputRef !== textField && textField != null) {
// EXPLANATION…
if (textField.props?.editable === false) {
return;
}
// …
}
}
There was a problem hiding this comment.
@lunaleaps @yungsters the PR was updated, thanks for review
Base commit: 2fdbf6a |
Base commit: 2fdbf6a |
dab1058 to
242a1ae
Compare
|
@lunaleaps has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
There was a problem hiding this comment.
@yungsters had some feedback:
I think a better fix would be for the platform to return a boolean — true if the focus is successful, and false otherwise.
But for now, this logic should live in TextInputState.focusTextInput.
function focusTextInput(textField: ?ComponentRef) {
// …
if (currentlyFocusedInputRef !== textField && textField != null) {
// EXPLANATION…
if (textField.props?.editable === false) {
return;
}
// …
}
}
|
@lunaleaps has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
|
This pull request was successfully merged by @vonovak in 8a5460c. When will my fix make it into a release? | Upcoming Releases |
Summary: when we call `focus()` upon a TextInput ref which has prop `editable=false` it marks the textinput as focused in `TextInputState` even though the focus is rejected by textinput itself because it is not editable. then, when you change `editable` prop to `true` and call `focus` again, [this condition](https://github.com/facebook/react-native/blob/e912c462eb0b7166ca5947bb5a3ee20761d910b6/Libraries/Components/TextInput/TextInputState.js#L46) or rather [this one](https://github.com/facebook/react-native/blob/1b2b2198e1b2383523b4655dc8c220d251b057d6/Libraries/Components/TextInput/TextInputState.js#L89) will evaluate to `false` and focus will not happen even though it can and should happen. see also https://github.com/facebook/react-native/blob/0.64-stable/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js#L3895 ## Changelog <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://github.com/facebook/react-native/wiki/Changelog --> [General] [Fixed] - `focus()` on TextInput to respect its `editable` state Pull Request resolved: facebook#30695 Test Plan: Create a `TextInput` with prop `editable=false` and call `ref.current.focus()` upon its ref. TextInput should not be marked as focused in `TextInputState`. Reviewed By: yungsters Differential Revision: D34357913 Pulled By: lunaleaps fbshipit-source-id: 9a2fb819bbb05ef213c9b5d739dec583ae0a3e6f
Summary
when we call
focus()upon a TextInput ref which has propeditable=falseit marks the textinput as focused inTextInputStateeven though the focus is rejected by textinput itself because it is not editable.then, when you change
editableprop totrueand callfocusagain, this condition or rather this one will evaluate tofalseand focus will not happen even though it can and should happen.see also https://github.com/facebook/react-native/blob/0.64-stable/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js#L3895
Changelog
[General] [Fixed] -
focus()on TextInput to respect itseditablestateTest Plan
Create a
TextInputwith propeditable=falseand callref.current.focus()upon its ref. TextInput should not be marked as focused inTextInputState.