-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[Feature] RichSuggestBox control #3649
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
Comments
Hello, 'huynhsontung! Thanks for submitting a new feature request. I've automatically added a vote 👍 reaction to help get things started. Other community members can vote to help us prioritize this feature in the future! |
@huynhsontung Thanks for the PR and it looks like a very engaging feature. Will it test out once the PR is ready and on the meantime will open this for discussion to see what others think 🤔 |
<!-- 🚨 Please Do Not skip any instructions and information mentioned below as they are all required and essential to evaluate and test the PR. By fulfilling all the required information you will be able to reduce the volume of questions and most likely help merge the PR faster 🚨 --> <!-- 📝 It is preferred if you keep the "☑️ Allow edits by maintainers" checked in the Pull Request Template as it increases collaboration with the Toolkit maintainers by permitting commits to your PR branch (only) created from your fork. This can let us quickly make fixes for minor typos or forgotten StyleCop issues during review without needing to wait on you doing extra work. Let us help you help us! 🎉 --> ## Fixes # <!-- Add the relevant issue number after the "#" mentioned above (for ex: Fixes #1234) which will automatically close the issue once the PR is merged. --> Closes #3649 <!-- Add a brief overview here of the feature/bug & fix. --> Implement rich suggest text control as discussed in the issue. ## PR Type What kind of change does this PR introduce? <!-- Please uncomment one or more that apply to this PR. --> <!-- - Bugfix --> - Feature <!-- - Code style update (formatting) --> <!-- - Refactoring (no functional changes, no api changes) --> <!-- - Build or CI related changes --> <!-- - Documentation content changes --> <!-- - Sample app changes --> <!-- - Other... Please describe: --> ## What is the current behavior? <!-- Please describe the current behavior that you are modifying, or link to a relevant issue. --> None. The control did not exist before this PR. ## What is the new behavior? <!-- Describe how was this issue resolved or changed? --> 'RichSuggestBox' is now a usable control in the `Microsoft.Toolkit.Uwp.UI.Controls` namespace. ## PR Checklist Please check if your PR fulfills the following requirements: - [ ] Tested code with current [supported SDKs](../readme.md#supported) - [x] Pull Request has been submitted to the documentation repository [instructions](..\contributing.md#docs). Link: MicrosoftDocs/WindowsCommunityToolkitDocs#558 - [x] Sample in sample app has been added / updated (for bug fixes / features) - [x] Icon has been created (if new sample) following the [Thumbnail Style Guide and templates](https://github.com/windows-toolkit/WindowsCommunityToolkit-design-assets) - [ ] New major technical changes in the toolkit have or will be added to the [Wiki](https://github.com/windows-toolkit/WindowsCommunityToolkit/wiki) e.g. build changes, source generators, testing infrastructure, sample creation changes, etc... - [x] Tests for the changes have been added (for bug fixes / features) (if applicable) - [x] Header has been added to all new source files (run *build/UpdateHeaders.bat*) - [x] Contains **NO** breaking changes <!-- If this PR contains a breaking change, please describe the impact and migration path for existing applications below. Please note that breaking changes are likely to be rejected within minor release cycles or held until major versions. --> ## Other information ### Convenient issue tracker - Limited styling options for tokens. Only text styling options are available. - Tokens are raw text and not UI elements. UI events (e.g. `UIElement.PointerEntered`) are not available. ~~This makes behaviors like showing flyout when hover mouse over the token impossible.~~ - Tokens are always underlined. - Tokens cannot adapt to theme change dynamically. They will lose foreground color while having the same background color which will most likely introduce bad contrast. - Cannot disable spelling check on tokens (token text may have red underline). - ~~Cannot use Tab to select a suggestion due to conflict with the accessibility feature.~~ - Deleted tokens will be kept in an internal list until cleared programmatically to support Undo and Redo. ### RichEditBox issues Below are `RichEditBox` related issues encountered during the development of this control. - Getting `Link` property from a range might change the range. - Replacing a formatted link at the beginning of the document does not reset the formatting. The replaced text still has the same formatting. - Setting the `Link` property can sometimes fail but only when the target text is at the beginning of the document. - There is no event for when text is about to change. `TextChanging` and `SelectionChanging` are invoked after the text has changed. - Character format foreground color cannot display a range of colors (e.g. #F7FFB3)
Describe the problem this feature would solve
I am making a chat app using UWP and I realized there is no easy way to implement a chat box that has mentioning feature (think of Slack or Discord or even GitHub where you type
@
to mention other people). This feature is prevalent in comment or chat context, you can find it in every application that provides communication between people in a group. A text box with mentioning feature is crucial to many social applications.Describe the solution
Making a text box that provides suggestions on specific prefixes (like
@
for mention,#
for channel, etc.). IntroducingRichSuggestBox
(name pending)! During the break, I actually made this control for my app and I think it would be a good addition for many UWP apps.Please see the last section for demos
How it works
Inspired by Content links in text controls,
RichSuggestBox
works on top of aRichEditBox
and it embeds the token into the document as a link. Unlike content links where you can only add either places or people in your Windows contacts,RichSuggestBox
lets you embed anything! It provides a suggestion dropdown for users to pick a suggestion, similar toAutoSuggestBox
. Links generated are not real hyperlinks (user cannotCtrl + Click
the link).Features
RichEditBox
@
for mention,#
for channel)Caveats
There are some caveats with how the control works at the moment. I may require the community's assistance/decisions on these.
RichEditBox
, you are stuck with basic text foreground, background, bold, italic, underline, etc. But until we can add custom UI intoRichEditBox
(related WinUI issue), the only way I can think of is to make a fully custom input control fromRichTextBlock
, which I think should be avoided.Describe alternatives you've considered
TokenizingTextBox
. It does not support raw text, token does not wrap, and has greater height than text, making it unsuitable for multiline text box. See [Feature] Raw text support for TokenizingTextBox #3486AutoSuggestBox
. Underlying input control isTextBox
which cannot modify text style.Additional context & Screenshots
Some demos using the following event handlers.
How it looks like (the control is only the text box, everything else is for demonstration purposes).

Support multiple prefixes with custom style override.

Observable token position.

Support undo and redo.

Suggestions based on caret.

The text was updated successfully, but these errors were encountered: