Skip to content

Commit fc5e69e

Browse files
alanleedevcipolleschi
authored andcommitted
TextInput - selection prop is not set on component creation (#44398)
Summary: Pull Request resolved: #44398 **Problem:** `selection` prop is not being set on component creation. Not quite sure which RN version this issue was introduced but fixing it on latest code. Use playground for testing (refer to following diff) **Proposed Solution:** Added notes in comments but `viewCommands.setTextAndSelection()` is called only on text or selection update which relies on comparing data with `lastNativeSelection`. Problem is that `lastNativeSelection` is initially set to the props value that is passed in so does not send the command on component creation. So assign a default selection value of `{start: -1, end: -1}` so it can be set on component creation. **Changelog:** [General][Fixed] - `selection` prop in `TextInput` was not being applied at component creation Reviewed By: cipolleschi Differential Revision: D56911712 fbshipit-source-id: 7774b246383f85216536040688b0a8ea85b3478a
1 parent 71153f6 commit fc5e69e

File tree

1 file changed

+5
-3
lines changed
  • packages/react-native/Libraries/Components/TextInput

1 file changed

+5
-3
lines changed

packages/react-native/Libraries/Components/TextInput/TextInput.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,12 +1135,14 @@ function InternalTextInput(props: Props): React.Node {
11351135
};
11361136

11371137
const [mostRecentEventCount, setMostRecentEventCount] = useState<number>(0);
1138-
11391138
const [lastNativeText, setLastNativeText] = useState<?Stringish>(props.value);
11401139
const [lastNativeSelectionState, setLastNativeSelection] = useState<{|
1141-
selection: ?Selection,
1140+
selection: Selection,
11421141
mostRecentEventCount: number,
1143-
|}>({selection, mostRecentEventCount});
1142+
|}>({
1143+
selection: {start: -1, end: -1},
1144+
mostRecentEventCount: mostRecentEventCount,
1145+
});
11441146

11451147
const lastNativeSelection = lastNativeSelectionState.selection;
11461148

0 commit comments

Comments
 (0)