Skip to content

Commit c2f1e3f

Browse files
Prevent Nunjucks size params overriding class
1 parent 907e5d5 commit c2f1e3f

File tree

5 files changed

+64
-3
lines changed

5 files changed

+64
-3
lines changed

packages/nhsuk-frontend/src/nhsuk/components/fieldset/fixtures.mjs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,25 @@ export const examples = {
104104
}
105105
]
106106
},
107+
'with legend size class': {
108+
context: {
109+
legend: {
110+
text: 'What is your address?',
111+
classes: 'nhsuk-fieldset__legend--l',
112+
isPageHeading: true
113+
}
114+
}
115+
},
116+
'with legend size class overriding size param': {
117+
context: {
118+
legend: {
119+
text: 'What is your address?',
120+
classes: 'nhsuk-fieldset__legend--l',
121+
size: 's',
122+
isPageHeading: true
123+
}
124+
}
125+
},
107126
'without page heading': {
108127
context: {
109128
legend: {

packages/nhsuk-frontend/src/nhsuk/components/label/fixtures.mjs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,21 @@ export const examples = {
4949
viewports: ['tablet']
5050
}
5151
},
52+
'size class': {
53+
context: {
54+
text: 'What is your full name?',
55+
classes: 'nhsuk-label--l',
56+
isPageHeading: true
57+
}
58+
},
59+
'size class overriding size param': {
60+
context: {
61+
text: 'What is your full name?',
62+
classes: 'nhsuk-label--l',
63+
size: 's',
64+
isPageHeading: true
65+
}
66+
},
5267
'without page heading': {
5368
context: {
5469
text: 'What is your full name?'

packages/nhsuk-frontend/src/nhsuk/components/label/template.njk

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,16 @@
33
{#- Set classes for this component #}
44
{%- set classNames = "nhsuk-label" -%}
55

6-
{%- if params.size and params.size in ["s", "m", "l", "xl"] %}
6+
{%- if params.size and
7+
params.size in ["s", "m", "l", "xl"] and (
8+
not params.classes or (
9+
not "nhsuk-label--s" in params.classes and
10+
not "nhsuk-label--m" in params.classes and
11+
not "nhsuk-label--l" in params.classes and
12+
not "nhsuk-label--xl" in params.classes
13+
)
14+
)
15+
%}
716
{% set classNames = classNames ~ " nhsuk-label--" ~ params.size %}
817
{% endif %}
918

packages/nhsuk-frontend/src/nhsuk/components/legend/template.njk

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,16 @@
33
{#- Set classes for this component #}
44
{%- set classNames = "nhsuk-fieldset__legend" -%}
55

6-
{%- if params.size and params.size in ["s", "m", "l", "xl"] %}
6+
{%- if params.size and
7+
params.size in ["s", "m", "l", "xl"] and (
8+
not params.classes or (
9+
not "nhsuk-fieldset__legend--s" in params.classes and
10+
not "nhsuk-fieldset__legend--m" in params.classes and
11+
not "nhsuk-fieldset__legend--l" in params.classes and
12+
not "nhsuk-fieldset__legend--xl" in params.classes
13+
)
14+
)
15+
%}
716
{% set classNames = classNames ~ " nhsuk-fieldset__legend--" ~ params.size %}
817
{% endif %}
918

packages/nhsuk-frontend/src/nhsuk/components/tables/template.njk

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,16 @@
44
{%- set classNames = "nhsuk-table" if not params.responsive else "nhsuk-table-responsive" -%}
55
{%- set classNamesCaption = "nhsuk-table__caption" -%}
66

7-
{%- if params.captionSize %}
7+
{%- if params.captionSize and
8+
params.captionSize in ["s", "m", "l", "xl"] and (
9+
not params.captionClasses or (
10+
not "nhsuk-label--s" in params.captionClasses and
11+
not "nhsuk-label--m" in params.captionClasses and
12+
not "nhsuk-label--l" in params.captionClasses and
13+
not "nhsuk-label--xl" in params.captionClasses
14+
)
15+
)
16+
%}
817
{% set classNamesCaption = classNamesCaption ~ " nhsuk-table__caption--" ~ params.captionSize %}
918
{% endif %}
1019

0 commit comments

Comments
 (0)