Skip to content

Commit

Permalink
Remove indents from conditional reveals in radios and checkboxes
Browse files Browse the repository at this point in the history
  • Loading branch information
owenatgov committed Apr 3, 2024
1 parent 4b914bf commit 34e7dee
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ We've made fixes to GOV.UK Frontend in the following pull requests:

- [#4906: Update the icon in the warning text component to match the defined text colour and background colour, rather than always being white on black](https://github.com/alphagov/govuk-frontend/pull/4906)
- [#4919: Use canvas colour for cookie banner over hardcoded grey](https://github.com/alphagov/govuk-frontend/pull/4919)
- [#4899: Remove indents from conditional reveals in radios and checkboxes](https://github.com/alphagov/govuk-frontend/pull/4899)

## GOV.UK Frontend v5.3.0 (Feature release)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -955,3 +955,16 @@ examples:
- value: blue
text: Blue
values: [red, green]
- name: textarea in conditional
hidden: true
options:
name: conditional
items:
- value: other
text: Other
conditional:
html: |
<label class="govuk-label" for="conditional-textarea">textarea</label>
<textarea class="govuk-textarea govuk-!-width-one-third" name="conditional-textarea" id="conditional-textarea">
test
</textarea>
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
</div>
{% if item.conditional.html %}
<div class="govuk-checkboxes__conditional {%- if not isChecked %} govuk-checkboxes__conditional--hidden{% endif %}" id="{{ conditionalId }}">
{{ item.conditional.html | safe | trim | indent(6) }}
{{ item.conditional.html | safe | trim }}
</div>
{% endif %}
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,15 @@ describe('Checkboxes', () => {
const $input = $('.govuk-checkboxes__input').first()
expect($input.attr('data-aria-controls')).toBeFalsy()
})

// Indentation in nunjucks can mutate the value of textareas, since
// textarea value is defined between the html tags
it('does not add space to the input value of textareas inside conditionals', () => {
const $ = render('checkboxes', examples['textarea in conditional'])

const $textarea = $('#conditional-textarea')
expect($textarea.text()).toBe('test\n')
})
})

describe('when they include an error message', () => {
Expand Down
13 changes: 13 additions & 0 deletions packages/govuk-frontend/src/govuk/components/radios/radios.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -944,3 +944,16 @@ examples:
- value: blue
text: Blue
value: green
- name: textarea in conditional
hidden: true
options:
name: conditional
items:
- value: other
text: Other
conditional:
html: |
<label class="govuk-label" for="conditional-textarea">textarea</label>
<textarea class="govuk-textarea govuk-!-width-one-third" name="conditional-textarea" id="conditional-textarea">
test
</textarea>
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
</div>
{% if item.conditional.html %}
<div class="govuk-radios__conditional {%- if not isChecked %} govuk-radios__conditional--hidden{% endif %}" id="{{ conditionalId }}">
{{ item.conditional.html | safe | trim | indent(6) }}
{{ item.conditional.html | safe | trim }}
</div>
{% endif %}
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,15 @@ describe('Radios', () => {
const $input = $('.govuk-radios__input').first()
expect($input.attr('data-aria-controls')).toBeFalsy()
})

// Indentation in nunjucks can mutate the value of textareas, since
// textarea value is defined between the html tags
it('does not add space to the input value of textareas inside conditionals', () => {
const $ = render('radios', examples['textarea in conditional'])

const $textarea = $('#conditional-textarea')
expect($textarea.text()).toBe('test\n')
})
})

it('render divider', () => {
Expand Down

0 comments on commit 34e7dee

Please sign in to comment.