CommunityToolkit / CommunityToolkit/Windows

[Feature] Ability for TokenizingTextBox to keep the typed text after submitting or selecting

Aperta
#168 3 commenti 1 reazione 0 assegnatari Vedi su GitHub
components::controls::tokenizingtextbox enhancement feature request :mailbox_with_mail:
Lingua principale
C#
Stelle
1.1k
Fork
166
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

### Describe the problem

I'm using the TokenizingTextBox to implement an advanced quick search in my application. When a user starts typing, they first get a list of fields they can search through, and when selecting one the selected field appears as a token in the search box letting the user know they are searching only for that field. They can select several fields to search through all the selected ones.

The trouble is that every time the TTB is submitted (by pressing enter or by selecting an item from the suggestions) the Text property is emptied. I have to resort to cheating it via "TokenItemAdding" and "GotFocus" events (to store the text in a temp string, and restore it after the "QuerySubmitted" event has executed, as I noticed in the source code for the TTB that the QuerySubmitted event actually empties the Text property.

### Describe the solution

I found the exact place the TTB empties the Text field (lines 156 and 157 of the TokenizingTextBoxItem.cs):

![QuerySubmittedMethod](https://github.com/CommunityToolkit/WindowsCommunityToolkit/assets/45658254/45fb06e9-9c37-4117-87d8-c3f17de8ca5f)

My proposal is to surround the two lines that empty the text with a conditional statement dependent on a top-level property that can be set in XAML, something like KeepTextInputAfterQuerySubmit defaulted to false to keep it backward compatible.

I tested it in a branch ad it behaves exactly like I need it to behave (I commented out the two lines to get a quick feel).

I can put in the work to properly introduce the property in the XAML and all the in-between code in order to make it proper and submit a PR. I just need acceptance by the community to get the PR approved.

### Alternatives

One alternative is to introduce a PostQuerySubmitted event that i can use to restor the text box content. But this is less elegant and there will be a slight delay when the filed will be empty.

Yet another alternative is to enable the component to be extended and the original QuerySubmitted method overridden, but this is much more trouble than its worth IMHO.

### Additional info

This is an example from my modified component that keeps the text:

![ExampleOfTtbKeepingTheText](https://github.com/CommunityToolkit/WindowsCommunityToolkit/assets/45658254/b15e6ff0-e9d3-4124-a3e8-d6b86723a76a)

I achieved this by commenting out the two lines and testing it in the Sample App. The text is kept in the text box after typing and selecting one of the offered options. It creates the token, but the text can be used to refine the search after the results have been loaded (in my use case).

### Help us help you

Yes, I'd like to be assigned to work on this item.

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia da TokenizingTextBoxItem.cs, in particolare dalle righe identificate come quelle che cancellano la proprietà Text, e ispeziona l’app di esempio TokenizingTextBox per verificare il comportamento attuale. Aggiungi un’opzione configurabile tramite XAML che conservi il testo digitato dopo l’invio o la selezione di un suggerimento, mantenendo invariato il comportamento predefinito; il lavoro è completato quando l’esempio dimostra entrambe le modalità.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
csharp
Ambito
desktop, frontend
Tipo di issue
Funzionalità
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.