Skip to content

Commit

Permalink
checkboxes component
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-shaw committed Jan 30, 2024
1 parent 5b83c69 commit a9325c6
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions govuk_frontend_jinja/templates/components/checkboxes/macro.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% macro govukCheckboxes(params) %}
{% from "govuk_frontend_jinja/components/error-message/macro.html" import govukErrorMessage -%}
{% from "govuk_frontend_jinja/components/error-message/macro.html" import govukErrorMessage %}
{% from "govuk_frontend_jinja/components/fieldset/macro.html" import govukFieldset %}
{% from "govuk_frontend_jinja/components/hint/macro.html" import govukHint %}
{% from "govuk_frontend_jinja/components/label/macro.html" import govukLabel %}
Expand Down Expand Up @@ -27,7 +27,7 @@
{% set ns.describedBy = ns.describedBy + ' ' + hintId if ns.describedBy else hintId %}
{{ govukHint({
'id': hintId,
'classes': (params.hint.classes if params.hint and params.hint.classes),
'classes': params.hint.classes,
'attributes': params.hint.attributes,
'html': params.hint.html,
'text': params.hint.text
Expand All @@ -46,8 +46,7 @@
}) | indent(2) | trim }}
{% endif %}
<div class="govuk-checkboxes {%- if params.classes %} {{ params.classes }}{% endif %}"
{%- for attribute, value in (params.attributes.items() if params.attributes else {}.items()) %} {{ attribute }}="{{ value }}"{% endfor %}
data-module="govuk-checkboxes">
{%- for attribute, value in (params.attributes.items() if params.attributes else {}.items()) %} {{ attribute }}="{{ value }}"{% endfor %} data-module="govuk-checkboxes">
{% for item in params['items'] %}
{% if item %}
{#- If the user explicitly sets an id, use this instead of the regular idPrefix -#}
Expand All @@ -66,8 +65,8 @@
{%- if item.divider %}
<div class="govuk-checkboxes__divider">{{ item.divider }}</div>
{%- else %}
{% set isChecked = item.checked | default(params.get("values", false) and item.value in params.get('values', [])) %}
{% set hasHint = True if (item.hint.text if item.hint and item.hint.text) or (item.hint.html if item.hint and item.hint.html) %}
{% set isChecked = item.checked | default((item.value in params.get('values', []) and item.checked != False) if params.values else false, true) %}
{% set hasHint = True if item.hint and (item.hint.text or item.hint.html) %}
{% set itemHintId = id + "-item-hint" if hasHint else "" %}
{% set itemDescribedBy = ns.describedBy if not hasFieldset else "" %}
{% set itemDescribedBy = (itemDescribedBy + " " + itemHintId) | trim %}
Expand All @@ -78,12 +77,12 @@
{%- if item.conditional and item.conditional.html %} data-aria-controls="{{ conditionalId }}"{% endif -%}
{%- if item.behaviour %} data-behaviour="{{ item.behaviour }}"{% endif -%}
{%- if itemDescribedBy %} aria-describedby="{{ itemDescribedBy }}"{% endif -%}
{%- for attribute, value in (item.attributes.items() if item.attributes else {}.items()) %} {{ attribute }}="{{ value }}"{% endfor -%}>
{%- for attribute, value in (item.attributes.items() if item.attributes else {}.items()) %} {{ attribute }}="{{ value }}"{% endfor %}>
{{ govukLabel({
'html': item.html,
'text': item.text,
'classes': 'govuk-checkboxes__label' + (' ' + item.label.classes if item.label and item.label.classes else ''),
'attributes': (item.label.attributes if item.label and item.label.attributes),
'attributes': item.label.attributes if item.label,
'for': id
}) | indent(6) | trim }}
{% if hasHint %}
Expand All @@ -97,7 +96,7 @@
{% endif %}
</div>
{% if item.conditional and item.conditional.html %}
<div class="govuk-checkboxes__conditional{% if not isChecked %} govuk-checkboxes__conditional--hidden{% endif %}" id="{{ conditionalId }}">
<div class="govuk-checkboxes__conditional {%- if not isChecked %} govuk-checkboxes__conditional--hidden{% endif %}" id="{{ conditionalId }}">
{{ item.conditional.html | safe }}
</div>
{% endif %}
Expand Down

0 comments on commit a9325c6

Please sign in to comment.