Browse Source

Merge pull request #26499 from abpframework/fix/mudblazor-notification-title

Show a MudBlazor notification's title as markup, not as text
pull/26504/head
Enis Necipoglu 2 weeks ago
committed by GitHub
parent
commit
cbb2c95bb4
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 25
      framework/src/Volo.Abp.MudBlazorUI/Components/UiNotificationAlert.razor.cs

25
framework/src/Volo.Abp.MudBlazorUI/Components/UiNotificationAlert.razor.cs

@ -1,4 +1,5 @@
using System; using System;
using System.Net;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Localization; using Microsoft.Extensions.Localization;
@ -57,21 +58,33 @@ public partial class UiNotificationAlert : ComponentBase, IDisposable
Title = e.Title; Title = e.Title;
Options = e.Options; Options = e.Options;
var message = !string.IsNullOrEmpty(Title)
? $"<strong>{Title}</strong><br/>{Message}"
: Message;
await InvokeAsync(() => await InvokeAsync(() =>
{ {
Snackbar.Add(message, GetSeverity(e.NotificationType), config => Action<SnackbarOptions> configure = config =>
{ {
config.RequireInteraction = false; config.RequireInteraction = false;
config.ShowCloseIcon = true; config.ShowCloseIcon = true;
config.CloseAfterNavigation = true; config.CloseAfterNavigation = true;
}); };
// A string is shown as plain text, so the title's markup must go as a MarkupString.
// Title and message are encoded first: they can carry user input (a chat message, a name).
if (!string.IsNullOrEmpty(Title))
{
Snackbar.Add(GetTitledMessage(Title, Message), GetSeverity(e.NotificationType), configure);
}
else
{
Snackbar.Add(Message, GetSeverity(e.NotificationType), configure);
}
}); });
} }
protected virtual MarkupString GetTitledMessage(string title, string message)
{
return new MarkupString($"<strong>{WebUtility.HtmlEncode(title)}</strong><br/>{WebUtility.HtmlEncode(message)}");
}
public virtual void Dispose() public virtual void Dispose()
{ {
if (UiNotificationService != null) if (UiNotificationService != null)

Loading…
Cancel
Save