Skip to content

Commit bc7524f

Browse files
Updated an validated modals to be working
1 parent 7cbb332 commit bc7524f

File tree

15 files changed

+56
-32
lines changed

15 files changed

+56
-32
lines changed

src/AspNetCore.Utilities.Bootstrap5TagHelpers.Sample/Views/Home/Index.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@
344344
<form-input asp-for="FirstName"></form-input>
345345
</modal-body>
346346
<modal-footer>
347-
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
347+
<bs-button bs-color="Secondary" dismisses="modal">Close</bs-button>
348348
</modal-footer>
349349
</modal>
350350
</td>

src/AspNetCore.Utilities.Bootstrap5TagHelpers.Tests/ButtonTagHelperTests.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,9 @@ public async Task Throws_Error_If_Invalid_ButtonSize()
109109
}
110110

111111
[Fact]
112-
public async Task Adds_Class_If_Block_Button()
112+
public async Task Adds_Attribute_If_Dismisses_Has_Value()
113113
{
114-
var output = await (new ButtonTagHelper() { Block=true }).Render();
115-
output.AssertContainsClass("btn-block");
114+
var output = await (new ButtonTagHelper() { Dismisses = "modal"}).Render();
116115
await VerifyTagHelper(output);
117116
}
118117

src/AspNetCore.Utilities.Bootstrap5TagHelpers.Tests/Modal/ModalHeaderDismissTagHelperTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ public void Should_Render_As_Button()
2222

2323
[Theory]
2424
[InlineData("aria-label", "Close")]
25-
[InlineData("data-dismiss", "modal")]
26-
[InlineData("class", "close")]
25+
[InlineData("data-bs-dismiss", "modal")]
26+
[InlineData("class", "btn-close")]
2727
[InlineData("type", "button")]
2828
public void Should_Set_Needed_Attributes(string expectedAttribute, string expectedValue)
2929
{

src/AspNetCore.Utilities.Bootstrap5TagHelpers.Tests/Modal/ModalHeaderTagHelperTests.cs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ public async Task Should_NotRender_InnerContent_When_Title_Missing()
105105
}
106106

107107
[Theory]
108-
[InlineData("My Title", "", "<h5 class=\"modal-title\">My Title</h5>")]
109-
[InlineData("My Title", "myModal", "<h5 class=\"modal-title\" id=\"myModalLabel\">My Title</h5>")]
108+
[InlineData("My Title", "", "<h2 class=\"modal-title fs-5\">My Title</h2>")]
109+
[InlineData("My Title", "myModal", "<h2 class=\"modal-title fs-5\" id=\"myModalLabel\">My Title</h2>")]
110110
public async Task Should_Render_InnerContent_Title_When_Title_Provided(string title, string id, string expectedHtml)
111111
{
112112
//Arrange
@@ -121,4 +121,24 @@ public async Task Should_Render_InnerContent_Title_When_Title_Provided(string ti
121121
//Assert
122122
Assert.Equal(expectedHtml, output.Content.GetContent());
123123
}
124+
125+
[Theory]
126+
[InlineData("My Title", "", "", "<h2 class=\"modal-title fs-5\">My Title</h2>")]
127+
[InlineData("My Title", "myModal", "h5", "<h5 class=\"modal-title fs-5\" id=\"myModalLabel\">My Title</h5>")]
128+
public async Task Should_Render_InnerContent_Title_WithCustomTag_When_Title_Provided(string title, string id, string tag, string expectedHtml)
129+
{
130+
//Arrange
131+
TagHelperContext context = MakeTagHelperContext();
132+
context.Items.Add(typeof(ModalContext), new ModalContext { Id = id });
133+
TagHelperOutput output = MakeTagHelperOutput(" ");
134+
135+
//Act
136+
var helper = new ModalHeaderTagHelper { Title = title };
137+
if (!string.IsNullOrEmpty(tag))
138+
helper.TitleTag = tag;
139+
await helper.ProcessAsync(context, output);
140+
141+
//Assert
142+
Assert.Equal(expectedHtml, output.Content.GetContent());
143+
}
124144
}

src/AspNetCore.Utilities.Bootstrap5TagHelpers.Tests/Modal/ModalTagHelperTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public async Task Should_Render_Static_Backdrop_Attribute_When_Flagged(bool stat
120120
string expectedAttributeValue)
121121
{
122122
//Arrange
123-
var attributeName = "data-backdrop";
123+
var attributeName = "data-bs-backdrop";
124124
TagHelperContext context = MakeTagHelperContext();
125125
TagHelperOutput output = MakeTagHelperOutput(" ");
126126

src/AspNetCore.Utilities.Bootstrap5TagHelpers.Tests/Modal/ModalToggleTagHelperTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public void Should_Render_DataToggle_Attribute()
6262
helper.Process(context, output);
6363

6464
//Assert
65-
Assert.Equal("modal", output.Attributes["data-toggle"].Value);
65+
Assert.Equal("modal", output.Attributes["data-bs-toggle"].Value);
6666
}
6767

6868
[Fact]
@@ -77,7 +77,7 @@ public void Should_Render_DataTarget_Attribute()
7777
helper.Process(context, output);
7878

7979
//Assert
80-
Assert.Equal("#testTarget", output.Attributes["data-target"].Value);
80+
Assert.Equal("#testTarget", output.Attributes["data-bs-target"].Value);
8181
}
8282

8383
[Fact]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+

2+
<button type="HtmlEncode[[button]]" class="btn btn-info" role="HtmlEncode[[button]]" data-bs-dismiss="HtmlEncode[[modal]]"></button>

src/AspNetCore.Utilities.Bootstrap5TagHelpers/ButtonTagHelper.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ public class ButtonTagHelper : TagHelper
8787
public bool Disabled { get; set; }
8888

8989
/// <summary>
90-
/// Is this a block level button
90+
/// If a value is provided this
9191
/// </summary>
92-
public bool Block { get; set; }
92+
public string? Dismisses { get; set; }
9393

9494
/// <summary>
9595
/// The size of this button
@@ -134,9 +134,9 @@ public override async Task ProcessAsync(TagHelperContext context, TagHelperOutpu
134134
}, HtmlEncoder.Default);
135135
}
136136

137-
if (Block)
137+
if (!string.IsNullOrEmpty(Dismisses))
138138
{
139-
output.AddClass("btn-block", HtmlEncoder.Default);
139+
output.Attributes.Add("data-bs-dismiss", Dismisses);
140140
}
141141

142142
TagHelperContent? content = await output.GetChildContentAsync();

src/AspNetCore.Utilities.Bootstrap5TagHelpers/Card/CardBodyTagHelper.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace ICG.AspNetCore.Utilities.Bootstrap5TagHelpers.Card
88
/// <summary>
99
/// Tag Helper for the body of a Card
1010
/// </summary>
11+
[HtmlTargetElement("card-body", ParentTag = "card")]
1112
public class CardBodyTagHelper : TagHelper
1213
{
1314
/// <summary>

src/AspNetCore.Utilities.Bootstrap5TagHelpers/Card/CardFooterTagHelper.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace ICG.AspNetCore.Utilities.Bootstrap5TagHelpers.Card;
88
/// <summary>
99
/// Tag Helper for rendering the header for a card
1010
/// </summary>
11+
[HtmlTargetElement("card-footer", ParentTag = "card")]
1112
public class CardFooterTagHelper : TagHelper
1213
{
1314
/// <summary>

0 commit comments

Comments
 (0)