-
Notifications
You must be signed in to change notification settings - Fork 1.9k
The entry's cursor position is lost when transitioning to the next entry field on iOS only #19109
Description
Description
The entry's CursorPosition property is being ignored when moving to the next field.
If I set the CursorPosition property in the Entry XAML control, it is not being counted to set the position when moving from a previous entry, and it always fall at the end of the text in the entry control.
I found out that this file may be the responsible of setting the cursor position at the end of the text in the entry control.
Steps to Reproduce
- Create a new .NET MAUI 8 project
- On the MainPage add the following code:
<Entry
x:Name="Entry1"
Placeholder="Entry 1 (Tap `Next` or `Enter` or `Return` when finished)"
ReturnType="Next"/>
<Entry
x:Name="Entry2"
Text="Entry 2"
CursorPosition="5"
Placeholder="Entry 2 (Tap `Next` or `Enter` or `Return` on the keyboard when finished)"
ReturnType="Next" />- Run the application and focus on the Entry 1, then tap the "Next" button on the keyboard, the Entry 2 should be focused.
What happened is that the cursor position is at the end of the text length of the Entry 2 instead of the position 5 set on the Entry's 2 property.
This issue occurs only on iOS. I ran tests on Android, MacCatalyst , and Windows and it worked OK.
maui-cursor-position-issue-ios.mp4
Link to public reproduction project repository
https://github.com/vhugogarcia/maui-sample-cursor-position
Version with bug
8.0.3
Is this a regression from previous behavior?
No, this is something new
Last version that worked well
Unknown/Other
Affected platforms
iOS
Affected platform versions
iOS 17
Did you find any workaround?
if I set the Entry 2 CursorPosition property on an event in the code-behind it works partially. The first time it sets the cursor in the specified position, however, if I focus again on Entry 1 and tap on the Next button, the cursor position goes to the end of the text length.
<Entry
x:Name="Entry1"
Placeholder="Entry 1 (Tap `Next` or `Enter` or `Return` when finished)"
ReturnType="Next"
Completed="Entry1_Completed"/>
<Entry
x:Name="Entry2"
Text="Entry 2"
Placeholder="Entry 2 (Tap `Next` or `Enter` or `Return` on the keyboard when finished)"
ReturnType="Next" />void Entry1_Completed(System.Object sender, System.EventArgs e)
{
Entry2.CursorPosition = 5;
}Relevant log output
Not log, but I believe I found the file that is responsible for the cursor position on iOS: TextExtension.cs