Skip to content

Commit

Permalink
Indent HTML for Text input
Browse files Browse the repository at this point in the history
  • Loading branch information
colinrotherham committed Jan 25, 2024
1 parent 9497750 commit e9e9f0a
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions packages/govuk-frontend/src/govuk/components/input/template.njk
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,11 @@
}) | trim | indent(2) }}
{% endif %}

{%- if params.prefix or params.suffix %}<div class="govuk-input__wrapper">{% endif -%}

{%- if params.prefix.text or params.prefix.html -%}
<div class="govuk-input__prefix {%- if params.prefix.classes %} {{ params.prefix.classes }}{% endif %}" aria-hidden="true" {%- for attribute, value in params.prefix.attributes %} {{ attribute }}="{{ value }}"{% endfor %}>
{{- params.prefix.html | safe if params.prefix.html else params.prefix.text -}}
</div>
{% endif -%}
{%- set hasPrefix = true if params.prefix else false %}
{%- set hasSuffix = true if params.suffix else false %}

{#- Capture the HTML so we can optionally nest it in a prefix or suffix wrapper -#}
{%- set innerHtml -%}
<input class="govuk-input {%- if params.classes %} {{ params.classes }}{% endif %} {%- if params.errorMessage %} govuk-input--error{% endif %}" id="{{ params.id }}" name="{{ params.name }}" type="{{ params.type | default("text", true) }}"
{%- if (params.spellcheck === false) or (params.spellcheck === true) %} spellcheck="{{ params.spellcheck }}"{% endif %}
{%- if params.value %} value="{{ params.value }}"{% endif %}
Expand All @@ -56,13 +53,23 @@
{%- if params.pattern %} pattern="{{ params.pattern }}"{% endif %}
{%- if params.inputmode %} inputmode="{{ params.inputmode }}"{% endif %}
{%- for attribute, value in params.attributes %} {{ attribute }}="{{ value }}"{% endfor %}>
{%- endset %}

{%- if params.suffix.text or params.suffix.html -%}
{%- if hasPrefix or hasSuffix %}
<div class="govuk-input__wrapper">
{% if params.prefix.text or params.prefix.html %}
<div class="govuk-input__prefix {%- if params.prefix.classes %} {{ params.prefix.classes }}{% endif %}" aria-hidden="true" {%- for attribute, value in params.prefix.attributes %} {{ attribute }}="{{ value }}"{% endfor %}>
{{- params.prefix.html | safe if params.prefix.html else params.prefix.text -}}
</div>
{% endif %}
{{ innerHtml | safe | trim | indent(4) }}
{% if params.suffix.text or params.suffix.html -%}
<div class="govuk-input__suffix {%- if params.suffix.classes %} {{ params.suffix.classes }}{% endif %}" aria-hidden="true" {%- for attribute, value in params.suffix.attributes %} {{ attribute }}="{{ value }}"{% endfor %}>
{{- params.suffix.html | safe if params.suffix.html else params.suffix.text -}}
</div>
{% endif -%}

{%- if params.prefix or params.suffix %}</div>{% endif %}

{% endif %}
</div>
{% else %}
{{ innerHtml | safe }}
{% endif %}
</div>

0 comments on commit e9e9f0a

Please sign in to comment.