Skip to content

Commit

Permalink
Make error summary callable
Browse files Browse the repository at this point in the history
  • Loading branch information
querkmachine committed Jul 27, 2022
1 parent c3ebb8f commit 99694b5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/govuk/components/error-summary/error-summary.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ params:
type: string
required: false
description: HTML to use for the description of the errors. If you set this option, the component will ignore `descriptionText`.
- name: caller
type: nunjucks-block
required: false
description: Not strictly a parameter but [Nunjucks code convention](https://mozilla.github.io/nunjucks/templating.html#call). Using a `call` block enables you to call a macro with all the text inside the tag. This is helpful if you want to pass a lot of content into a macro. To use it, you will need to wrap the entire error summary component in a `call` block.
- name: errorList
type: array
required: true
Expand Down
4 changes: 2 additions & 2 deletions src/govuk/components/error-summary/template.njk
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
{{ params.titleHtml | safe if params.titleHtml else params.titleText }}
</h2>
<div class="govuk-error-summary__body">
{% if params.descriptionHtml or params.descriptionText %}
{% if caller or params.descriptionHtml or params.descriptionText %}
<p>
{{ params.descriptionHtml | safe if params.descriptionHtml else params.descriptionText }}
{{ caller() if caller else (params.descriptionHtml | safe if params.descriptionHtml else params.descriptionText) }}
</p>
{% endif %}
<ul class="govuk-list govuk-error-summary__list">
Expand Down
6 changes: 6 additions & 0 deletions src/govuk/components/error-summary/template.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ describe('Error-summary', () => {
expect(summaryDescription).toEqual('See <span>errors</span> below')
})

it('renders nested components in description using `call`', () => {
const $ = render('error-summary', {}, '<div class="app-nested-component"></div>')

expect($('.govuk-error-summary .app-nested-component').length).toBeTruthy()
})

it('allows additional classes to be added to the error-summary component', () => {
const $ = render('error-summary', examples.classes)

Expand Down

0 comments on commit 99694b5

Please sign in to comment.