Skip to content

Commit

Permalink
govuk-frontend 5.9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-shaw committed Mar 5, 2025
1 parent 1298585 commit 4584974
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
{%- set textareaDescriptionLength = params.maxwords or params.maxlength -%}
{%- set textareaDescriptionText = params.textareaDescriptionText or 'You can enter up to %{count} ' ~ ('words' if params.maxwords else 'characters') -%}
{%- set textareaDescriptionTextNoLimit = textareaDescriptionText | replace('%{count}', textareaDescriptionLength) if not hasNoLimit -%}
{%- set id = params.id if params.id else params.name -%}

{%- set countMessageHtml %}
{{ govukHint({
'text': textareaDescriptionTextNoLimit,
'id': params.id ~ '-info',
'id': id ~ '-info',
'classes': 'govuk-character-count__message' ~ (' ' ~ params.countMessage.classes if params.countMessage and params.countMessage.classes)
}) | trim }}
{% if params.formGroup and params.formGroup.afterInput %}
Expand Down Expand Up @@ -94,9 +95,9 @@
{%- endif -%}

{{ govukTextarea({
'id': params.id,
'id': id,
'name': params.name,
'describedBy': params.id ~ '-info',
'describedBy': id ~ '-info',
'rows': params.rows,
'spellcheck': params.spellcheck,
'value': params.value,
Expand All @@ -115,7 +116,7 @@
'classes': params.label.classes,
'isPageHeading': params.label.isPageHeading,
'attributes': params.label.attributes,
'for': params.id
'for': id
},
'hint': params.hint,
'errorMessage': params.errorMessage,
Expand Down
47 changes: 42 additions & 5 deletions govuk_frontend_jinja/templates/components/file-upload/macro.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
{% macro govukFileUpload(params) %}
{% from "govuk_frontend_jinja/macros/attributes.html" import govukAttributes %}
{% from "govuk_frontend_jinja/macros/i18n.html" import govukI18nAttributes %}
{% from "govuk_frontend_jinja/components/error-message/macro.html" import govukErrorMessage %}
{% from "govuk_frontend_jinja/components/hint/macro.html" import govukHint %}
{% from "govuk_frontend_jinja/components/label/macro.html" import govukLabel %}

{#- a record of other elements that we need to associate with the input using
aria-describedby – for example hints or error messages -#}
{% set describedBy = params.describedBy if params.describedBy else "" %}
{%- set describedBy = params.describedBy if params.describedBy else "" -%}
{%- set id = params.id if params.id else params.name -%}

<div class="govuk-form-group {%- if params.errorMessage %} govuk-form-group--error{% endif %} {%- if params.formGroup and params.formGroup.classes %} {{ params.formGroup.classes }}{% endif %}"
{{- govukAttributes(params.formGroup.attributes if params.formGroup) }}>
{{ govukLabel({
Expand All @@ -15,10 +18,10 @@
'classes': params.label.classes,
'isPageHeading': params.label.isPageHeading,
'attributes': params.label.attributes,
'for': params.id
'for': id
}) | trim | indent(2) }}
{% if params.hint %}
{% set hintId = params.id ~ '-hint' %}
{% set hintId = id ~ '-hint' %}
{% set describedBy = describedBy ~ ' ' ~ hintId if describedBy else hintId %}
{{ govukHint({
'id': hintId,
Expand All @@ -29,7 +32,7 @@
}) | trim | indent(2) }}
{% endif %}
{% if params.errorMessage %}
{% set errorId = params.id ~ '-error' %}
{% set errorId = id ~ '-error' %}
{% set describedBy = describedBy ~ ' ' ~ errorId if describedBy else errorId %}
{{ govukErrorMessage({
'id': errorId,
Expand All @@ -43,11 +46,45 @@
{% if params.formGroup and params.formGroup.beforeInput %}
{{ params.formGroup.beforeInput.html | safe | trim | indent(2) if params.formGroup and params.formGroup.beforeInput.html else params.formGroup.beforeInput.text }}
{% endif %}
<input class="govuk-file-upload {%- if params.classes %} {{ params.classes }}{% endif %} {%- if params.errorMessage %} govuk-file-upload--error{% endif %}" id="{{ params.id }}" name="{{ params.name }}" type="file"
{% if params.javascript %}
<div
class="govuk-drop-zone"
data-module="govuk-file-upload"
{{- govukI18nAttributes({
'key': 'choose-files-button',
'message': params.chooseFilesButtonText
}) -}}
{{- govukI18nAttributes({
'key': 'no-file-chosen',
'message': params.noFileChosenText
}) -}}
{{- govukI18nAttributes({
'key': 'multiple-files-chosen',
'messages': params.multipleFilesChosenText
}) -}}
{{- govukI18nAttributes({
'key': 'drop-instruction',
'message': params.dropInstructionText
}) -}}
{{- govukI18nAttributes({
'key': 'entered-drop-zone',
'message': params.enteredDropZoneText
}) -}}
{{- govukI18nAttributes({
'key': 'left-drop-zone',
'message': params.leftDropZoneText
}) -}}
>
{% endif %}
<input class="govuk-file-upload {%- if params.classes %} {{ params.classes }}{% endif %} {%- if params.errorMessage %} govuk-file-upload--error{% endif %}" id="{{ id }}" name="{{ params.name }}" type="file"
{%- if params.value %} value="{{ params.value }}"{% endif %}
{%- if params.disabled %} disabled{% endif %}
{%- if params.multiple %} multiple{% endif %}
{%- if describedBy %} aria-describedby="{{ describedBy }}"{% endif %}
{{- govukAttributes(params.attributes) }}>
{% if params.javascript %}
</div>
{% endif %}
{% if params.formGroup and params.formGroup.afterInput %}
{{ params.formGroup.afterInput.html | safe | trim | indent(2) if params.formGroup and params.formGroup.afterInput.html else params.formGroup.afterInput.text }}
{% endif %}
Expand Down
9 changes: 5 additions & 4 deletions govuk_frontend_jinja/templates/components/input/macro.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
{#- a record of other elements that we need to associate with the input using
aria-describedby – for example hints or error messages -#}
{% set describedBy = params.describedBy if params.describedBy else undefined -%}
{%- set id = params.id if params.id else params.name -%}

{%- set hasPrefix = true if params.prefix and (params.prefix.text or params.prefix.html) else false %}
{%- set hasSuffix = true if params.suffix and (params.suffix.text or params.suffix.html) else false %}
Expand All @@ -28,7 +29,7 @@
<input
{{- govukAttributes({
'class': classNames,
'id': params.id,
'id': id,
'name': params.name,
'type': params.type | default("text", true),
'spellcheck': {
Expand Down Expand Up @@ -84,10 +85,10 @@
'classes': params.label.classes,
'isPageHeading': params.label.isPageHeading,
'attributes': params.label.attributes,
'for': params.id
'for': id
}) | trim | indent(2) }}
{% if params.hint %}
{% set hintId = params.id ~ '-hint' %}
{% set hintId = id ~ '-hint' %}
{% set describedBy = describedBy ~ ' ' ~ hintId if describedBy else hintId %}
{{ govukHint({
'id': hintId,
Expand All @@ -98,7 +99,7 @@
}) | trim | indent(2) }}
{% endif %}
{% if params.errorMessage %}
{% set errorId = params.id ~ '-error' %}
{% set errorId = id ~ '-error' %}
{% set describedBy = describedBy ~ ' ' ~ errorId if describedBy else errorId %}
{{ govukErrorMessage({
'id': errorId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
{% from "govuk_frontend_jinja/components/button/macro.html" import govukButton -%}
{% from "govuk_frontend_jinja/components/input/macro.html" import govukInput -%}

{%- set id = params.id if params.id else params.name -%}

{% set attributesHtml -%}
{{- ' data-module="govuk-password-input"' | safe }}

Expand Down Expand Up @@ -52,7 +54,7 @@
'classes': "govuk-button--secondary govuk-password-input__toggle govuk-js-password-input-toggle" ~ (" " ~ params.button.classes if params.button and params.button.classes),
'text': params.showPasswordText | default("Show"),
'attributes': {
"aria-controls": params.id,
"aria-controls": id,
"aria-label": params.showPasswordAriaLabelText | default("Show password"),
"hidden": {
'value': true,
Expand Down Expand Up @@ -81,7 +83,7 @@
'hint': params.hint,
'classes': "govuk-password-input__input govuk-js-password-input-input" ~ (" " ~ params.classes if params.classes),
'errorMessage': params.errorMessage,
'id': params.id,
'id': id,
'name': params.name,
'type': "password",
'spellcheck': false,
Expand Down
18 changes: 10 additions & 8 deletions govuk_frontend_jinja/templates/components/select/macro.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
{#- a record of other elements that we need to associate with the input using
aria-describedby – for example hints or error messages -#}
{% set describedBy = params.describedBy if params.describedBy else "" %}
{%- set id = params.id if params.id else params.name -%}

<div class="govuk-form-group {%- if params.errorMessage %} govuk-form-group--error{% endif %} {%- if params.formGroup and params.formGroup.classes %} {{ params.formGroup.classes }}{% endif %}"
{{- govukAttributes(params.formGroup.attributes if params.formGroup) }}>
{{ govukLabel({
Expand All @@ -15,10 +17,10 @@
'classes': params.label.classes,
'isPageHeading': params.label.isPageHeading,
'attributes': params.label.attributes,
'for': params.id
'for': id
}) | trim | indent(2) }}
{% if params.hint %}
{% set hintId = params.id ~ '-hint' %}
{% set hintId = id ~ '-hint' %}
{% set describedBy = describedBy ~ ' ' ~ hintId if describedBy else hintId %}
{{ govukHint({
'id': hintId,
Expand All @@ -29,7 +31,7 @@
}) | trim | indent(2) }}
{% endif %}
{% if params.errorMessage %}
{% set errorId = params.id ~ '-error' %}
{% set errorId = id ~ '-error' %}
{% set describedBy = describedBy ~ ' ' ~ errorId if describedBy else errorId %}
{{ govukErrorMessage({
'id': errorId,
Expand All @@ -44,13 +46,13 @@
{{ params.formGroup.beforeInput.html | safe | trim | indent(2) if params.formGroup and params.formGroup.beforeInput.html else params.formGroup.beforeInput.text }}
{% endif %}
<select class="govuk-select
{%- if params.classes %} {{ params.classes }}{% endif %}{%- if params.errorMessage %} govuk-select--error{% endif %}" id="{{ params.id }}" name="{{ params.name }}"
{%- if params.classes %} {{ params.classes }}{% endif %}{%- if params.errorMessage %} govuk-select--error{% endif %}" id="{{ id }}" name="{{ params.name }}"
{%- if params.disabled %} disabled{% endif %}
{%- if describedBy %} aria-describedby="{{ describedBy }}"{% endif %}
{{- govukAttributes(params.attributes) }}>
{% if 'items' in params and params['items'] | length %}
{% for item in params['items'] %}
{% if item %}
{% if item %}
{#- Allow selecting by text content (the value for an option when no value attribute is specified) #}
{%- set effectiveValue = item.value | default(item.text) %}
<option {%- if item.value is not undefined %} value="{{ item.value | lower }}"{% endif %}
Expand All @@ -59,9 +61,9 @@
{{- govukAttributes(item.attributes) }}>
{{- item.text -}}
</option>
{% endif %}
{% endfor %}
{% endif %}
{% endif %}
{% endfor %}
{% endif %}
</select>
{% if params.formGroup and params.formGroup.afterInput %}
{{ params.formGroup.afterInput.html | safe | trim | indent(2) if params.formGroup and params.formGroup.afterInput.html else params.formGroup.afterInput.text }}
Expand Down
10 changes: 6 additions & 4 deletions govuk_frontend_jinja/templates/components/textarea/macro.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
{#- a record of other elements that we need to associate with the input using
aria-describedby – for example hints or error messages -#}
{% set describedBy = params.describedBy if params.describedBy else "" %}
{%- set id = params.id if params.id else params.name -%}

<div class="govuk-form-group {%- if params.errorMessage %} govuk-form-group--error{% endif %} {%- if params.formGroup and params.formGroup.classes %} {{ params.formGroup.classes }}{% endif %}"
{{- govukAttributes(params.formGroup.attributes if params.formGroup) }}>
{{ govukLabel({
Expand All @@ -15,10 +17,10 @@
'classes': params.label.classes,
'isPageHeading': params.label.isPageHeading,
'attributes': params.label.attributes,
'for': params.id
'for': id
}) | trim | indent(2) }}
{% if params.hint %}
{% set hintId = params.id ~ '-hint' %}
{% set hintId = id ~ '-hint' %}
{% set describedBy = describedBy ~ ' ' ~ hintId if describedBy else hintId %}
{{ govukHint({
'id': hintId,
Expand All @@ -29,7 +31,7 @@
}) | trim | indent(2) }}
{% endif %}
{% if params.errorMessage %}
{% set errorId = params.id ~ '-error' %}
{% set errorId = id ~ '-error' %}
{% set describedBy = describedBy ~ ' ' ~ errorId if describedBy else errorId %}
{{ govukErrorMessage({
'id': errorId,
Expand All @@ -43,7 +45,7 @@
{% if params.formGroup and params.formGroup.beforeInput %}
{{ params.formGroup.beforeInput.html | safe | trim | indent(2) if params.formGroup and params.formGroup.beforeInput.html else params.formGroup.beforeInput.text }}
{% endif %}
<textarea class="govuk-textarea {%- if params.errorMessage %} govuk-textarea--error{% endif %} {%- if params.classes %} {{ params.classes }}{% endif %}" id="{{ params.id }}" name="{{ params.name }}" rows="{{ params.rows | default(5, true) }}"
<textarea class="govuk-textarea {%- if params.errorMessage %} govuk-textarea--error{% endif %} {%- if params.classes %} {{ params.classes }}{% endif %}" id="{{ id }}" name="{{ params.name }}" rows="{{ params.rows | default(5, true) }}"
{%- if (params.spellcheck is false) or (params.spellcheck is true) %} spellcheck="{{ params.spellcheck | lower }}"{% endif %}
{%- if params.disabled %} disabled{% endif %}
{%- if describedBy %} aria-describedby="{{ describedBy }}"{% endif %}
Expand Down

0 comments on commit 4584974

Please sign in to comment.