Skip to content

Commit be09d12

Browse files
alanleedevfacebook-github-bot
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 9b77506 commit be09d12

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

+5-3
Original file line numberDiff line numberDiff line change
@@ -1099,12 +1099,14 @@ function InternalTextInput(props: Props): React.Node {
10991099
};
11001100

11011101
const [mostRecentEventCount, setMostRecentEventCount] = useState<number>(0);
1102-
11031102
const [lastNativeText, setLastNativeText] = useState<?Stringish>(props.value);
11041103
const [lastNativeSelectionState, setLastNativeSelection] = useState<{|
1105-
selection: ?Selection,
1104+
selection: Selection,
11061105
mostRecentEventCount: number,
1107-
|}>({selection, mostRecentEventCount});
1106+
|}>({
1107+
selection: {start: -1, end: -1},
1108+
mostRecentEventCount: mostRecentEventCount,
1109+
});
11081110

11091111
const lastNativeSelection = lastNativeSelectionState.selection;
11101112

0 commit comments

Comments
 (0)