Skip to content

Commit

Permalink
Update to govuk-frontend 4.4.1 (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
gunndabad authored Jul 10, 2023
1 parent 4df77f2 commit 7fad79e
Show file tree
Hide file tree
Showing 32 changed files with 390 additions and 132 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
![ci](https://github.com/gunndabad/govuk-frontend-aspnetcore/workflows/ci/badge.svg)
![Nuget (with prereleases)](https://img.shields.io/nuget/vpre/GovUk.Frontend.AspNetCore)

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

## Installation

Expand Down
6 changes: 6 additions & 0 deletions docs/components/accordion.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@
| --- | --- | --- |
| `id` | `string` | *Required* The `id` attribute for the accordion. Must be unique across the domain of your service. Cannot be `null` or empty. |
| `heading-level` | `int` | The heading level. Must be between `1` and `6` (inclusive). The default is `2`. |
| `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. |
| `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. |
| `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'. |
| `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. |
| `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. |
| `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'. |

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

Expand Down
2 changes: 1 addition & 1 deletion lib/govuk-frontend
Submodule govuk-frontend updated 354 files
2 changes: 1 addition & 1 deletion src/GovUk.Frontend.AspNetCore/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ namespace GovUk.Frontend.AspNetCore
internal static class Constants
{
public const string IdAttributeDotReplacement = "_";
public const string GdsLibraryVersion = "4.3.0";
public const string GdsLibraryVersion = "4.4.1";
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using GovUk.Frontend.AspNetCore.HtmlGeneration;
using GovUk.Frontend.AspNetCore.ModelBinding;
using GovUk.Frontend.AspNetCore.TagHelpers;
using Microsoft.AspNetCore.Http;
Expand Down Expand Up @@ -41,10 +40,7 @@ public GovUkFrontendAspNetCoreOptions()
/// <summary>
/// The default value for <see cref="ButtonTagHelper.PreventDoubleClick"/>.
/// </summary>
/// <remarks>
/// The default is <c>false</c>.
/// </remarks>
public bool DefaultButtonPreventDoubleClick { get; set; } = ComponentGenerator.ButtonDefaultPreventDoubleClick;
public bool? DefaultButtonPreventDoubleClick { get; set; }

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

/// <summary>
/// Whether to prepend 'Error: ' to the &lt;title&gt; element when ModelState is not valid.
/// Whether to prepend &quot;Error: &quot; to the &lt;title&gt; element when ModelState is not valid.
/// </summary>
/// <remarks>
/// The default is <c>true</c>.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.ViewFeatures;

Expand All @@ -19,6 +20,12 @@ public TagBuilder GenerateAccordion(
string id,
int headingLevel,
AttributeDictionary? attributes,
string? hideAllSectionsText,
string? hideSectionText,
string? hideSectionAriaLabelText,
string? showAllSectionsText,
string? showSectionText,
string? showSectionAriaLabelText,
IEnumerable<AccordionItem> items)
{
Guard.ArgumentNotNullOrEmpty(nameof(id), id);
Expand All @@ -38,6 +45,36 @@ public TagBuilder GenerateAccordion(
tagBuilder.Attributes.Add("data-module", "govuk-accordion");
tagBuilder.Attributes.Add("id", id);

if (hideAllSectionsText is not null)
{
tagBuilder.Attributes.Add("data-i18n.hide-all-sections", hideAllSectionsText);
}

if (hideSectionText is not null)
{
tagBuilder.Attributes.Add("data-i18n.hide-section", hideSectionText);
}

if (hideSectionAriaLabelText is not null)
{
tagBuilder.Attributes.Add("data-i18n.hide-section-aria-label", hideSectionAriaLabelText);
}

if (showAllSectionsText is not null)
{
tagBuilder.Attributes.Add("data-i18n.show-all-sections", showAllSectionsText);
}

if (showSectionText is not null)
{
tagBuilder.Attributes.Add("data-i18n.show-section", showSectionText);
}

if (showSectionAriaLabelText is not null)
{
tagBuilder.Attributes.Add("data-i18n.show-section-aria-label", showSectionAriaLabelText);
}

var index = 0;
foreach (var item in items)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ internal partial class ComponentGenerator
{
internal const bool ButtonDefaultDisabled = false;
internal const bool ButtonDefaultIsStartButton = false;
internal const bool ButtonDefaultPreventDoubleClick = false;
internal const string ButtonElement = "button";
internal const string ButtonLinkElement = "a";

public TagBuilder GenerateButton(
bool isStartButton,
bool disabled,
bool preventDoubleClick,
bool? preventDoubleClick,
IHtmlContent content,
AttributeDictionary? attributes)
{
Expand All @@ -34,9 +33,9 @@ public TagBuilder GenerateButton(
tagBuilder.Attributes.Add("aria-disabled", "true");
}

if (preventDoubleClick)
if (preventDoubleClick.HasValue)
{
tagBuilder.Attributes.Add("data-prevent-double-click", "true");
tagBuilder.Attributes.Add("data-prevent-double-click", preventDoubleClick.Value ? "true" : "false");
}

tagBuilder.InnerHtml.AppendHtml(content);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,20 @@ public TagBuilder GenerateCharacterCount(
int? maxWords,
decimal? threshold,
IHtmlContent formGroup,
AttributeDictionary? countMessageAttributes)
AttributeDictionary? countMessageAttributes,
string? textAreaDescriptionText,
(string Other, string One)? charactersUnderLimitText,
string? charactersAtLimitText,
(string Other, string One)? charactersOverLimitText,
(string Other, string One)? wordsUnderLimitText,
string? wordsAtLimitText,
(string Other, string One)? wordsOverLimitText)
{
Guard.ArgumentNotNull(nameof(textAreaId), textAreaId);
Guard.ArgumentNotNull(nameof(formGroup), formGroup);

var hasNoLimit = maxLength is null && maxWords is null;

var tagBuilder = new TagBuilder(CharacterCountElement);
tagBuilder.MergeCssClass("govuk-character-count");
tagBuilder.Attributes.Add("data-module", "govuk-character-count");
Expand All @@ -39,6 +48,53 @@ public TagBuilder GenerateCharacterCount(
tagBuilder.Attributes.Add("data-maxwords", maxWords.Value.ToString());
}

if (hasNoLimit && textAreaDescriptionText is not null)
{
tagBuilder.AddPluralisedI18nAttributes("textarea-description", "other", textAreaDescriptionText);
}

if (charactersUnderLimitText is not null)
{
tagBuilder.AddPluralisedI18nAttributes(
"characters-under-limit",
("other", charactersUnderLimitText!.Value.Other),
("one", charactersUnderLimitText.Value!.One));
}

if (charactersAtLimitText is not null)
{
tagBuilder.Attributes.Add("data-i18n.characters-at-limit", charactersAtLimitText);
}

if (charactersOverLimitText is not null)
{
tagBuilder.AddPluralisedI18nAttributes(
"characters-over-limit",
("other", charactersOverLimitText!.Value.Other),
("one", charactersOverLimitText.Value!.One));
}

if (wordsUnderLimitText is not null)
{
tagBuilder.AddPluralisedI18nAttributes(
"words-under-limit",
("other", wordsUnderLimitText!.Value.Other),
("one", wordsUnderLimitText.Value!.One));
}

if (wordsAtLimitText is not null)
{
tagBuilder.Attributes.Add("data-i18n.words-at-limit", wordsAtLimitText);
}

if (wordsOverLimitText is not null)
{
tagBuilder.AddPluralisedI18nAttributes(
"words-over-limit",
("other", wordsOverLimitText!.Value.Other),
("one", wordsOverLimitText.Value!.One));
}

tagBuilder.InnerHtml.AppendHtml(formGroup);
tagBuilder.InnerHtml.AppendHtml(GenerateHint());

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

var content = maxWords.HasValue ?
$"You can enter up to {maxWords} words" :
$"You can enter up to {maxLength} characters";
var content = hasNoLimit ? "" :
(textAreaDescriptionText ?? $"You can enter up to %{{count}} {(maxWords.HasValue ? "words" : "characters")}")
.Replace("%{count}", (maxWords.HasValue ? maxWords : maxLength).ToString());

var hintContent = new HtmlString(HtmlEncoder.Default.Encode(content));

var attributes = countMessageAttributes.ToAttributeDictionary();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ namespace GovUk.Frontend.AspNetCore.HtmlGeneration
internal partial class ComponentGenerator
{
internal const string ErrorSummaryDefaultTitle = "There is a problem";
internal const bool ErrorSummaryDefaultDisableAutoFocus = false;
internal const string ErrorSummaryElement = "div";

public TagBuilder GenerateErrorSummary(
bool disableAutoFocus,
bool? disableAutoFocus,
IHtmlContent titleContent,
AttributeDictionary titleAttributes,
IHtmlContent descriptionContent,
Expand All @@ -25,21 +24,21 @@ public TagBuilder GenerateErrorSummary(
var tagBuilder = new TagBuilder(ErrorSummaryElement);
tagBuilder.MergeAttributes(attributes);
tagBuilder.MergeCssClass("govuk-error-summary");
tagBuilder.Attributes.Add("aria-labelledby", "error-summary-title");
tagBuilder.Attributes.Add("role", "alert");
tagBuilder.Attributes.Add("data-module", "govuk-error-summary");

if (disableAutoFocus)
if (disableAutoFocus.HasValue)
{
tagBuilder.Attributes.Add("data-disable-auto-focus", "true");
tagBuilder.Attributes.Add("data-disable-auto-focus", disableAutoFocus.Value ? "true" : "false");
}

var alert = new TagBuilder("div");
alert.Attributes.Add("role", "alert");

var heading = new TagBuilder("h2");
heading.MergeAttributes(titleAttributes);
heading.MergeCssClass("govuk-error-summary__title");
heading.Attributes.Add("id", "error-summary-title");
heading.InnerHtml.AppendHtml(titleContent);
tagBuilder.InnerHtml.AppendHtml(heading);
alert.InnerHtml.AppendHtml(heading);

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

body.InnerHtml.AppendHtml(ul);

tagBuilder.InnerHtml.AppendHtml(body);
alert.InnerHtml.AppendHtml(body);

tagBuilder.InnerHtml.AppendHtml(alert);

return tagBuilder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ namespace GovUk.Frontend.AspNetCore.HtmlGeneration
{
internal partial class ComponentGenerator
{
internal const bool NotificationBannerDefaultDisableAutoFocus = false;
internal const string NotificationBannerDefaultRole = "region";
internal const string NotificationBannerDefaultSuccessRole = "alert";
internal const string NotificationBannerDefaultSuccessTitle = "Success";
Expand All @@ -23,7 +22,7 @@ internal partial class ComponentGenerator
public TagBuilder GenerateNotificationBanner(
NotificationBannerType type,
string? role,
bool disableAutoFocus,
bool? disableAutoFocus,
string? titleId,
int? titleHeadingLevel,
IHtmlContent? titleContent,
Expand Down Expand Up @@ -64,9 +63,9 @@ public TagBuilder GenerateNotificationBanner(
tagBuilder.Attributes.Add("role", role);
tagBuilder.Attributes.Add("aria-labelledby", titleId);

if (disableAutoFocus)
if (disableAutoFocus.HasValue)
{
tagBuilder.Attributes.Add("data-disable-auto-focus", "true");
tagBuilder.Attributes.Add("data-disable-auto-focus", disableAutoFocus.Value ? "true" : "false");
}

tagBuilder.InnerHtml.AppendHtml(GenerateHeading());
Expand Down
21 changes: 17 additions & 4 deletions src/GovUk.Frontend.AspNetCore/IGovUkHtmlGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ TagBuilder GenerateAccordion(
string id,
int headingLevel,
AttributeDictionary attributes,
string hideAllSectionsText,
string hideSectionText,
string hideSectionAriaLabelText,
string showAllSectionsText,
string showSectionText,
string showSectionAriaLabelText,
IEnumerable<AccordionItem> items);

TagBuilder GenerateBackLink(IHtmlContent content, AttributeDictionary attributes);
Expand All @@ -25,7 +31,7 @@ TagBuilder GenerateBreadcrumbs(
TagBuilder GenerateButton(
bool isStartButton,
bool disabled,
bool preventDoubleClick,
bool? preventDoubleClick,
IHtmlContent content,
AttributeDictionary attributes);

Expand All @@ -41,7 +47,14 @@ TagBuilder GenerateCharacterCount(
int? maxWords,
decimal? threshold,
IHtmlContent formGroup,
AttributeDictionary countMessageAttributes);
AttributeDictionary countMessageAttributes,
string textAreaDescriptionText,
(string Other, string One)? charactersUnderLimitText,
string charactersAtLimitText,
(string Other, string One)? charactersOverLimitText,
(string Other, string One)? wordsUnderLimitText,
string wordsAtLimitText,
(string Other, string One)? wordsOverLimitText);

TagBuilder GenerateCheckboxes(
string idPrefix,
Expand Down Expand Up @@ -73,7 +86,7 @@ TagBuilder GenerateErrorMessage(
AttributeDictionary attributes);

TagBuilder GenerateErrorSummary(
bool disableAutofocus,
bool? disableAutofocus,
IHtmlContent titleContent,
AttributeDictionary titleAttributes,
IHtmlContent descriptionContent,
Expand Down Expand Up @@ -112,7 +125,7 @@ TagBuilder GenerateLabel(
TagBuilder GenerateNotificationBanner(
NotificationBannerType type,
string role,
bool disableAutoFocus,
bool? disableAutoFocus,
string titleId,
int? titleHeadingLevel,
IHtmlContent titleContent,
Expand Down
6 changes: 3 additions & 3 deletions src/GovUk.Frontend.AspNetCore/PageTemplateHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public IHtmlContent GenerateScriptImports(string? cspNonce = null)
TagBuilder GenerateImportScript()
{
var tagBuilder = new TagBuilder("script");
tagBuilder.MergeAttribute("src", "/govuk-frontend-4.3.0.min.js");
tagBuilder.MergeAttribute("src", "/govuk-frontend-4.4.1.min.js");
return tagBuilder;
}

Expand All @@ -91,10 +91,10 @@ TagBuilder GenerateInitScript()
/// </remarks>
/// <returns><see cref="IHtmlContent"/> containing the <c>link</c> tags.</returns>
public IHtmlContent GenerateStyleImports() => new HtmlString(@"<!--[if !IE 8]><!-->
<link rel=""stylesheet"" href=""/govuk-frontend-4.3.0.min.css"">
<link rel=""stylesheet"" href=""/govuk-frontend-4.4.1.min.css"">
<!--<![endif]-->
<!--[if IE 8]>
<link rel = ""stylesheet"" href=""/govuk-frontend-ie8-4.2.0.min.css"">
<link rel = ""stylesheet"" href=""/govuk-frontend-ie8-4.4.1.min.css"">
<![endif]-->");

/// <summary>
Expand Down
Loading

0 comments on commit 7fad79e

Please sign in to comment.