dotnet/maui

DisplayPromptAsync preselect initialValue in prompt for easy overwriting

Open

#4 981 ouverte le 1 mars 2022

Voir sur GitHub
 (6 commentaires) (3 réactions) (0 assignés)C# (1 951 forks)batch import
area-controls-dialogalertgood first issueproposal/opent/enhancement ☀️

Métriques du dépôt

Stars
 (23 245 stars)
Métriques de merge PR
 (Merge moyen 47j 9h) (248 PRs mergées en 30 j)

Description

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".

Guide contributeur