|
3 | 3 | {% from "../hint/macro.njk" import govukHint %}
|
4 | 4 | {% from "../label/macro.njk" import govukLabel %}
|
5 | 5 |
|
| 6 | +{#- Set classes for this component #} |
| 7 | +{%- set classNames = "govuk-input" -%} |
| 8 | + |
| 9 | +{%- if params.classes %} |
| 10 | + {% set classNames = classNames + " " + params.classes %} |
| 11 | +{% endif %} |
| 12 | + |
| 13 | +{%- if params.errorMessage %} |
| 14 | + {% set classNames = classNames + " govuk-input--error" %} |
| 15 | +{% endif %} |
| 16 | + |
6 | 17 | {#- a record of other elements that we need to associate with the input using
|
7 | 18 | aria-describedby – for example hints or error messages -#}
|
8 | 19 | {% set describedBy = params.describedBy if params.describedBy else "" -%}
|
|
13 | 24 | {%- set hasAfterInput = true if params.formGroup.afterInput and (params.formGroup.afterInput.text or params.formGroup.afterInput.html) else false %}
|
14 | 25 |
|
15 | 26 | {%- macro _inputElement(params) -%}
|
16 |
| - <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) }}" |
17 |
| - {%- if (params.spellcheck === false) or (params.spellcheck === true) %} spellcheck="{{ params.spellcheck }}"{% endif %} |
18 |
| - {%- if params.value %} value="{{ params.value }}"{% endif %} |
19 |
| - {%- if params.disabled %} disabled{% endif %} |
20 |
| - {%- if describedBy %} aria-describedby="{{ describedBy }}"{% endif %} |
21 |
| - {%- if params.autocomplete %} autocomplete="{{ params.autocomplete }}"{% endif %} |
22 |
| - {%- if params.pattern %} pattern="{{ params.pattern }}"{% endif %} |
23 |
| - {%- if params.inputmode %} inputmode="{{ params.inputmode }}"{% endif %} |
24 |
| - {%- if params.autocapitalize %} autocapitalize="{{ params.autocapitalize }}"{% endif %} |
| 27 | + <input |
| 28 | + {{- govukAttributes({ |
| 29 | + class: classNames, |
| 30 | + id: params.id, |
| 31 | + name: params.name, |
| 32 | + type: params.type | default("text", true), |
| 33 | + spellcheck: { |
| 34 | + value: params.spellcheck | string |
| 35 | + if [true, false].includes(params.spellcheck) |
| 36 | + else false, |
| 37 | + optional: true |
| 38 | + }, |
| 39 | + value: { |
| 40 | + value: params.value, |
| 41 | + optional: true |
| 42 | + }, |
| 43 | + disabled: { |
| 44 | + value: params.disabled, |
| 45 | + optional: true |
| 46 | + }, |
| 47 | + "aria-describedby": { |
| 48 | + value: describedBy, |
| 49 | + optional: true |
| 50 | + }, |
| 51 | + autocomplete: { |
| 52 | + value: params.autocomplete, |
| 53 | + optional: true |
| 54 | + }, |
| 55 | + autocapitalize: { |
| 56 | + value: params.autocapitalize, |
| 57 | + optional: true |
| 58 | + }, |
| 59 | + pattern: { |
| 60 | + value: params.pattern, |
| 61 | + optional: true |
| 62 | + }, |
| 63 | + inputmode: { |
| 64 | + value: params.inputmode, |
| 65 | + optional: true |
| 66 | + } |
| 67 | + }) -}} |
| 68 | + |
25 | 69 | {{- govukAttributes(params.attributes) }}>
|
26 | 70 | {%- endmacro -%}
|
27 | 71 |
|
|
0 commit comments