diff --git a/CHANGELOG.md b/CHANGELOG.md index 53bea20b6a..cc195fd77c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ ### Fixes - [Pull request #1655: Ensure components use public `govuk-media-query` mixin](https://github.com/alphagov/govuk-frontend/pull/1655). +- [Pull request #1638: Check component item arrays are not empty before outputting markup](https://github.com/alphagov/govuk-frontend/pull/1638). ## 3.4.0 (Feature release) @@ -58,7 +59,6 @@ You can now add attributes to the `` element of a page, by using the [`bod - [Pull request #1620: Only add underline to back link when href exists ](https://github.com/alphagov/govuk-frontend/pull/1620). - [Pull request #1631: Fix classes on character count when in error state](https://github.com/alphagov/govuk-frontend/pull/1631). - ## 3.3.0 (Feature release) ### New features diff --git a/src/govuk/components/date-input/template.njk b/src/govuk/components/date-input/template.njk index 8bf462b80e..29b9eadc1c 100644 --- a/src/govuk/components/date-input/template.njk +++ b/src/govuk/components/date-input/template.njk @@ -7,7 +7,7 @@ aria-describedby – for example hints or error messages -#} {% set describedBy = params.fieldset.describedBy if params.fieldset.describedBy else "" %} -{% if params.items %} +{% if params.items | length %} {% set dateInputItems = params.items %} {% else %} {% set dateInputItems = [ diff --git a/src/govuk/components/date-input/template.test.js b/src/govuk/components/date-input/template.test.js index a0b74b24d9..e62094af50 100644 --- a/src/govuk/components/date-input/template.test.js +++ b/src/govuk/components/date-input/template.test.js @@ -69,6 +69,15 @@ describe('Date input', () => { expect($items.length).toEqual(3) }) + it('renders defaults when an empty item array is provided', () => { + const $ = render('date-input', { + items: [] + }) + + const $items = $('.govuk-date-input__item') + expect($items.length).toEqual(3) + }) + it('renders with default items', () => { const $ = render('date-input', {}) diff --git a/src/govuk/components/footer/template.njk b/src/govuk/components/footer/template.njk index 1e797312a3..745300b4f8 100644 --- a/src/govuk/components/footer/template.njk +++ b/src/govuk/components/footer/template.njk @@ -1,12 +1,12 @@