Skip to content
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

Mobile: Fixes #11820: Fix cursor moves to incorrect position when revising TextInput value #11821

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

mrjo118
Copy link
Contributor

@mrjo118 mrjo118 commented Feb 10, 2025

There is an issue on mobile whereby making amendments to text in React Native TextInput components causes the cursor to move before the new character which has just been typed, when the cursor is not currently at the end of the string. A similar issue has been raised here callstack/react-native-paper#1668 and the fix proposed there resolves the issue. It is fixed by simply using the defaultValue attribute instead of the value attribute on the TextInput component, to map the value to be displayed by the component.

This PR fixes #11820

Existing behaviour:
https://github.com/user-attachments/assets/c296269c-1ba5-492e-a00f-9a0b1e30e576

New behaviour with code change:
https://github.com/user-attachments/assets/559d9155-b526-4da7-92c4-448c06d0f0b8

Testing:
I have verified that amending and saving the value of a STRING type configuration setting (eg. WebDAV sync target settings / proxy url setting) updates and saves as expected

@@ -149,7 +149,7 @@ const SettingComponent: React.FunctionComponent<Props> = props => {
autoCapitalize="none"
key="control"
style={styleSheet.settingControl}
value={props.value}
defaultValue={props.value}
Copy link
Owner

Choose a reason for hiding this comment

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

That may fix the issue but that doesn't seem correct? This is a controlled component so we shouldn't touch the defaultValue property, only the value and change ones.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure there is another way to fix this unfortunately, other than to find a TextInput alternative in a third party library. I haven't been able to find an upstream report for this issue specifically on the react-native repository, but I'm pretty sure this is an upstream issue.

Speaking of controlled components, there is this issue on the react-native repository: facebook/react-native#34437 . It's an open issue since 2022 that controlling a TextInput component doesn't actually work, and the suggestion there is to make it uncontrolled by using defaultValue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mobile: Cursor moves to incorrect position when revising TextInput value
2 participants