Skip to content

Commit 7fad79e

Browse files
authored
Update to govuk-frontend 4.4.1 (#262)
1 parent 4df77f2 commit 7fad79e

32 files changed

+390
-132
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
![ci](https://github.com/gunndabad/govuk-frontend-aspnetcore/workflows/ci/badge.svg)
44
![Nuget (with prereleases)](https://img.shields.io/nuget/vpre/GovUk.Frontend.AspNetCore)
55

6-
Targets [GDS Frontend v4.3.0](https://github.com/alphagov/govuk-frontend/releases/tag/v4.3.0)
6+
Targets [GDS Frontend v4.4.1](https://github.com/alphagov/govuk-frontend/releases/tag/v4.4.1)
77

88
## Installation
99

docs/components/accordion.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@
114114
| --- | --- | --- |
115115
| `id` | `string` | *Required* The `id` attribute for the accordion. Must be unique across the domain of your service. Cannot be `null` or empty. |
116116
| `heading-level` | `int` | The heading level. Must be between `1` and `6` (inclusive). The default is `2`. |
117+
| `hide-all-sections-text` | `string` | The text content of the 'Hide all sections' button at the top of the accordion when all sections are expanded. |
118+
| `hide-section-text` | `string` | The text content of the 'Hide' button within each section of the accordion, which is visible when the section is expanded. |
119+
| `hide-section-aria-label-text` | `string` | The text made available to assistive technologies, like screen-readers, as the final part of the toggle's accessible name when the section is expanded. Defaults to 'Hide this section'. |
120+
| `show-all-sections-text` | `string` | The text content of the 'Show all sections' button at the top of the accordion when at least one section is collapsed. |
121+
| `show-section-text` | `string` | The text content of the 'Show' button within each section of the accordion, which is visible when the section is collapsed. |
122+
| `hide-section-aria-label-text` | `string` | The text made available to assistive technologies, like screen-readers, as the final part of the toggle's accessible name when the section is collapsed. Defaults to 'Show this section'. |
117123

118124
### `<govuk-accordion-item>`
119125

lib/govuk-frontend

Submodule govuk-frontend updated 354 files

src/GovUk.Frontend.AspNetCore/Constants.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ namespace GovUk.Frontend.AspNetCore
33
internal static class Constants
44
{
55
public const string IdAttributeDotReplacement = "_";
6-
public const string GdsLibraryVersion = "4.3.0";
6+
public const string GdsLibraryVersion = "4.4.1";
77
}
88
}

src/GovUk.Frontend.AspNetCore/GovUkFrontendAspNetCoreOptions.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using GovUk.Frontend.AspNetCore.HtmlGeneration;
43
using GovUk.Frontend.AspNetCore.ModelBinding;
54
using GovUk.Frontend.AspNetCore.TagHelpers;
65
using Microsoft.AspNetCore.Http;
@@ -41,10 +40,7 @@ public GovUkFrontendAspNetCoreOptions()
4140
/// <summary>
4241
/// The default value for <see cref="ButtonTagHelper.PreventDoubleClick"/>.
4342
/// </summary>
44-
/// <remarks>
45-
/// The default is <c>false</c>.
46-
/// </remarks>
47-
public bool DefaultButtonPreventDoubleClick { get; set; } = ComponentGenerator.ButtonDefaultPreventDoubleClick;
43+
public bool? DefaultButtonPreventDoubleClick { get; set; }
4844

4945
/// <summary>
5046
/// A delegate for retrieving a CSP nonce for the current request.
@@ -69,7 +65,7 @@ public GovUkFrontendAspNetCoreOptions()
6965
public bool PrependErrorSummaryToForms { get; set; }
7066

7167
/// <summary>
72-
/// Whether to prepend 'Error: ' to the &lt;title&gt; element when ModelState is not valid.
68+
/// Whether to prepend &quot;Error: &quot; to the &lt;title&gt; element when ModelState is not valid.
7369
/// </summary>
7470
/// <remarks>
7571
/// The default is <c>true</c>.

src/GovUk.Frontend.AspNetCore/HtmlGeneration/ComponentGenerator.Accordion.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using Microsoft.AspNetCore.Html;
34
using Microsoft.AspNetCore.Mvc.Rendering;
45
using Microsoft.AspNetCore.Mvc.ViewFeatures;
56

@@ -19,6 +20,12 @@ public TagBuilder GenerateAccordion(
1920
string id,
2021
int headingLevel,
2122
AttributeDictionary? attributes,
23+
string? hideAllSectionsText,
24+
string? hideSectionText,
25+
string? hideSectionAriaLabelText,
26+
string? showAllSectionsText,
27+
string? showSectionText,
28+
string? showSectionAriaLabelText,
2229
IEnumerable<AccordionItem> items)
2330
{
2431
Guard.ArgumentNotNullOrEmpty(nameof(id), id);
@@ -38,6 +45,36 @@ public TagBuilder GenerateAccordion(
3845
tagBuilder.Attributes.Add("data-module", "govuk-accordion");
3946
tagBuilder.Attributes.Add("id", id);
4047

48+
if (hideAllSectionsText is not null)
49+
{
50+
tagBuilder.Attributes.Add("data-i18n.hide-all-sections", hideAllSectionsText);
51+
}
52+
53+
if (hideSectionText is not null)
54+
{
55+
tagBuilder.Attributes.Add("data-i18n.hide-section", hideSectionText);
56+
}
57+
58+
if (hideSectionAriaLabelText is not null)
59+
{
60+
tagBuilder.Attributes.Add("data-i18n.hide-section-aria-label", hideSectionAriaLabelText);
61+
}
62+
63+
if (showAllSectionsText is not null)
64+
{
65+
tagBuilder.Attributes.Add("data-i18n.show-all-sections", showAllSectionsText);
66+
}
67+
68+
if (showSectionText is not null)
69+
{
70+
tagBuilder.Attributes.Add("data-i18n.show-section", showSectionText);
71+
}
72+
73+
if (showSectionAriaLabelText is not null)
74+
{
75+
tagBuilder.Attributes.Add("data-i18n.show-section-aria-label", showSectionAriaLabelText);
76+
}
77+
4178
var index = 0;
4279
foreach (var item in items)
4380
{

src/GovUk.Frontend.AspNetCore/HtmlGeneration/ComponentGenerator.Button.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@ internal partial class ComponentGenerator
99
{
1010
internal const bool ButtonDefaultDisabled = false;
1111
internal const bool ButtonDefaultIsStartButton = false;
12-
internal const bool ButtonDefaultPreventDoubleClick = false;
1312
internal const string ButtonElement = "button";
1413
internal const string ButtonLinkElement = "a";
1514

1615
public TagBuilder GenerateButton(
1716
bool isStartButton,
1817
bool disabled,
19-
bool preventDoubleClick,
18+
bool? preventDoubleClick,
2019
IHtmlContent content,
2120
AttributeDictionary? attributes)
2221
{
@@ -34,9 +33,9 @@ public TagBuilder GenerateButton(
3433
tagBuilder.Attributes.Add("aria-disabled", "true");
3534
}
3635

37-
if (preventDoubleClick)
36+
if (preventDoubleClick.HasValue)
3837
{
39-
tagBuilder.Attributes.Add("data-prevent-double-click", "true");
38+
tagBuilder.Attributes.Add("data-prevent-double-click", preventDoubleClick.Value ? "true" : "false");
4039
}
4140

4241
tagBuilder.InnerHtml.AppendHtml(content);

src/GovUk.Frontend.AspNetCore/HtmlGeneration/ComponentGenerator.CharacterCount.cs

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,20 @@ public TagBuilder GenerateCharacterCount(
1515
int? maxWords,
1616
decimal? threshold,
1717
IHtmlContent formGroup,
18-
AttributeDictionary? countMessageAttributes)
18+
AttributeDictionary? countMessageAttributes,
19+
string? textAreaDescriptionText,
20+
(string Other, string One)? charactersUnderLimitText,
21+
string? charactersAtLimitText,
22+
(string Other, string One)? charactersOverLimitText,
23+
(string Other, string One)? wordsUnderLimitText,
24+
string? wordsAtLimitText,
25+
(string Other, string One)? wordsOverLimitText)
1926
{
2027
Guard.ArgumentNotNull(nameof(textAreaId), textAreaId);
2128
Guard.ArgumentNotNull(nameof(formGroup), formGroup);
2229

30+
var hasNoLimit = maxLength is null && maxWords is null;
31+
2332
var tagBuilder = new TagBuilder(CharacterCountElement);
2433
tagBuilder.MergeCssClass("govuk-character-count");
2534
tagBuilder.Attributes.Add("data-module", "govuk-character-count");
@@ -39,6 +48,53 @@ public TagBuilder GenerateCharacterCount(
3948
tagBuilder.Attributes.Add("data-maxwords", maxWords.Value.ToString());
4049
}
4150

51+
if (hasNoLimit && textAreaDescriptionText is not null)
52+
{
53+
tagBuilder.AddPluralisedI18nAttributes("textarea-description", "other", textAreaDescriptionText);
54+
}
55+
56+
if (charactersUnderLimitText is not null)
57+
{
58+
tagBuilder.AddPluralisedI18nAttributes(
59+
"characters-under-limit",
60+
("other", charactersUnderLimitText!.Value.Other),
61+
("one", charactersUnderLimitText.Value!.One));
62+
}
63+
64+
if (charactersAtLimitText is not null)
65+
{
66+
tagBuilder.Attributes.Add("data-i18n.characters-at-limit", charactersAtLimitText);
67+
}
68+
69+
if (charactersOverLimitText is not null)
70+
{
71+
tagBuilder.AddPluralisedI18nAttributes(
72+
"characters-over-limit",
73+
("other", charactersOverLimitText!.Value.Other),
74+
("one", charactersOverLimitText.Value!.One));
75+
}
76+
77+
if (wordsUnderLimitText is not null)
78+
{
79+
tagBuilder.AddPluralisedI18nAttributes(
80+
"words-under-limit",
81+
("other", wordsUnderLimitText!.Value.Other),
82+
("one", wordsUnderLimitText.Value!.One));
83+
}
84+
85+
if (wordsAtLimitText is not null)
86+
{
87+
tagBuilder.Attributes.Add("data-i18n.words-at-limit", wordsAtLimitText);
88+
}
89+
90+
if (wordsOverLimitText is not null)
91+
{
92+
tagBuilder.AddPluralisedI18nAttributes(
93+
"words-over-limit",
94+
("other", wordsOverLimitText!.Value.Other),
95+
("one", wordsOverLimitText.Value!.One));
96+
}
97+
4298
tagBuilder.InnerHtml.AppendHtml(formGroup);
4399
tagBuilder.InnerHtml.AppendHtml(GenerateHint());
44100

@@ -48,9 +104,10 @@ IHtmlContent GenerateHint()
48104
{
49105
var hintId = $"{textAreaId}-info";
50106

51-
var content = maxWords.HasValue ?
52-
$"You can enter up to {maxWords} words" :
53-
$"You can enter up to {maxLength} characters";
107+
var content = hasNoLimit ? "" :
108+
(textAreaDescriptionText ?? $"You can enter up to %{{count}} {(maxWords.HasValue ? "words" : "characters")}")
109+
.Replace("%{count}", (maxWords.HasValue ? maxWords : maxLength).ToString());
110+
54111
var hintContent = new HtmlString(HtmlEncoder.Default.Encode(content));
55112

56113
var attributes = countMessageAttributes.ToAttributeDictionary();

src/GovUk.Frontend.AspNetCore/HtmlGeneration/ComponentGenerator.ErrorSummary.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ namespace GovUk.Frontend.AspNetCore.HtmlGeneration
88
internal partial class ComponentGenerator
99
{
1010
internal const string ErrorSummaryDefaultTitle = "There is a problem";
11-
internal const bool ErrorSummaryDefaultDisableAutoFocus = false;
1211
internal const string ErrorSummaryElement = "div";
1312

1413
public TagBuilder GenerateErrorSummary(
15-
bool disableAutoFocus,
14+
bool? disableAutoFocus,
1615
IHtmlContent titleContent,
1716
AttributeDictionary titleAttributes,
1817
IHtmlContent descriptionContent,
@@ -25,21 +24,21 @@ public TagBuilder GenerateErrorSummary(
2524
var tagBuilder = new TagBuilder(ErrorSummaryElement);
2625
tagBuilder.MergeAttributes(attributes);
2726
tagBuilder.MergeCssClass("govuk-error-summary");
28-
tagBuilder.Attributes.Add("aria-labelledby", "error-summary-title");
29-
tagBuilder.Attributes.Add("role", "alert");
3027
tagBuilder.Attributes.Add("data-module", "govuk-error-summary");
3128

32-
if (disableAutoFocus)
29+
if (disableAutoFocus.HasValue)
3330
{
34-
tagBuilder.Attributes.Add("data-disable-auto-focus", "true");
31+
tagBuilder.Attributes.Add("data-disable-auto-focus", disableAutoFocus.Value ? "true" : "false");
3532
}
3633

34+
var alert = new TagBuilder("div");
35+
alert.Attributes.Add("role", "alert");
36+
3737
var heading = new TagBuilder("h2");
3838
heading.MergeAttributes(titleAttributes);
3939
heading.MergeCssClass("govuk-error-summary__title");
40-
heading.Attributes.Add("id", "error-summary-title");
4140
heading.InnerHtml.AppendHtml(titleContent);
42-
tagBuilder.InnerHtml.AppendHtml(heading);
41+
alert.InnerHtml.AppendHtml(heading);
4342

4443
var body = new TagBuilder("div");
4544
body.MergeCssClass("govuk-error-summary__body");
@@ -89,7 +88,9 @@ public TagBuilder GenerateErrorSummary(
8988

9089
body.InnerHtml.AppendHtml(ul);
9190

92-
tagBuilder.InnerHtml.AppendHtml(body);
91+
alert.InnerHtml.AppendHtml(body);
92+
93+
tagBuilder.InnerHtml.AppendHtml(alert);
9394

9495
return tagBuilder;
9596
}

src/GovUk.Frontend.AspNetCore/HtmlGeneration/ComponentGenerator.NotificationBanner.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ namespace GovUk.Frontend.AspNetCore.HtmlGeneration
88
{
99
internal partial class ComponentGenerator
1010
{
11-
internal const bool NotificationBannerDefaultDisableAutoFocus = false;
1211
internal const string NotificationBannerDefaultRole = "region";
1312
internal const string NotificationBannerDefaultSuccessRole = "alert";
1413
internal const string NotificationBannerDefaultSuccessTitle = "Success";
@@ -23,7 +22,7 @@ internal partial class ComponentGenerator
2322
public TagBuilder GenerateNotificationBanner(
2423
NotificationBannerType type,
2524
string? role,
26-
bool disableAutoFocus,
25+
bool? disableAutoFocus,
2726
string? titleId,
2827
int? titleHeadingLevel,
2928
IHtmlContent? titleContent,
@@ -64,9 +63,9 @@ public TagBuilder GenerateNotificationBanner(
6463
tagBuilder.Attributes.Add("role", role);
6564
tagBuilder.Attributes.Add("aria-labelledby", titleId);
6665

67-
if (disableAutoFocus)
66+
if (disableAutoFocus.HasValue)
6867
{
69-
tagBuilder.Attributes.Add("data-disable-auto-focus", "true");
68+
tagBuilder.Attributes.Add("data-disable-auto-focus", disableAutoFocus.Value ? "true" : "false");
7069
}
7170

7271
tagBuilder.InnerHtml.AppendHtml(GenerateHeading());

0 commit comments

Comments
 (0)