From 5bc5aae45e9eaea21b47a08db1fd1ea4dbf840a2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 27 Jul 2025 21:34:48 +0000 Subject: [PATCH 1/2] Initial plan From 41949494f03169780ecff5bcd81683dfad841256 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 27 Jul 2025 21:47:15 +0000 Subject: [PATCH 2/2] Add IsInline property support to FormCheckboxTagHelper Co-authored-by: mitchelsellers <5659113+mitchelsellers@users.noreply.github.com> --- .../Views/Home/StandardForm.cshtml | 7 ++ .../Form/FormCheckboxTagHelperTests.cs | 67 +++++++++++++++++++ .../Form/TestModel.cs | 2 + ...eckboxTagHelperTests.Renders.verified.html | 7 ++ ...agHelperTests.Renders_Inline.verified.html | 7 ++ ...erTests.Renders_InlineSwitch.verified.html | 7 ++ ...agHelperTests.Renders_Switch.verified.html | 7 ++ .../Form/FormCheckboxTagHelper.cs | 9 +++ 8 files changed, 113 insertions(+) create mode 100644 src/AspNetCore.Utilities.Bootstrap5TagHelpers.Tests/Form/FormCheckboxTagHelperTests.cs create mode 100644 src/AspNetCore.Utilities.Bootstrap5TagHelpers.Tests/VerifySnapshots/FormCheckboxTagHelperTests.Renders.verified.html create mode 100644 src/AspNetCore.Utilities.Bootstrap5TagHelpers.Tests/VerifySnapshots/FormCheckboxTagHelperTests.Renders_Inline.verified.html create mode 100644 src/AspNetCore.Utilities.Bootstrap5TagHelpers.Tests/VerifySnapshots/FormCheckboxTagHelperTests.Renders_InlineSwitch.verified.html create mode 100644 src/AspNetCore.Utilities.Bootstrap5TagHelpers.Tests/VerifySnapshots/FormCheckboxTagHelperTests.Renders_Switch.verified.html diff --git a/src/AspNetCore.Utilities.Bootstrap5TagHelpers.Sample/Views/Home/StandardForm.cshtml b/src/AspNetCore.Utilities.Bootstrap5TagHelpers.Sample/Views/Home/StandardForm.cshtml index 5504029..f8b9821 100644 --- a/src/AspNetCore.Utilities.Bootstrap5TagHelpers.Sample/Views/Home/StandardForm.cshtml +++ b/src/AspNetCore.Utilities.Bootstrap5TagHelpers.Sample/Views/Home/StandardForm.cshtml @@ -37,6 +37,13 @@ +
+ + + + + +
Click Here To Test Validation diff --git a/src/AspNetCore.Utilities.Bootstrap5TagHelpers.Tests/Form/FormCheckboxTagHelperTests.cs b/src/AspNetCore.Utilities.Bootstrap5TagHelpers.Tests/Form/FormCheckboxTagHelperTests.cs new file mode 100644 index 0000000..1246ffe --- /dev/null +++ b/src/AspNetCore.Utilities.Bootstrap5TagHelpers.Tests/Form/FormCheckboxTagHelperTests.cs @@ -0,0 +1,67 @@ +using ICG.AspNetCore.Utilities.Bootstrap5TagHelpers.Form; +using ICG.AspNetCore.Utilities.Bootstrap5TagHelpers.Tests.FromFramework; +using Microsoft.AspNetCore.Mvc.Rendering; +using Microsoft.AspNetCore.Mvc.ViewFeatures; +using Xunit.Abstractions; + +namespace ICG.AspNetCore.Utilities.Bootstrap5TagHelpers.Tests.Form; + +[UsesVerify] +public sealed class FormCheckboxTagHelperTests : ModelTagHelperTest +{ + public FormCheckboxTagHelperTests(ITestOutputHelper output) : base(output) + { + + } + + [Fact] + public async Task Renders() + { + var metadataProvider = new TestModelMetadataProvider(); + var htmlGenerator = new TestableHtmlGenerator(metadataProvider); + + var tagHelper = GetTagHelper(htmlGenerator, model: false, propertyName: nameof(TestModel.CheckboxField)); + var output = await tagHelper.Render(); + await VerifyTagHelper(output); + } + + [Fact] + public async Task Renders_Inline() + { + var metadataProvider = new TestModelMetadataProvider(); + var htmlGenerator = new TestableHtmlGenerator(metadataProvider); + + var tagHelper = GetTagHelper(htmlGenerator, model: false, propertyName: nameof(TestModel.CheckboxField)); + tagHelper.IsInline = true; + var output = await tagHelper.Render(); + await VerifyTagHelper(output); + } + + [Fact] + public async Task Renders_Switch() + { + var metadataProvider = new TestModelMetadataProvider(); + var htmlGenerator = new TestableHtmlGenerator(metadataProvider); + + var tagHelper = GetTagHelper(htmlGenerator, model: false, propertyName: nameof(TestModel.CheckboxField)); + tagHelper.IsSwitch = true; + var output = await tagHelper.Render(); + await VerifyTagHelper(output); + } + + [Fact] + public async Task Renders_InlineSwitch() + { + var metadataProvider = new TestModelMetadataProvider(); + var htmlGenerator = new TestableHtmlGenerator(metadataProvider); + + var tagHelper = GetTagHelper(htmlGenerator, model: false, propertyName: nameof(TestModel.CheckboxField)); + tagHelper.IsInline = true; + tagHelper.IsSwitch = true; + var output = await tagHelper.Render(); + await VerifyTagHelper(output); + } + + internal override FormCheckboxTagHelper TagHelperFactory(IHtmlGenerator htmlGenerator, ModelExpression modelExpression, ViewContext viewContext) + => new(htmlGenerator) { For = modelExpression, ViewContext = viewContext }; +} \ No newline at end of file diff --git a/src/AspNetCore.Utilities.Bootstrap5TagHelpers.Tests/Form/TestModel.cs b/src/AspNetCore.Utilities.Bootstrap5TagHelpers.Tests/Form/TestModel.cs index 4f07c86..233ce2f 100644 --- a/src/AspNetCore.Utilities.Bootstrap5TagHelpers.Tests/Form/TestModel.cs +++ b/src/AspNetCore.Utilities.Bootstrap5TagHelpers.Tests/Form/TestModel.cs @@ -7,4 +7,6 @@ public class TestModel [Required] public int? RequiredIntField { get; set; } + + public bool CheckboxField { get; set; } } diff --git a/src/AspNetCore.Utilities.Bootstrap5TagHelpers.Tests/VerifySnapshots/FormCheckboxTagHelperTests.Renders.verified.html b/src/AspNetCore.Utilities.Bootstrap5TagHelpers.Tests/VerifySnapshots/FormCheckboxTagHelperTests.Renders.verified.html new file mode 100644 index 0000000..5584840 --- /dev/null +++ b/src/AspNetCore.Utilities.Bootstrap5TagHelpers.Tests/VerifySnapshots/FormCheckboxTagHelperTests.Renders.verified.html @@ -0,0 +1,7 @@ + +
+ + + + +
\ No newline at end of file diff --git a/src/AspNetCore.Utilities.Bootstrap5TagHelpers.Tests/VerifySnapshots/FormCheckboxTagHelperTests.Renders_Inline.verified.html b/src/AspNetCore.Utilities.Bootstrap5TagHelpers.Tests/VerifySnapshots/FormCheckboxTagHelperTests.Renders_Inline.verified.html new file mode 100644 index 0000000..87f5351 --- /dev/null +++ b/src/AspNetCore.Utilities.Bootstrap5TagHelpers.Tests/VerifySnapshots/FormCheckboxTagHelperTests.Renders_Inline.verified.html @@ -0,0 +1,7 @@ + +
+ + + + +
\ No newline at end of file diff --git a/src/AspNetCore.Utilities.Bootstrap5TagHelpers.Tests/VerifySnapshots/FormCheckboxTagHelperTests.Renders_InlineSwitch.verified.html b/src/AspNetCore.Utilities.Bootstrap5TagHelpers.Tests/VerifySnapshots/FormCheckboxTagHelperTests.Renders_InlineSwitch.verified.html new file mode 100644 index 0000000..3209756 --- /dev/null +++ b/src/AspNetCore.Utilities.Bootstrap5TagHelpers.Tests/VerifySnapshots/FormCheckboxTagHelperTests.Renders_InlineSwitch.verified.html @@ -0,0 +1,7 @@ + +
+ + + + +
\ No newline at end of file diff --git a/src/AspNetCore.Utilities.Bootstrap5TagHelpers.Tests/VerifySnapshots/FormCheckboxTagHelperTests.Renders_Switch.verified.html b/src/AspNetCore.Utilities.Bootstrap5TagHelpers.Tests/VerifySnapshots/FormCheckboxTagHelperTests.Renders_Switch.verified.html new file mode 100644 index 0000000..47044f3 --- /dev/null +++ b/src/AspNetCore.Utilities.Bootstrap5TagHelpers.Tests/VerifySnapshots/FormCheckboxTagHelperTests.Renders_Switch.verified.html @@ -0,0 +1,7 @@ + +
+ + + + +
\ No newline at end of file diff --git a/src/AspNetCore.Utilities.Bootstrap5TagHelpers/Form/FormCheckboxTagHelper.cs b/src/AspNetCore.Utilities.Bootstrap5TagHelpers/Form/FormCheckboxTagHelper.cs index 76e0063..f11646e 100644 --- a/src/AspNetCore.Utilities.Bootstrap5TagHelpers/Form/FormCheckboxTagHelper.cs +++ b/src/AspNetCore.Utilities.Bootstrap5TagHelpers/Form/FormCheckboxTagHelper.cs @@ -32,6 +32,11 @@ public class FormCheckboxTagHelper : InputTagHelper, IFormElementMixin /// public bool IsSwitch { get; set; } = false; + /// + /// Controls if this should be rendered inline + /// + public bool IsInline { get; set; } = false; + /// /// Public constructor that will receive the incoming generator to leverage existing Microsoft Tag Helpers @@ -70,6 +75,10 @@ public override void Process(TagHelperContext context, TagHelperOutput output) groupClass += " form-switch"; output.Attributes.Add("role", "switch"); } + if (IsInline) + { + groupClass += " form-check-inline"; + } this.StartFormGroup(output, groupClass); //Generate our label if not inline