From 2080e924e03ea7358c5beea623b0238596dfe6ad Mon Sep 17 00:00:00 2001 From: igloosi Date: Thu, 25 Oct 2018 09:38:57 +0100 Subject: [PATCH] Make it possible to set the error state on checkboxes without passing an error message Currently the error state for a conditionally revealed content shows the 'error bar' against the revealed content only. We want to move the error bar to the 'question' which will include the revealing checkboxes themselves. --- src/components/checkboxes/checkboxes.yaml | 40 ++++++++++++++++++++++ src/components/checkboxes/template.njk | 2 +- src/components/checkboxes/template.test.js | 22 ++++++++++++ 3 files changed, 63 insertions(+), 1 deletion(-) diff --git a/src/components/checkboxes/checkboxes.yaml b/src/components/checkboxes/checkboxes.yaml index fe7fa08613f..cf9003a0f4d 100644 --- a/src/components/checkboxes/checkboxes.yaml +++ b/src/components/checkboxes/checkboxes.yaml @@ -14,6 +14,15 @@ params: required: false description: Options for the errorMessage component (e.g. text). isComponent: true +- name: formGroup + type: object + required: false + description: Options for the form-group wrapper + params: + - name: classes + type: string + required: false + description: Optional classes to add to the form group (e.g. to show error state for the whole group) - name: idPrefix type: string required: false @@ -343,3 +352,34 @@ examples: html: | + +- name: with optional form-group classes showing group error + readme: false + data: + idPrefix: how-contacted-checked + formGroup: + classes: 'govuk-form-group--error' + fieldset: + legend: + text: How do you want to be contacted? + items: + - value: email + text: Email + conditional: + html: | + + + - value: phone + text: Phone + checked: true + conditional: + html: | + + Problem with input + + - value: text + text: Text message + conditional: + html: | + + diff --git a/src/components/checkboxes/template.njk b/src/components/checkboxes/template.njk index 148f787a1f9..8f39b79e5d2 100644 --- a/src/components/checkboxes/template.njk +++ b/src/components/checkboxes/template.njk @@ -83,7 +83,7 @@ {% endset -%} -
+
{% if params.fieldset %} {% call govukFieldset({ describedBy: describedBy, diff --git a/src/components/checkboxes/template.test.js b/src/components/checkboxes/template.test.js index 6a7ad4d4290..8b49fac4661 100644 --- a/src/components/checkboxes/template.test.js +++ b/src/components/checkboxes/template.test.js @@ -100,6 +100,28 @@ describe('Checkboxes', () => { expect($formGroup.length).toBeTruthy() }) + it('render a custom class on the form group', () => { + const $ = render('checkboxes', { + name: 'example-name', + items: [ + { + value: '1', + text: 'Option 1' + }, + { + value: '2', + text: 'Option 2' + } + ], + formGroup: { + classes: 'custom-group-class' + } + }) + + const $formGroup = $('.govuk-form-group') + expect($formGroup.hasClass('custom-group-class')).toBeTruthy() + }) + describe('items', () => { it('render a matching label and input using name by default', () => { const $ = render('checkboxes', {