Maui.FreakyControls icon indicating copy to clipboard operation
Maui.FreakyControls copied to clipboard

Select all text on TextInputLayout

Open FrankVDL2471 opened this issue 11 months ago • 2 comments

Hello,

I want all the text to be selected, when the control gets focus (is tabbed on) I tried the code below, but it does not seem to work. Any suggestions on how to make this work ?


public class SjwingEntry : FreakyTextInputLayout, IDisposable {

	public SjwingEntry() {
		this.BorderType = Maui.FreakyControls.Shared.Enums.BorderType.Full;
		this.BorderCornerRadius = 5;
		this.BorderStrokeThickness = 2;
		this.BorderStroke = Brush.DarkGray;
		this.ControlBackgroundColor = Colors.White;
		this.TextColor = Colors.Black;
		this.FontFamily = "Default";
		this.FontSize = 16;


		this.Focused += SjwingEntry_Focused;
	}

	public void Dispose() {
		this.Focused -= SjwingEntry_Focused;
	}

	private void SjwingEntry_Focused(object sender, FocusEventArgs e) {
		this.CursorPosition = 0;
		this.SelectionLength = this.Text.Length;
	}
}

FrankVDL2471 avatar Mar 02 '24 14:03 FrankVDL2471

I just checked this, seems to be an issue but I am not sure if I can actually add a fix to this soon, To be honest not even sure if I know how to fix this lol.

FreakyAli avatar Mar 02 '24 22:03 FreakyAli

So after some RnD, I found that as soon as you add the Entry into a ContentView custom control these properties stop working on Focus, But I am not 100% sure why yet!

FreakyAli avatar Mar 05 '24 11:03 FreakyAli

As of right now, i think this is not fixable but i am still doing some RnD for this hopefully when i find a solution i will update you!

FreakyAli avatar May 13 '24 15:05 FreakyAli

@FrankVDL2471 Need your help, I just tried this with the latest version of Android and this is not working with a basic entry, can you confirm if this works for you there?

FreakyAli avatar May 16 '24 01:05 FreakyAli

@FrankVDL2471

This should solve your issue, I have just tested it let me know if this works so i can close this issue

public class SjwingEntry : FreakyTextInputLayout, IDisposable
{
    private readonly Entry internalEntry;

    public SjwingEntry()
    {
        this.BorderType = Shared.Enums.BorderType.Full;
        this.BorderCornerRadius = 5;
        this.BorderStrokeThickness = 2;
        this.BorderStroke = Brush.DarkGray;
        this.ControlBackgroundColor = Colors.White;
        this.TextColor = Colors.Black;
        this.FontFamily = "Default";
        this.FontSize = 16;
        internalEntry = this.FindByName<Entry>("EntryField");
        internalEntry.Focused += SjwingEntry_Focused;
    }

    protected void Dispose()
    {
        internalEntry.Focused -= SjwingEntry_Focused;
    }

    private async void SjwingEntry_Focused(object sender, FocusEventArgs e)
    {
        internalEntry.SelectionLength = 0;
        await Dispatcher.DispatchAsync(() =>
        {
            internalEntry.CursorPosition = 0;
            internalEntry.SelectionLength = this.Text.Length;
        });
    }
}

FreakyAli avatar May 16 '24 01:05 FreakyAli

Just tested it, and it seems to be working fine.

Thanks for the update

FrankVDL2471 avatar May 16 '24 13:05 FrankVDL2471

Awesome, I will. be closing this in that case!!

FreakyAli avatar May 16 '24 13:05 FreakyAli