diff --git a/src/AspNetCore.Utilities.Bootstrap5TagHelpers.Sample/Views/Home/Index.cshtml b/src/AspNetCore.Utilities.Bootstrap5TagHelpers.Sample/Views/Home/Index.cshtml
index 200c116..474c069 100644
--- a/src/AspNetCore.Utilities.Bootstrap5TagHelpers.Sample/Views/Home/Index.cshtml
+++ b/src/AspNetCore.Utilities.Bootstrap5TagHelpers.Sample/Views/Home/Index.cshtml
@@ -73,21 +73,29 @@
-
- Warning Dismissible |
-
-
- This is a dismissible warning alert!
-
- |
-
-
- <alert alert-color="Warning" dismissible="false">
- This is a dismissible warning alert!
- </alert>
-
- |
-
+
+ Warning Dismissible |
+
+
+ This is a dismissible warning alert!
+
+ |
+
+
+ <alert alert-color="Warning" dismissible="false">
+ This is a dismissible warning alert!
+ </alert>
+
+ |
+
+
+ Alert With Header |
+
+
+ Look at me! I have a header!
+
+ |
+
diff --git a/src/AspNetCore.Utilities.Bootstrap5TagHelpers/AlertTagHelper.cs b/src/AspNetCore.Utilities.Bootstrap5TagHelpers/AlertTagHelper.cs
index fcf955b..453d5db 100644
--- a/src/AspNetCore.Utilities.Bootstrap5TagHelpers/AlertTagHelper.cs
+++ b/src/AspNetCore.Utilities.Bootstrap5TagHelpers/AlertTagHelper.cs
@@ -26,6 +26,11 @@ public class AlertTagHelper : TagHelper
///
public bool Dismissible { get; set; } = false;
+ ///
+ /// If supplied this will render as a heading inside the alert.
+ ///
+ public string? HeadingText { get; set; }
+
///
/// Processes the tag helper
///
@@ -50,10 +55,21 @@ public override async Task ProcessAsync(TagHelperContext context, TagHelperOutpu
output.AddClass("fade", HtmlEncoder.Default);
output.AddClass("show", HtmlEncoder.Default);
}
+
output.Attributes.Add("role", "alert");
+ if (!string.IsNullOrEmpty(HeadingText))
+ {
+ var headingBuilder = new TagBuilder("h4");
+ headingBuilder.AddCssClass("alert-heading");
+ headingBuilder.InnerHtml.Append(HeadingText);
+ output.PreContent.AppendHtml(headingBuilder);
+ }
+
if (!Dismissible)
+ {
return;
+ }
var buttonBuilder = new TagBuilder("button");
buttonBuilder.Attributes.Add("type", "button");
@@ -62,7 +78,7 @@ public override async Task ProcessAsync(TagHelperContext context, TagHelperOutpu
buttonBuilder.Attributes.Add("aria-label", "Close");
//Get existing content
- var existing = await output.GetChildContentAsync();
+ TagHelperContent existing = await output.GetChildContentAsync();
output.Content.AppendHtml(existing.GetContent());
output.Content.AppendHtml(buttonBuilder);
}