dotnet/maui

DisplayPromptAsync preselect initialValue in prompt for easy overwriting

Open

#4981 aperta il 1 mar 2022

Vedi su GitHub
 (6 commenti) (3 reazioni) (0 assegnatari)C# (1951 fork)batch import
area-controls-dialogalertgood first issueproposal/opent/enhancement ☀️

Metriche repository

Star
 (23.245 star)
Metriche merge PR
 (Merge medio 47g 9h) (248 PR mergiate in 30 g)

Descrizione

Description

With DisplayPromptAsync you can include an initialValue to be showed in the dialog shown.

I'd like a feature for this initialValue to be preselected so it is ready to be overwritten with a simple input, instead of the user needs to clear the field first.

Also requested on StackOverflow by another user.

Public API Changes

Not sure if I fill out this field correctly, but just add another optional parameter next to string initialValue named e.g. bool preselectInitialValue = false. In body, if new parameter is true, select all of the text in tne Entry. Also test scenariou where user enters input very quickly after rendering, as the .Text apparently can be null.

public Task<string> DisplayPromptAsync(
  string title, 
  string message, 
  string accept = "OK", 
  string cancel = "Cancel", 
  string placeholder = null, 
  int maxLength = -1, 
  Keyboard keyboard = null, 
  string initialValue = "", 
  bool preselectInitialValue = false) 
{
  (...)
  if (preselectInitialValue && !string.isNullOrEmpty(initialValue)) {
    x.SelectionLength = x.Text != null ? x.Text.Length : 0;
  }
  (...)
}

Intended Use-Case

Example: User needs to enter number of copies to print. Most often this is 1, so that is set as initialValue. If user presses "2" to print two copies, it now says "12". If as requested, we could indicate the initialValue should be preselected (quite a normal UI functionality), then when user presses "2", it would overwrite "1" and instead the value entered would be "2".

Guida contributor