[dev-v5] Toast Service Refactoring#4950
Open
dvoituron wants to merge 45 commits into
Open
Conversation
…ew naming conventions
…setting on dismissal
…ove code readability
…nce component key handling
…nd improve dismissal handling
…rove status logging
…ss handling, and update close method signature
…d clarity in dismissal handling
…tates, and enhance toast instance management
…ut, and improve progress display
…in ascending order
…nd DismissTooltip, enhancing customization options for dismiss actions
…ion of dismiss options, including label, tooltip, and callback functionality.
…ser interaction with customizable actions in the toast footer.
… detailed usage guidelines and examples for better user understanding.
…tdated content and enhancing usage guidelines. Update toast component to use transparent button appearance for dismiss action and remove unnecessary timestamp property from ToastOptions.
…allbackAsync to OnClickAsync for improved clarity and consistency. Add new example for default toast options.
… methods for improved clarity and consistency. Update button actions to reflect changes in toast display logic.
… rendering and improve type safety with DynamicallyAccessedMembers attributes. Update toast content rendering logic for better flexibility.
…uce ToastResultTiming enum for improved result completion control.
…ntrol and user interaction. Introduce new example for result timing options and update toast service methods for improved clarity.
…t functionality into a more streamlined testing approach.
…tial values. Refactor message bar test to correct interface implementation.
…nService and improve setup consistency
|
✅ All tests passed successfully Details on your Workflow / Core Tests page. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the Toast system to use a unified INotificationService shared with MessageBar, introducing new toast option semantics (custom body components + parameters, action model, and result timing) and updating providers, docs, and demo examples accordingly.
Changes:
- Replaced
IToastService/ToastServicewithINotificationService/NotificationServicefor toast operations and lifecycle handling. - Updated toast APIs (
ToastOptions,ToastInstance,ToastResult,ToastResultTiming, action model) and provider rendering to support dynamic Razor components and actions. - Removed legacy toast tests and updated MessageBar tests; refreshed documentation and demo examples; extracted toast web-component styles into a separate TS module.
Reviewed changes
Copilot reviewed 49 out of 49 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Core/Components/Toast/ToastInstanceTests.razor | Removed legacy toast instance/service tests (no replacement included in this PR). |
| tests/Core/Components/Toast/FluentToastTests.razor | Removed legacy FluentToast bUnit test suite. |
| tests/Core/Components/Toast/FluentToastTests.FluentToast_WithInstance.verified.razor.html | Removed legacy snapshot for toast tests. |
| tests/Core/Components/Toast/FluentToastProviderTests.razor | Removed legacy FluentToastProvider test suite. |
| tests/Core/Components/MessageBar/MessageBarServiceTests.cs | Updated tests to resolve INotificationService from DI using bUnit context. |
| tests/Core/Components/MessageBar/MessageBarInstanceTests.cs | Updated tests for new notification service base types and DI usage. |
| tests/Core/Components/MessageBar/MessageBarEventArgsTests.cs | Updated tests to use DI-provided notification service. |
| tests/Core/Components/MessageBar/FluentMessageBarProviderTests.razor | Adjusted fake instance implementation for INotificationInstance. |
| src/Core/Extensions/ServiceCollectionExtensions.cs | Removed IToastService registration; registers INotificationService as the unified service. |
| src/Core/Events/ToastEventArgs.cs | Simplified event args construction; updated docs to reference notification service. |
| src/Core/Enums/ToastResultTiming.cs | Introduced ToastResultTiming (replacing previous enum content) for controlling when results complete. |
| src/Core/Enums/ToastIntent.cs | Expanded intent docs and added Progress. |
| src/Core/Components/Toast/Services/ToastService.cs | Removed legacy ToastService implementation. |
| src/Core/Components/Toast/Services/ToastResult.cs | Added structured toast result (Reason, Data, Instance). |
| src/Core/Components/Toast/Services/ToastOptionsAction.cs | Added unified action model for quick/dismiss actions. |
| src/Core/Components/Toast/Services/ToastOptions.cs | Renamed/reshaped toast options (message/lifetime/actions/parameters/result timing). |
| src/Core/Components/Toast/Services/ToastInstance.cs | Updated toast instance to work with notification service + new result model and status transitions. |
| src/Core/Components/Toast/Services/NotificationService.cs | Added toast-related notification service implementation (show/close/queue/remove). |
| src/Core/Components/Toast/Services/LibraryToastOptions.cs | Updated global toast defaults (lifetime/allow dismiss/width) and documentation. |
| src/Core/Components/Toast/Services/IToastService.cs | Removed legacy toast service interface. |
| src/Core/Components/Toast/Services/IToastInstance.cs | Updated toast instance interface to align with notification-instance model and results. |
| src/Core/Components/Toast/Services/INotificationService.cs | Added toast-capable notification service interface (toast API surface). |
| src/Core/Components/Toast/FluentToastProvider.razor.cs | Updated provider to subscribe/unsubscribe to notification updates; new queue/render logic. |
| src/Core/Components/Toast/FluentToastProvider.razor | Updated provider rendering: cascading instance, dynamic body component/message, footer template, lifetime, width. |
| src/Core/Components/Toast/FluentToast.razor.cs | Updated FluentToast component API (lifetime, actions, cascading instance) and lifecycle handling. |
| src/Core/Components/Toast/FluentToast.razor | Updated toast markup (slots, lifetime->timeout ms, sanitized title/subtitle, footer template). |
| src/Core/Components/MessageBar/Services/NotificationService.Subscribers.cs | Generalized subscribers to INotificationInstance. |
| src/Core/Components/MessageBar/Services/NotificationService.cs | Converted service base type to INotificationInstance and generalized CloseAsync(id, ...) to close message bars or toasts. |
| src/Core/Components/MessageBar/Services/MessageBarOptions.cs | Minor doc improvement for options factory parameter. |
| src/Core/Components/MessageBar/Services/MessageBarInstance.cs | Updated to implement INotificationInstance component-type plumbing with trimming annotations. |
| src/Core/Components/MessageBar/Services/INotificationService.cs | Updated notification service interface base type and generalized close-by-id semantics. |
| src/Core/Components/MessageBar/Services/INotificationInstance.cs | Added shared notification instance abstraction (Id, Index, CloseAsync, optional component type). |
| src/Core/Components/MessageBar/Services/IMessageBarInstance.cs | Updated to inherit INotificationInstance. |
| src/Core/Components/MessageBar/FluentMessageBarProvider.razor.cs | Updated provider filtering to use new INotificationInstance item store. |
| src/Core/Components/Dialog/DialogEventArgs.cs | Extracted dialog state derivation into reusable helper (GetDialogState). |
| src/Core/Components/Base/FluentSlot.cs | Added toast slot constants (ToastMedia, ToastTitle, ToastAction, ToastSubtitle, ToastFooter). |
| src/Core.Scripts/src/Components/Toast/FluentToast.ts | Refactored style injection to use extracted TS styles module. |
| src/Core.Scripts/src/Components/Toast/FluentToast-Styles.ts | Added extracted toast CSS as a TS string constant. |
| examples/Demo/FluentUI.Demo.Client/Documentation/Components/Toast/FluentToast.md | Updated docs to reference INotificationService, new options/actions/result timing, and updated defaults. |
| examples/Demo/FluentUI.Demo.Client/Documentation/Components/Toast/Examples/Toast/CustomizedProgressToast.razor | Added custom toast body component example using cascading toast instance + parameters. |
| examples/Demo/FluentUI.Demo.Client/Documentation/Components/Toast/Examples/FluentToastResultTiming.razor | Added result timing example (Closed vs Visible). |
| examples/Demo/FluentUI.Demo.Client/Documentation/Components/Toast/Examples/FluentToastQuickActions.razor | Added quick actions example using ToastOptionsAction. |
| examples/Demo/FluentUI.Demo.Client/Documentation/Components/Toast/Examples/FluentToastInverted.razor | Updated inverted toast demo to use INotificationService + new options. |
| examples/Demo/FluentUI.Demo.Client/Documentation/Components/Toast/Examples/FluentToastIndeterminateProgress.razor | Updated progress example to new progress intent + instance tracking. |
| examples/Demo/FluentUI.Demo.Client/Documentation/Components/Toast/Examples/FluentToastDeterminateProgress.razor | Updated determinate progress example to use custom component toast. |
| examples/Demo/FluentUI.Demo.Client/Documentation/Components/Toast/Examples/FluentToastDefaultOptions.razor | Added new default-options sample using intent-based toasts. |
| examples/Demo/FluentUI.Demo.Client/Documentation/Components/Toast/Examples/FluentToastDefault.razor | Updated default demo to use convenience toast methods + progress instance handling. |
| examples/Demo/FluentUI.Demo.Client/Documentation/Components/Toast/Examples/FluentToastCustomDismiss.razor | Updated custom dismiss example to use new dismiss action model. |
| examples/Demo/FluentUI.Demo.Client/Documentation/Components/TextInput/Examples/TextInputPrefixSuffix.razor | Updated clipboard toast usage to INotificationService. |
Comments suppressed due to low confidence (1)
src/Core/Components/Toast/FluentToastProvider.razor.cs:180
SynchronizeToastQueuedoesn't handle the documentedMaxToastCount = 0(unlimited) case. WithmaxToastCount == 0, the conditionactiveCount >= maxToastCountis always true, so queued toasts will never be promoted to visible.
var maxToastCount = configuration.Toast.MaxToastCount;
var activeCount = ToastItems.Count(toast => toast.LifecycleStatus is ToastLifecycleStatus.Visible or ToastLifecycleStatus.Dismissed);
var queuedToasts = ToastItems.Where(toast => toast.LifecycleStatus == ToastLifecycleStatus.Queued)
.OrderBy(toast => toast.Index)
.ToList();
foreach (var toast in queuedToasts)
{
if (activeCount >= maxToastCount)
{
break;
Summary - Unit Tests Code CoverageSummary
CoverageMicrosoft.FluentUI.AspNetCore.Components - 98.5%
|
vnbaaij
requested changes
Jun 23, 2026
…definite display for interactive toasts
…time behavior based on options and actions
… and dismissal behaviors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
[dev-v5] Toast Service Refactoring
Migrate Toast components to a new notification system, improving the structure, state management, and customization options. Update the documentation and examples. This change improves user interaction and aligns with the new naming conventions to facilitate maintenance.
Main new features:
INotificationService, shared with MessageBar and ToastShowSuccessToastAsyncToastOptionsActionclass for quick actions and dismiss actionsResultTimingoption to interact with theResultvalue when it is available in C# (awaitkeyword)Examples
Fastest helper methods
This example shows the fastest helper methods to display success, info, warning, error and progress toasts
by using a required title plus optional message and dismiss button details.
Default
This example shows the standard toast setup with default behavior and intent. Use it as the baseline pattern for simple status feedback.
In this example, Success, Warning, Error, and Info toasts are shown for 5 seconds (
lifetime = 5) and then close automatically.The Progress toast behaves differently: the line
ProgressResult = await NotificationService.ShowProgressToastAsync()returns immediatelya toast instance that is stored in
ProgressResult.Instance.When
ProgressResultis available, the [Close Progress] button is enabled so the user can close that toast manually.Custom dismissal
This example shows a toast that uses a custom dismiss action instead of the default dismiss button, useful when you need a tailored close flow.
Determinate progress
This example shows a determinate progress toast that updates as the operation advances toward completion.
It uses
ShowToastAsync<TToast>(...), where the generic typeTToastis the Razor component dynamically rendered inside the toast body.With this approach, you can open any Razor component in the toast and fully customize its content and behavior.
Quick actions
This example shows quick action links inside the toast so people can immediately respond to the notification.
Result Timing
This example shows when your application should consider an interaction with a context notification to be complete and when the .NET code should continue executing
var result = await NotificationService.ShowToastAsync().By default,
await NotificationService.ShowToastAsync(...)resumes only when the toast is closed.If you do not want to wait for the result, start the call without waiting for completion:
_ = NotificationService.ShowToastAsync(...);You can also control when the awaited result is completed with
ResultTiming:ResultTiming = Closed(default): code afterawaitruns after the toast is closed.ResultTiming = Visible: code afterawaitruns as soon as the toast is visible.When using
Visible, keep the returnedresult.Instanceif you need to interact with that toast later (for example, close it programmatically).In the sample, both toasts stay visible for 5 seconds. Show Lifetime On Close reports the result after the toast closes,
while Show Lifetime On Visible reports it immediately when the toast appears.
TODO