From f5123d051d840b100f0c9fc1c90b3e7eab7b9d54 Mon Sep 17 00:00:00 2001 From: James Gunn Date: Tue, 14 Jan 2025 17:12:59 +0000 Subject: [PATCH] Deprecate stand-alone error message and fieldset tag helpers (#306) --- CHANGELOG.md | 3 +++ .../GovUk.Frontend.AspNetCore.DocSamples.csproj | 1 + .../TagHelpers/ErrorMessageTagHelper.cs | 1 + src/GovUk.Frontend.AspNetCore/TagHelpers/FieldsetContext.cs | 4 ++++ .../TagHelpers/FieldsetLegendTagHelper.cs | 2 ++ src/GovUk.Frontend.AspNetCore/TagHelpers/FieldsetTagHelper.cs | 2 ++ .../TagHelpers/ErrorMessageTagHelperTests.cs | 1 + .../TagHelpers/FieldsetLegendTagHelperTests.cs | 1 + .../TagHelpers/FieldsetTagHelperTests.cs | 1 + 9 files changed, 16 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index abfe0a77..71202e0d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ #### `asp-for` attributes The `asp-for` attribute is now obsolete; the `for` attribute should be used in its place. +#### `` and `` tag helpers +The `` and `` tag helpers are deprecated and will be removed in a future release. + ## 2.8.0 Targets GOV.UK Frontend v5.8.0. diff --git a/src/GovUk.Frontend.AspNetCore.DocSamples/GovUk.Frontend.AspNetCore.DocSamples.csproj b/src/GovUk.Frontend.AspNetCore.DocSamples/GovUk.Frontend.AspNetCore.DocSamples.csproj index c54a73d3..1f0241d3 100644 --- a/src/GovUk.Frontend.AspNetCore.DocSamples/GovUk.Frontend.AspNetCore.DocSamples.csproj +++ b/src/GovUk.Frontend.AspNetCore.DocSamples/GovUk.Frontend.AspNetCore.DocSamples.csproj @@ -2,6 +2,7 @@ net8.0 + CS0618 diff --git a/src/GovUk.Frontend.AspNetCore/TagHelpers/ErrorMessageTagHelper.cs b/src/GovUk.Frontend.AspNetCore/TagHelpers/ErrorMessageTagHelper.cs index a9eb909e..bd4019ec 100644 --- a/src/GovUk.Frontend.AspNetCore/TagHelpers/ErrorMessageTagHelper.cs +++ b/src/GovUk.Frontend.AspNetCore/TagHelpers/ErrorMessageTagHelper.cs @@ -17,6 +17,7 @@ namespace GovUk.Frontend.AspNetCore.TagHelpers; /// [HtmlTargetElement(TagName)] [OutputElementHint(ComponentGenerator.ErrorMessageElement)] +[Obsolete("This tag helper will be removed in a future release.")] public class ErrorMessageTagHelper : TagHelper { internal const string TagName = "govuk-error-message"; diff --git a/src/GovUk.Frontend.AspNetCore/TagHelpers/FieldsetContext.cs b/src/GovUk.Frontend.AspNetCore/TagHelpers/FieldsetContext.cs index ac18ca4c..063c5e40 100644 --- a/src/GovUk.Frontend.AspNetCore/TagHelpers/FieldsetContext.cs +++ b/src/GovUk.Frontend.AspNetCore/TagHelpers/FieldsetContext.cs @@ -16,9 +16,11 @@ public void SetLegend( if (Legend != null) { +#pragma warning disable CS0618 // Type or member is obsolete throw ExceptionHelper.OnlyOneElementIsPermittedIn( FieldsetLegendTagHelper.TagName, FieldsetTagHelper.TagName); +#pragma warning restore CS0618 // Type or member is obsolete } Legend = (isPageHeading, attributes, content); @@ -28,7 +30,9 @@ public void ThrowIfNotComplete() { if (Legend == null) { +#pragma warning disable CS0618 // Type or member is obsolete throw ExceptionHelper.AChildElementMustBeProvided(FieldsetLegendTagHelper.TagName); +#pragma warning restore CS0618 // Type or member is obsolete } } } diff --git a/src/GovUk.Frontend.AspNetCore/TagHelpers/FieldsetLegendTagHelper.cs b/src/GovUk.Frontend.AspNetCore/TagHelpers/FieldsetLegendTagHelper.cs index a085576c..687ec0c6 100644 --- a/src/GovUk.Frontend.AspNetCore/TagHelpers/FieldsetLegendTagHelper.cs +++ b/src/GovUk.Frontend.AspNetCore/TagHelpers/FieldsetLegendTagHelper.cs @@ -1,3 +1,4 @@ +using System; using System.Threading.Tasks; using GovUk.Frontend.AspNetCore.HtmlGeneration; using Microsoft.AspNetCore.Razor.TagHelpers; @@ -9,6 +10,7 @@ namespace GovUk.Frontend.AspNetCore.TagHelpers; /// [HtmlTargetElement(TagName, ParentTag = FieldsetTagHelper.TagName)] [OutputElementHint(ComponentGenerator.FieldsetLegendElement)] +[Obsolete("This tag helper will be removed in a future release.")] public class FieldsetLegendTagHelper : TagHelper { internal const string TagName = "govuk-fieldset-legend"; diff --git a/src/GovUk.Frontend.AspNetCore/TagHelpers/FieldsetTagHelper.cs b/src/GovUk.Frontend.AspNetCore/TagHelpers/FieldsetTagHelper.cs index 6726882a..6a9e2936 100644 --- a/src/GovUk.Frontend.AspNetCore/TagHelpers/FieldsetTagHelper.cs +++ b/src/GovUk.Frontend.AspNetCore/TagHelpers/FieldsetTagHelper.cs @@ -1,3 +1,4 @@ +using System; using System.Threading.Tasks; using GovUk.Frontend.AspNetCore.HtmlGeneration; using Microsoft.AspNetCore.Html; @@ -11,6 +12,7 @@ namespace GovUk.Frontend.AspNetCore.TagHelpers; /// [HtmlTargetElement(TagName)] [OutputElementHint(ComponentGenerator.FieldsetElement)] +[Obsolete("This tag helper will be removed in a future release.")] public class FieldsetTagHelper : TagHelper { internal const string TagName = "govuk-fieldset"; diff --git a/tests/GovUk.Frontend.AspNetCore.Tests/TagHelpers/ErrorMessageTagHelperTests.cs b/tests/GovUk.Frontend.AspNetCore.Tests/TagHelpers/ErrorMessageTagHelperTests.cs index 505fc34f..40a3928a 100644 --- a/tests/GovUk.Frontend.AspNetCore.Tests/TagHelpers/ErrorMessageTagHelperTests.cs +++ b/tests/GovUk.Frontend.AspNetCore.Tests/TagHelpers/ErrorMessageTagHelperTests.cs @@ -10,6 +10,7 @@ using Microsoft.AspNetCore.Razor.TagHelpers; using Moq; using Xunit; +#pragma warning disable CS0618 // Type or member is obsolete namespace GovUk.Frontend.AspNetCore.Tests.TagHelpers; diff --git a/tests/GovUk.Frontend.AspNetCore.Tests/TagHelpers/FieldsetLegendTagHelperTests.cs b/tests/GovUk.Frontend.AspNetCore.Tests/TagHelpers/FieldsetLegendTagHelperTests.cs index 6e0acd2f..227f0b29 100644 --- a/tests/GovUk.Frontend.AspNetCore.Tests/TagHelpers/FieldsetLegendTagHelperTests.cs +++ b/tests/GovUk.Frontend.AspNetCore.Tests/TagHelpers/FieldsetLegendTagHelperTests.cs @@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Html; using Microsoft.AspNetCore.Razor.TagHelpers; using Xunit; +#pragma warning disable CS0618 // Type or member is obsolete namespace GovUk.Frontend.AspNetCore.Tests.TagHelpers; diff --git a/tests/GovUk.Frontend.AspNetCore.Tests/TagHelpers/FieldsetTagHelperTests.cs b/tests/GovUk.Frontend.AspNetCore.Tests/TagHelpers/FieldsetTagHelperTests.cs index abe2ec5a..94b93e45 100644 --- a/tests/GovUk.Frontend.AspNetCore.Tests/TagHelpers/FieldsetTagHelperTests.cs +++ b/tests/GovUk.Frontend.AspNetCore.Tests/TagHelpers/FieldsetTagHelperTests.cs @@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Html; using Microsoft.AspNetCore.Razor.TagHelpers; using Xunit; +#pragma warning disable CS0618 // Type or member is obsolete namespace GovUk.Frontend.AspNetCore.Tests.TagHelpers;