-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added support for limiting max tokens in TokenizingTextBox #4163
Conversation
Thanks shweaver-MSFT for opening a Pull Request! The reviewers will test the PR and highlight if there is any conflict or changes required. If the PR is approved we will proceed to merge the pull request 🙌 |
As soon as I posted this, I had a thought... What if this feature were a boolean instead of an enum? But what to call it, |
Yeah, converting to draft while we figure these questions out. 🙂 Selection is kind of overloaded in this way as well (as we have 'selecting' a token which puts it in a list which can then be 'selected' later (which is what the ListView property is supposed to affect)). If we add this, I definitely think we need a different property, and maybe later we support the actual I also just don't know if it makes sense to have this mode on this control vs. just using a However, I do like the idea of @RosarioPulella @XAML-Knight would love to know your thoughts too. FYI @marcpems |
I like this PR as-is, and view an added With regards to converting this control over to |
I really like the I also like how the two could be complimentary, @michael-hawker, what do you think? |
I do think that if we had both it could be a bit confusing, as if TokenSelectionMode was Single, then that would supersede any value for the MaximumTokens property. While |
I think you're right @michael-hawker, I'll change it to Sound good? |
Microsoft.Toolkit.Uwp.UI.Controls.Input/TokenizingTextBox/TokenizingTextBox.Properties.cs
Outdated
Show resolved
Hide resolved
Microsoft.Toolkit.Uwp.UI.Controls.Input/TokenizingTextBox/TokenizingTextBox.Properties.cs
Outdated
Show resolved
Hide resolved
…nizingTextBox.Properties.cs Co-authored-by: Michael Hawker MSFT (XAML Llama) <[email protected]>
This PR has been marked as "needs attention 👋" and awaiting a response from the team. |
This PR has been marked as "needs attention 👋" and awaiting a response from the team. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Microsoft.Toolkit.Uwp.SampleApp/SamplePages/TokenizingTextBox/TokenizingTextBoxXaml.bind
Outdated
Show resolved
Hide resolved
This PR has been marked as "needs attention 👋" and awaiting a response from the team. |
@XAML-Knight you are right, my previous "bugfix" commit just added more bugs! 🐛🐜 That's what I get for moving too fast. Should be all fixed up now. |
tokenBox.AddTokenItem("TokenItem3"); | ||
|
||
Assert.AreEqual(startingItemsCount + maxTokens, tokenBox.Items.Count, "Token Replace failed"); | ||
Assert.AreEqual("TokenItem1", tokenBox.Items[0]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Weren't we expecting this to be TokenItem2 as TokenItem1 was the oldest?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TokenItem2 is the most recently added (right-most), so it gets replaced when TokenItem3 is added because MaxTokens is 2. TokenItem1 is the oldest (we added it first), so it is the left-most token and remains unaffected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I thought we had discussed a FIFO approach vs. a LIFO. Want me to poll our community to get a litmus test? I can generalize it to try and be more objective like:
If you had a collection of elements [1, 2, 3] with a maximum size (3), but had to add a new item at the end ("4"). Which of the following would you expect?
- Oldest Item is Removed: List is now [2, 3, 4]
- Newest Item is Removed: List is now [1, 2, 4]
- Something else?
(Because I think we at least agreed we should do something over nothing, eh?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reached out to the UWP Community Discord and asked question here (with more options about inserting): https://discord.com/channels/372137812037730304/663434534087426129/875096129828708412
General consensus was adding a new item should be prevented and we should probably just indicate in the box the count of items in the limit:
(mock up in sample app overlaid a new TextBlock over the TokenizingTextBox (by wrapping in a Grid))
<TextBlock Text="2/3" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="0,0,32,2"/>
(though not sure how that'd display if it goes multi-line... and we can probably arrange better in actual control template of course, but wanted to provide visual)
P2: Turn red when at max.
P2: Behavior over-ridable by dev (I'm wondering if the add event still fires and the dev could potentially remove a token of their choosing before the new one would check the max... that way they could implement any of the behaviors we've discussed with the insertion behavior...).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love it! I also think it is so cool that we can simply poll the community on the fly and get feedback! I'll work on adding the counter :) The P2s look interesting too. I can probably get the red-at-max feature handled, but the max-item-behavior is a bit more work. I'll create an issue so we won't forget.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh also, I am still planning on reducing the number of tokens from the end if the MaxTokens value is reduced below the current count. However, I don't expect changing the MaxTokens value on the fly to be a common scenario.
Build is complaining about the System.Math call...
But it definitely exists. The code build and deploys fine locally. What gives? |
...soft.Toolkit.Uwp.UI.Controls.Input/TokenizingTextBox/TokenizingTextBoxItem.AutoSuggestBox.cs
Outdated
Show resolved
Hide resolved
LGTM! 🎉🎉🎉 |
Related to #3672
This PR adds support for a new property,TokenizingTextBox.TokenSelectionMode
, which allows a developer to specify if the TTB should allow one or many tokens inside the box as results.This PR adds support for a new property,
TokenizingTextBox.MaxTokens
, which allows a developer to specify a maximum number of token results allowed in the TTB.An issue was originally reported on the Graph-Controls repo mentioning that the
SelectionMode
property is not being respected in the PeoplePicker control. The use case was to use PeoplePicker to select a person for a particular role in which there should only be one person assigned. Without a specific property to support this, applying a workaround for restricting theTokenizingTextBox
/PeoplePicker
controls to only allow one token is a pain.That said,
SelectionMode
actually comes fromListViewBase
, and is more associated with "Selection" in a different context. Work could be done to enable other "selection" features for tokens, but that's not what this issue is really about.PR Type
What kind of change does this PR introduce?
What is the current behavior?
Currently the
TokenizingTextBox
is allows multiple tokens to be selected and there is no mechanism for restricting the box to only one token at a time.Meanwhile, the
SelectionMode
property exists but is otherwise unused in this control. It's a separate thing.What is the new behavior?
The newTokenSelectionMode
enum andTokenizingTextBox.TokenSelectionMode
property controls how many tokens can be present in the TTB at a time.The default isTokenSelectionMode.Multiple
so that it works the same out of the box as before. However, you can now specifyTokenSelectionMode.Single
to restrict the TTB to only one token. In single mode, adding a new token will replace any existing.TokenSelectionMode
only has two values,Single
andMultiple
.The new
TokenizingTextBox.MaximumTokens
property controls how many tokens can be present in the TTB at a time.Potential values:
null
, meaning any number of tokens can be added without restriction.A counter visual has been added at the end to indicate how many items are present and the maximum number of tokens allowed. The counter visual is only visible when the MaximumTokensProperty is greater than 0.
When at maximum token capacity, the control will not accept new items and the counter will turn red:
PR Checklist
Please check if your PR fulfills the following requirements:
Other information