-
Notifications
You must be signed in to change notification settings - Fork 806
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
UITextField setText: should move caret position of underlying TextBox to end. #502
Conversation
… to end. Ensures caret position is correct if we programmatically gain focus (becomeFirstResponder).
// Ensure caret at end of field in case we programmatically | ||
// gain focus (becomeFirstResponder) after the text is set: | ||
_textBox.selectionStart = [_text length]; | ||
_textBox.selectionLength = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we want the same behavior for _passwordBox? #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PasswordBox doesn't have the SelectionStart/Length properties. However it already implements the right functionality automatically. (I did the basic test which is to programmatically set the text then programmatically gain focus with a secureMode UITextField - the caret just appears at the end)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yiyang-msft is added to the review. #Closed |
Thanks for your contribution. |
Ensures caret position is correct if we programmatically gain focus (becomeFirstResponder).
I'm in a situation where I have certain elements e.g. tableviewcells which, when tapped, programmatically set focus on a text field in the element (so that it's easier to bring the keyboard up without having to touch on exactly the bounds of the text field). There could also be situations where e.g. actual touches on a UITextField are blocked by another transparent UIView covering the field - with actual beginning editing of the covered UITextField handled by |becomeFirstResponder|.
This change ensures that in the above scenarios the caret is not at the beginning of the textfield's text.