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

Add cursor position to textInput onChange event #35616

Closed
wants to merge 1 commit into from

Conversation

Karim-30
Copy link

Summary

Somethimes we need to know where is the cursor inside the Textinput, unfortunately onChangeText only give us the text inside the TextInput and it receives a string (changing a string to an object isn't a good idea).

onChange callback receives an object so we can add the cursor position to it.

Changelog

[GENERAL] [ADDED] - Add cursor position to textInput onChange event

Test Plan

Screen.Recording.2022-12-12.at.6.38.04.PM.mov

@facebook-github-bot
Copy link
Contributor

Hi @Karim-30!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@analysis-bot
Copy link

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 7,776,905 +218
android hermes armeabi-v7a 7,096,689 +218
android hermes x86 8,251,757 +221
android hermes x86_64 8,109,172 +224
android jsc arm64-v8a 8,969,530 -124
android jsc armeabi-v7a 7,702,607 -132
android jsc x86 9,033,674 -134
android jsc x86_64 9,510,621 -125

Base commit: 0f089ea
Branch: main

@analysis-bot
Copy link

Platform Engine Arch Size (bytes) Diff
ios - universal n/a --

Base commit: 0f089ea
Branch: main

@pull-bot
Copy link

PR build artifact for 19f7106 is ready.
To use, download tarball from "Artifacts" tab in this CircleCI job then run yarn add <path to tarball> in your React Native project.

@pull-bot
Copy link

PR build artifact for 19f7106 is ready.
To use, download tarball from "Artifacts" tab in this CircleCI job then run yarn add <path to tarball> in your React Native project.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Dec 12, 2022
@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@necolas
Copy link
Contributor

necolas commented Dec 12, 2022

Instead of adding another non-standard API, perhaps we should implement the selection properties from the "reduce API fragmentation" RFC. That would mean adding selectionStart to the host node accessed via e.target. See https://github.com/necolas/discussions-and-proposals/blob/reduce-fragmentation/proposals/0000-reduce-fragmentation.md#htmlinputelement

@Karim-30
Copy link
Author

There Is no selection when we are editing a text (we can’t select and edit a text at the same time). To avoid confusion and avoid writing something like this inside the onChange function

const cursor = event.nativeEvent.selection?.start || event.target.selectionStart

We should give the developer a single property representing the cursor location inside the TextInput after editing and make it unique across all platforms.

@necolas
Copy link
Contributor

necolas commented Dec 13, 2022

selectionStart is the property that indicates the location of the cursor when no text is selected https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#concept-textarea/input-cursor

@github-actions
Copy link

This PR is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Jun 12, 2023
@github-actions
Copy link

This PR was closed because it has been stalled for 7 days with no activity.

@github-actions github-actions bot closed this Jun 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants