From d391eb606c65218a78b1719274e2241bf7b9dae9 Mon Sep 17 00:00:00 2001 From: Colin Rotherham Date: Tue, 13 Feb 2024 17:00:54 +0000 Subject: [PATCH 1/3] Move Tab list items into macro for easy indenting --- src/govuk/components/tabs/template.njk | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/govuk/components/tabs/template.njk b/src/govuk/components/tabs/template.njk index 99b1062cab..002e225169 100644 --- a/src/govuk/components/tabs/template.njk +++ b/src/govuk/components/tabs/template.njk @@ -1,5 +1,15 @@ {% from "../../macros/attributes.njk" import govukAttributes %} +{%- macro _tabListItem(params, item, index) %} +{% set tabPanelId = item.id if item.id else idPrefix + "-" + index -%} +
  • + + {{ item.label }} + +
  • +{% endmacro -%} + {#- If an id 'prefix' is not passed, fall back to using the name attribute instead. We need this for error messages and hints as well -#} {% set idPrefix = params.idPrefix if params.idPrefix -%} @@ -13,13 +23,7 @@ From 1caeddcdf79b2e394b477bf0824bb1a7b653de4c Mon Sep 17 00:00:00 2001 From: Colin Rotherham Date: Tue, 13 Feb 2024 17:05:41 +0000 Subject: [PATCH 2/3] Move Tab panels into macro for easy indenting --- src/govuk/components/tabs/template.njk | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/govuk/components/tabs/template.njk b/src/govuk/components/tabs/template.njk index 002e225169..2ee7b5c664 100644 --- a/src/govuk/components/tabs/template.njk +++ b/src/govuk/components/tabs/template.njk @@ -10,6 +10,18 @@ {% endmacro -%} +{%- macro _tabPanel(params, item, index) %} +{% set tabPanelId = item.id if item.id else idPrefix + "-" + index -%} +
    + {% if item.panel.html %} + {{ item.panel.html | safe }} + {% elif item.panel.text %} +

    {{ item.panel.text }}

    + {% endif %} +
    +{% endmacro -%} + {#- If an id 'prefix' is not passed, fall back to using the name attribute instead. We need this for error messages and hints as well -#} {% set idPrefix = params.idPrefix if params.idPrefix -%} @@ -30,15 +42,7 @@ {% endif %} {% for item in params.items %} {% if item %} - {% set id = item.id if item.id else idPrefix + "-" + loop.index %} -
    - {% if item.panel.html %} - {{ item.panel.html | safe }} - {% elif item.panel.text %} -

    {{ item.panel.text }}

    - {% endif %} -
    + {{- _tabPanel(params, item, loop.index) }} {% endif %} {% endfor %} From 6a577e1721aaecab42e8449d3a40ebe3632eabb1 Mon Sep 17 00:00:00 2001 From: Colin Rotherham Date: Tue, 13 Feb 2024 17:11:37 +0000 Subject: [PATCH 3/3] Indent HTML for Tabs --- src/govuk/components/tabs/template.njk | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/govuk/components/tabs/template.njk b/src/govuk/components/tabs/template.njk index 2ee7b5c664..77185e243b 100644 --- a/src/govuk/components/tabs/template.njk +++ b/src/govuk/components/tabs/template.njk @@ -14,11 +14,11 @@ {% set tabPanelId = item.id if item.id else idPrefix + "-" + index -%}
    - {% if item.panel.html %} - {{ item.panel.html | safe }} - {% elif item.panel.text %} -

    {{ item.panel.text }}

    - {% endif %} +{% if item.panel.html %} + {{ item.panel.html | safe | trim | indent(2) }} +{% elif item.panel.text %} +

    {{ item.panel.text }}

    +{% endif %}
    {% endmacro -%} @@ -31,18 +31,18 @@

    {{ params.title | default ("Contents") }}

    - {% if(params.items | length) %} +{% if params.items | length %}
      {% for item in params.items %} {% if item %} - {{- _tabListItem(params, item, loop.index) }} + {{- _tabListItem(params, item, loop.index) | trim | indent(4, true) }} {% endif %} {% endfor %}
    - {% endif %} {% for item in params.items %} {% if item %} - {{- _tabPanel(params, item, loop.index) }} + {{- _tabPanel(params, item, loop.index) | trim | indent(2, true) }} {% endif %} {% endfor %} +{% endif %}