Skip to content

Commit

Permalink
radios component
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-shaw committed Jan 30, 2024
1 parent a9325c6 commit a305552
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions govuk_frontend_jinja/templates/components/radios/macro.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% macro govukRadios(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 All @@ -21,7 +21,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 @@ -40,8 +40,7 @@
}) | indent(2) | trim }}
{% endif %}
<div class="govuk-radios {%- if params.classes %} {{ params.classes }}{% endif %}"
{%- for attribute, value in (params.attributes.items() if params.attributes else {}.items()) %} {{ attribute }}="{{ value }}"{% endfor %}
data-module="govuk-radios">
{%- for attribute, value in (params.attributes.items() if params.attributes else {}.items()) %} {{ attribute }}="{{ value }}"{% endfor %} data-module="govuk-radios">
{% for item in params['items'] %}
{% if item %}
{#- If the user explicitly sets an id, use this instead of the regular idPrefix -#}
Expand All @@ -59,21 +58,21 @@
{%- if item.divider %}
<div class="govuk-radios__divider">{{ item.divider }}</div>
{%- else %}
{% set isChecked = item.checked | default(params.value and item.value == params.value) %}
{% 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 == params.value and item.checked != False) if params.value else false, true) %}
{% set hasHint = True if item.hint and (item.hint.text or item.hint.html) %}
{% set itemHintId = id + '-item-hint' %}
<div class="govuk-radios__item">
<input class="govuk-radios__input" id="{{ id }}" name="{{ params.name }}" type="radio" value="{{ item.value }}"
{{-" checked" if isChecked }}
{{-" disabled" if item.disabled }}
{%- if item.conditional and item.conditional.html %} data-aria-controls="{{ conditionalId }}"{% endif -%}
{%- if hasHint %} aria-describedby="{{ itemHintId }}"{% 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-radios__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 @@ -87,7 +86,7 @@
{% endif %}
</div>
{% if item.conditional and item.conditional.html %}
<div class="govuk-radios__conditional{% if not isChecked %} govuk-radios__conditional--hidden{% endif %}" id="{{ conditionalId }}">
<div class="govuk-radios__conditional {%- if not isChecked %} govuk-radios__conditional--hidden{% endif %}" id="{{ conditionalId }}">
{{ item.conditional.html | safe }}
</div>
{% endif %}
Expand Down

0 comments on commit a305552

Please sign in to comment.