govuk_publishing_components 12.21.0 → 13.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/govuk_publishing_components/components/checkboxes.js +8 -0
- data/app/assets/stylesheets/govuk_publishing_components/_all_components.scss +0 -1
- data/app/assets/stylesheets/govuk_publishing_components/components/_accessible-autocomplete.scss +5 -1
- data/app/assets/stylesheets/govuk_publishing_components/components/_checkboxes.scss +26 -3
- data/app/views/govuk_publishing_components/components/_checkboxes.html.erb +32 -54
- data/app/views/govuk_publishing_components/components/_feedback.html.erb +5 -4
- data/app/views/govuk_publishing_components/components/_input.html.erb +2 -0
- data/app/views/govuk_publishing_components/components/docs/checkboxes.yml +93 -19
- data/app/views/govuk_publishing_components/components/docs/input.yml +7 -0
- data/lib/govuk_publishing_components.rb +1 -0
- data/lib/govuk_publishing_components/presenters/checkboxes_helper.rb +71 -0
- data/lib/govuk_publishing_components/version.rb +1 -1
- data/node_modules/jquery/package.json +1 -1
- metadata +3 -6
- data/app/assets/javascripts/govuk_publishing_components/components/checkbox.js +0 -17
- data/app/assets/stylesheets/govuk_publishing_components/components/_checkbox.scss +0 -11
- data/app/views/govuk_publishing_components/components/_checkbox.html.erb +0 -27
- data/app/views/govuk_publishing_components/components/docs/checkbox.yml +0 -86
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df69e5eebf0a2f518d9d7dfc66b2d56d91b438c062242366f9b76eb4e5d30788
|
4
|
+
data.tar.gz: 8b684cbf3231e99af0f82425a8375843660b9fd6454f6d3cb4cfe9f135a79e26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4683dd5bb8d6211c2d999e386d9a58f6d23486d36c2ba8b9a82a0b86c1101abe4f3d880c3546aeee3720a3eb9e8083870bd555ba86577483968cf34373c4f4fb
|
7
|
+
data.tar.gz: 35885c7e30def9ae024ae33a1854c596915e3ffcf08839843cfe842c232de37b8f798e791aa33abb6fd1e8a2f79f829f3e217565801ad001ee5c9b699e28e374
|
@@ -9,6 +9,7 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
|
|
9
9
|
Modules.Checkboxes = function () {
|
10
10
|
this.start = function (scope) {
|
11
11
|
var _this = this;
|
12
|
+
this.applyAriaControlsAttributes(scope);
|
12
13
|
|
13
14
|
$(scope).find('[data-nested=true] input[type=checkbox]').on('change', function(e) {
|
14
15
|
var checkbox = e.target;
|
@@ -21,6 +22,7 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
|
|
21
22
|
_this.toggleParentCheckbox(isNested, checkbox);
|
22
23
|
}
|
23
24
|
});
|
25
|
+
|
24
26
|
};
|
25
27
|
|
26
28
|
this.toggleNestedCheckboxes = function(scope, checkbox) {
|
@@ -41,5 +43,11 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
|
|
41
43
|
$('#' + parent_id).prop("checked", false);
|
42
44
|
}
|
43
45
|
};
|
46
|
+
|
47
|
+
this.applyAriaControlsAttributes = function (scope) {
|
48
|
+
$(scope).find('[data-controls]').each(function () {
|
49
|
+
$(this).attr('aria-controls', $(this).attr('data-controls'));
|
50
|
+
});
|
51
|
+
};
|
44
52
|
};
|
45
53
|
})(window.GOVUK.Modules);
|
@@ -1,3 +1,15 @@
|
|
1
|
+
@import "helpers/govuk-frontend-settings";
|
2
|
+
@import "govuk-frontend/components/checkboxes/checkboxes";
|
3
|
+
|
4
|
+
.gem-c-checkbox.gem-c-checkbox--margin-bottom:last-child,
|
5
|
+
.gem-c-checkbox.gem-c-checkbox--margin-bottom:last-of-type {
|
6
|
+
margin-bottom: $gutter-two-thirds;
|
7
|
+
|
8
|
+
@include media(tablet) {
|
9
|
+
margin-bottom: $gutter;
|
10
|
+
}
|
11
|
+
}
|
12
|
+
|
1
13
|
.govuk-checkboxes--nested {
|
2
14
|
margin-left: (govuk-spacing(3) + 3px);
|
3
15
|
box-sizing: border-box;
|
@@ -15,6 +27,7 @@
|
|
15
27
|
|
16
28
|
.gem-c-checkboxes__list {
|
17
29
|
padding-left: govuk-spacing(0);
|
30
|
+
margin: 0;
|
18
31
|
}
|
19
32
|
|
20
33
|
.gem-c-checkboxes__list-item {
|
@@ -22,7 +35,17 @@
|
|
22
35
|
margin-bottom: govuk-spacing(2);
|
23
36
|
}
|
24
37
|
|
25
|
-
.gem-c-checkboxes__list-item:last-child
|
26
|
-
|
27
|
-
|
38
|
+
.gem-c-checkboxes__list-item:last-child {
|
39
|
+
margin-bottom: 0;
|
40
|
+
|
41
|
+
.govuk-checkboxes--nested {
|
42
|
+
margin-bottom: 0;
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
// this is complex but needed to override the govuk-frontend styles in
|
47
|
+
// https://github.com/alphagov/govuk-frontend/blob/b8058640b9602ecb6e1f66f887553190cbae7b46/src/components/hint/_hint.scss#L16
|
48
|
+
// our elements are wrapped in list items that already provide a margin-bottom
|
49
|
+
.govuk-label:not(.govuk-label--m):not(.govuk-label--l):not(.govuk-label--xl) + .govuk-hint {
|
50
|
+
margin-bottom: 0;
|
28
51
|
}
|
@@ -1,72 +1,50 @@
|
|
1
1
|
<%
|
2
|
-
|
3
|
-
|
4
|
-
css_classes = %w( gem-c-checkboxes govuk-form-group )
|
5
|
-
css_classes << classes if classes
|
6
|
-
error ||= nil
|
7
|
-
css_classes << "govuk-form-group--error" if error
|
8
|
-
heading ||= nil
|
9
|
-
hint_text ||= "Select all that apply."
|
10
|
-
items ||= []
|
11
|
-
is_page_heading ||= false
|
12
|
-
|
13
|
-
# check if any item is set as being conditional
|
14
|
-
has_conditional = items.any? { |item| item.is_a?(Hash) && item[:conditional] }
|
15
|
-
has_nested = items.any? { |item| item.is_a?(Hash) && item[:items] }
|
2
|
+
cb_helper = GovukPublishingComponents::Presenters::CheckboxesHelper.new(local_assigns)
|
3
|
+
id = cb_helper.id
|
16
4
|
%>
|
17
5
|
|
18
|
-
<%= tag.div id: id, class: css_classes, data: { module: "checkboxes" } do %>
|
19
|
-
|
6
|
+
<%= tag.div id: id, class: cb_helper.css_classes, data: { module: "checkboxes" } do %>
|
7
|
+
<% if cb_helper.items.length == 1 %>
|
8
|
+
<%= cb_helper.checkbox_markup(cb_helper.items[0], 0) %>
|
20
9
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
<%= tag.legend heading, class: "govuk-fieldset__legend govuk-fieldset__legend--m" %>
|
10
|
+
<% else %>
|
11
|
+
<%= tag.fieldset class: "govuk-fieldset", "aria-describedby": cb_helper.fieldset_describedby do %>
|
12
|
+
<%= cb_helper.heading_markup %>
|
13
|
+
|
14
|
+
<% if cb_helper.hint_text %>
|
15
|
+
<%= tag.span cb_helper.hint_text, id: "#{id}-hint", class: "govuk-hint" %>
|
28
16
|
<% end %>
|
29
|
-
<% end %>
|
30
17
|
|
31
|
-
|
18
|
+
<% if cb_helper.error %>
|
19
|
+
<%= tag.span error, id: "#{id}-error", class: "govuk-error-message" %>
|
20
|
+
<% end %>
|
32
21
|
|
33
|
-
|
34
|
-
|
35
|
-
|
22
|
+
<%= tag.ul class: "govuk-checkboxes gem-c-checkboxes__list", data: {
|
23
|
+
module: ('checkboxes' if cb_helper.has_conditional),
|
24
|
+
nested: ('true' if cb_helper.has_nested),
|
25
|
+
} do %>
|
26
|
+
<% cb_helper.items.each_with_index do |item, index| %>
|
27
|
+
<%= tag.li class: "gem-c-checkboxes__list-item" do %>
|
28
|
+
<%= cb_helper.checkbox_markup(item, index) %>
|
36
29
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
} do %>
|
41
|
-
<% items.each_with_index do |item, index| %>
|
42
|
-
<%= tag.li class: "gem-c-checkboxes__list-item" do %>
|
43
|
-
<%= render 'govuk_publishing_components/components/checkbox', {
|
44
|
-
id: id,
|
45
|
-
name: name,
|
46
|
-
item: item,
|
47
|
-
index: index,
|
48
|
-
} %>
|
49
|
-
<% if item[:conditional] %>
|
50
|
-
<%= tag.div item[:conditional], id: "#{id}-#{index}-conditional-#{index}", class: "govuk-checkboxes__conditional govuk-checkboxes__conditional--hidden" %>
|
51
|
-
<% end %>
|
30
|
+
<% if item[:conditional] %>
|
31
|
+
<%= tag.div item[:conditional], id: "#{id}-#{index}-conditional-#{index}", class: "govuk-checkboxes__conditional govuk-checkboxes__conditional--hidden" %>
|
32
|
+
<% end %>
|
52
33
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
name: name,
|
60
|
-
item: nested_item,
|
61
|
-
index: "#{index}-#{nested_index}",
|
62
|
-
} %>
|
34
|
+
<% if item[:items].present? %>
|
35
|
+
<%= tag.ul id: "#{id}-nested-#{index}", class: "govuk-checkboxes govuk-checkboxes--nested", data: { parent: "#{id}-#{index}" } do %>
|
36
|
+
<% item[:items].each_with_index do |nested_item, nested_index| %>
|
37
|
+
<%= tag.li class: "gem-c-checkboxes__list-item" do %>
|
38
|
+
<%= cb_helper.checkbox_markup(nested_item, "#{index}-#{nested_index}") %>
|
39
|
+
<% end %>
|
63
40
|
<% end %>
|
64
41
|
<% end %>
|
65
42
|
<% end %>
|
43
|
+
|
66
44
|
<% end %>
|
67
45
|
<% end %>
|
68
46
|
<% end %>
|
69
|
-
<% end %>
|
70
47
|
|
48
|
+
<% end %>
|
71
49
|
<% end %>
|
72
50
|
<% end %>
|
@@ -3,8 +3,9 @@
|
|
3
3
|
margin_top ||= 1
|
4
4
|
margin_top_class = "gem-c-feedback--top-margin" if margin_top == 1
|
5
5
|
email_regex = /[^\s=\/?&]+(?:@|%40)[^\s=\/?&]+/
|
6
|
-
stripped_path = request.original_url.gsub(email_regex, '[email]')
|
7
|
-
stripped_url = request.fullpath.gsub(email_regex, '[email]')
|
6
|
+
stripped_path = request.original_url.gsub(email_regex, '[email]').encode
|
7
|
+
stripped_url = request.fullpath.gsub(email_regex, '[email]').encode
|
8
|
+
user_agent = request.user_agent.encode
|
8
9
|
%>
|
9
10
|
|
10
11
|
<div class="gem-c-feedback <%= margin_top_class %>" data-module="feedback">
|
@@ -90,7 +91,7 @@
|
|
90
91
|
<div class="gem-c-feedback__error-summary gem-c-feedback__js-show js-hidden js-errors" tabindex="-1"></div>
|
91
92
|
|
92
93
|
<input type="hidden" name="url" value="<%= stripped_path -%>">
|
93
|
-
<input type="hidden" name="user_agent" value="<%=
|
94
|
+
<input type="hidden" name="user_agent" value="<%= user_agent -%>">
|
94
95
|
|
95
96
|
<h3 class="gem-c-feedback__form-heading">Help us improve GOV.UK</h3>
|
96
97
|
<p id="feedback_explanation" class="gem-c-feedback__form-paragraph">Don’t include personal or financial information like your National Insurance number or credit card details.</p>
|
@@ -136,7 +137,7 @@
|
|
136
137
|
<div class="gem-c-feedback__error-summary js-hidden js-errors" tabindex="-1"></div>
|
137
138
|
|
138
139
|
<input type="hidden" name="url" value="<%= stripped_path -%>">
|
139
|
-
<input type="hidden" name="user_agent" value="<%=
|
140
|
+
<input type="hidden" name="user_agent" value="<%= user_agent -%>">
|
140
141
|
|
141
142
|
<input name="email_survey_signup[survey_id]" type="hidden" value="footer_satisfaction_survey">
|
142
143
|
<input name="email_survey_signup[survey_source]" type="hidden" value="<%= stripped_path -%>">
|
@@ -13,6 +13,7 @@
|
|
13
13
|
autofocus ||= nil
|
14
14
|
tabindex ||= nil
|
15
15
|
readonly ||= nil
|
16
|
+
maxlength ||= nil
|
16
17
|
has_error = error_message || error_items&.any?
|
17
18
|
hint_id = "hint-#{SecureRandom.hex(4)}"
|
18
19
|
error_id = "error-#{SecureRandom.hex(4)}"
|
@@ -67,6 +68,7 @@
|
|
67
68
|
tabindex: tabindex,
|
68
69
|
autofocus: autofocus,
|
69
70
|
readonly: readonly,
|
71
|
+
maxlength: maxlength,
|
70
72
|
aria: {
|
71
73
|
describedby: aria_described_by,
|
72
74
|
controls: controls
|
@@ -1,6 +1,5 @@
|
|
1
1
|
name: Form checkboxes
|
2
|
-
description: Let users select one or more options
|
3
|
-
body: This component uses [Checkbox component](/component-guide/checkbox).
|
2
|
+
description: Let users select one or more options with checkboxes.
|
4
3
|
govuk_frontend_components:
|
5
4
|
- checkboxes
|
6
5
|
accessibility_criteria: |
|
@@ -12,10 +11,20 @@ accessibility_criteria: |
|
|
12
11
|
- be usable with touch
|
13
12
|
- indicate when they have focus
|
14
13
|
- have correctly associated labels
|
14
|
+
- have a legend (see below)
|
15
15
|
|
16
16
|
Labels use the [label component](/component-guide/label).
|
17
|
+
|
18
|
+
Checkboxes in a fieldset require a legend. The text of the legend is passed using the 'heading' option. If no heading is passed, no legend is shown, which causes an accessibility error. You must pass a heading when using this component, or provide other measures to ensure accessibility.
|
17
19
|
examples:
|
18
20
|
default:
|
21
|
+
data:
|
22
|
+
name: "favourite_colour_default"
|
23
|
+
items:
|
24
|
+
- label: "Red"
|
25
|
+
value: "red_colour"
|
26
|
+
with_multiple_checkboxes:
|
27
|
+
description: When more than one checkbox is shown they are wrapped in a fieldset element, which requires a legend. This must be supplied to the component using the heading option.
|
19
28
|
data:
|
20
29
|
name: "favourite_colour"
|
21
30
|
heading: "What is your favourite colour?"
|
@@ -26,19 +35,31 @@ examples:
|
|
26
35
|
value: "green"
|
27
36
|
- label: "Blue"
|
28
37
|
value: "blue"
|
29
|
-
|
38
|
+
with_a_custom_id_attribute:
|
39
|
+
description: Note that if an id is not given one is generated automatically. In either case, the id is applied to the parent element of the checkboxes, and each checkbox is given the same id with an incremented number at the end, e.g. the checkboxes below have ids of potatoes-0 and potatoes-1.
|
30
40
|
data:
|
31
|
-
name: "
|
32
|
-
|
33
|
-
|
41
|
+
name: "potatoes"
|
42
|
+
id: "potatoes"
|
43
|
+
heading: "What kind of potatoes do you like?"
|
34
44
|
items:
|
35
45
|
- label: "Red"
|
36
46
|
value: "red"
|
37
47
|
- label: "Green"
|
38
48
|
value: "green"
|
39
|
-
|
40
|
-
|
41
|
-
|
49
|
+
with_custom_ids_on_individal_checkboxes:
|
50
|
+
description: Individual checkboxes can be given specific ids if required. Note that the general id option can still be used, but the individual ids will override the general one if it is given.
|
51
|
+
data:
|
52
|
+
name: "carrots"
|
53
|
+
id: "carrots"
|
54
|
+
heading: "What kind of carrots do you like?"
|
55
|
+
items:
|
56
|
+
- label: "Orange"
|
57
|
+
value: "orange"
|
58
|
+
id: "custom-orange-id"
|
59
|
+
- label: "Purple"
|
60
|
+
value: "purple"
|
61
|
+
with_custom_hint_text:
|
62
|
+
description: Note that a hint (and a heading) is only displayed if there is more than one checkbox.
|
42
63
|
data:
|
43
64
|
name: "favourite_skittle"
|
44
65
|
heading: "What is your favourite skittle?"
|
@@ -50,7 +71,48 @@ examples:
|
|
50
71
|
value: "green"
|
51
72
|
- label: "Blue"
|
52
73
|
value: "blue"
|
53
|
-
|
74
|
+
with_legend_as_page_heading:
|
75
|
+
description: Since the legend/heading is required, if the checkboxes are alone on a page it makes sense to use this element as the H1 on the page rather than duplicate text.
|
76
|
+
data:
|
77
|
+
name: "favourite_colour"
|
78
|
+
heading: "What is your favourite colour?"
|
79
|
+
is_page_heading: true
|
80
|
+
items:
|
81
|
+
- label: "Red"
|
82
|
+
value: "red"
|
83
|
+
- label: "Green"
|
84
|
+
value: "green"
|
85
|
+
- label: "Blue"
|
86
|
+
value: "blue"
|
87
|
+
checkboxes_with_data_attributes:
|
88
|
+
description: Data attributes such as tracking can be applied if required. Note that for a checkbox this will not fire tracking events automatically, so if you want your tracking to work you'll need to write some tracking Javascript in the app around the component to detect it.
|
89
|
+
data:
|
90
|
+
name: "With tracking"
|
91
|
+
items:
|
92
|
+
- label: "Tracked"
|
93
|
+
value: "tracked"
|
94
|
+
data_attributes: {
|
95
|
+
track_category: "checkboxClicked",
|
96
|
+
track_label: "/news-and-communications",
|
97
|
+
track_action: "news",
|
98
|
+
track_options: {
|
99
|
+
dimension28: 2,
|
100
|
+
dimension29: "Tracked"
|
101
|
+
}
|
102
|
+
}
|
103
|
+
with_aria_controls_attributes:
|
104
|
+
description: Aria controls attributes are applied to the checkboxes only if Javascript is enabled.
|
105
|
+
data:
|
106
|
+
name: "aria_controls"
|
107
|
+
heading: "What areas are you interested in?"
|
108
|
+
items:
|
109
|
+
- label: "Farming and the environment"
|
110
|
+
value: "farming"
|
111
|
+
controls: "js-live-results"
|
112
|
+
- label: "Water recycling"
|
113
|
+
value: "water"
|
114
|
+
controls: "js-live-results"
|
115
|
+
checkboxes_with_individual_hints:
|
54
116
|
data:
|
55
117
|
name: "nationality"
|
56
118
|
heading: "What is your nationality?"
|
@@ -63,6 +125,7 @@ examples:
|
|
63
125
|
value: "irish"
|
64
126
|
- label: "Other"
|
65
127
|
value: "other"
|
128
|
+
hint: "anything other than the above"
|
66
129
|
checkbox_items_with_error:
|
67
130
|
data:
|
68
131
|
name: "nationality"
|
@@ -78,19 +141,25 @@ examples:
|
|
78
141
|
- label: "Other"
|
79
142
|
value: "other"
|
80
143
|
checkbox_items_with_conditional_reveal:
|
144
|
+
description: |
|
145
|
+
Checkboxes can be configured to show additional elements when checked. This could include further components, such as text inputs as shown.
|
146
|
+
|
147
|
+
Note that if you do insert HTML, this may cause accessibility violations if the additional elements have different name attributes to the checkboxes. No styling will be applied to the inserted content by the component.
|
81
148
|
data:
|
82
|
-
name: "
|
83
|
-
|
84
|
-
|
149
|
+
name: "contactingme"
|
150
|
+
id: "contactingme"
|
151
|
+
heading: "How would you like to be contacted?"
|
152
|
+
hint_text: "Please select all options that are relevant to you."
|
85
153
|
items:
|
86
|
-
- label: "
|
87
|
-
value: "
|
88
|
-
conditional: "
|
89
|
-
- label: "
|
90
|
-
value: "
|
154
|
+
- label: "Email"
|
155
|
+
value: "email"
|
156
|
+
conditional: <div class="govuk-form-group"><label class="govuk-label" for="contact-by-email">Email address</label><input class="govuk-input govuk-!-width-one-third" id="contact-by-email" name="contactingme" type="email"></div>
|
157
|
+
- label: "Phone"
|
158
|
+
value: "phone"
|
159
|
+
conditional: <div class="govuk-form-group"><label class="govuk-label" for="contact-by-phone">Phone number</label><input class="govuk-input govuk-!-width-one-third" id="contact-by-phone" name="contactingme" type="tel"></div>
|
91
160
|
- label: "Other"
|
92
161
|
value: "other"
|
93
|
-
conditional: "
|
162
|
+
conditional: "See no styling."
|
94
163
|
checkbox_items_with_checked_items:
|
95
164
|
data:
|
96
165
|
name: "nationality"
|
@@ -125,3 +194,8 @@ examples:
|
|
125
194
|
value: "dark_blue"
|
126
195
|
- label: "Other"
|
127
196
|
value: "other"
|
197
|
+
items:
|
198
|
+
- label: "Orange"
|
199
|
+
value: "orange"
|
200
|
+
- label: "Puce"
|
201
|
+
value: "puce"
|
@@ -8,6 +8,7 @@ require "govuk_publishing_components/presenters/step_by_step_nav_helper"
|
|
8
8
|
require "govuk_publishing_components/presenters/page_with_step_by_step_navigation"
|
9
9
|
require "govuk_publishing_components/presenters/content_breadcrumbs_based_on_parent"
|
10
10
|
require "govuk_publishing_components/presenters/content_breadcrumbs_based_on_taxons"
|
11
|
+
require "govuk_publishing_components/presenters/checkboxes_helper"
|
11
12
|
require "govuk_publishing_components/presenters/services"
|
12
13
|
require "govuk_publishing_components/presenters/select"
|
13
14
|
require "govuk_publishing_components/presenters/meta_tags"
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module GovukPublishingComponents
|
2
|
+
module Presenters
|
3
|
+
class CheckboxesHelper
|
4
|
+
include ActionView::Helpers
|
5
|
+
include ActionView::Context
|
6
|
+
|
7
|
+
attr_reader :items, :name, :css_classes, :error, :has_conditional, :has_nested, :id, :hint_text
|
8
|
+
|
9
|
+
def initialize(options)
|
10
|
+
@items = options[:items] || []
|
11
|
+
@name = options[:name]
|
12
|
+
@css_classes = %w(gem-c-checkboxes govuk-form-group)
|
13
|
+
@css_classes << "govuk-form-group--error" if options[:error]
|
14
|
+
@error = true if options[:error]
|
15
|
+
|
16
|
+
# check if any item is set as being conditional
|
17
|
+
@has_conditional = options[:items].any? { |item| item.is_a?(Hash) && item[:conditional] }
|
18
|
+
@has_nested = options[:items].any? { |item| item.is_a?(Hash) && item[:items] }
|
19
|
+
|
20
|
+
@id = options[:id] || "checkboxes-#{SecureRandom.hex(4)}"
|
21
|
+
@heading = options[:heading]
|
22
|
+
@is_page_heading = options[:is_page_heading]
|
23
|
+
@hint_text = options[:hint_text] || "Select all that apply."
|
24
|
+
end
|
25
|
+
|
26
|
+
def fieldset_describedby
|
27
|
+
text = %w()
|
28
|
+
text << "#{id}-hint" if @hint_text
|
29
|
+
text << "#{id}-error" if @error
|
30
|
+
text
|
31
|
+
end
|
32
|
+
|
33
|
+
def heading_markup
|
34
|
+
return unless @heading.present?
|
35
|
+
|
36
|
+
if @is_page_heading
|
37
|
+
content_tag(
|
38
|
+
:legend,
|
39
|
+
class: "govuk-fieldset__legend govuk-fieldset__legend--xl gem-c-title gem-c-title--margin-bottom-5"
|
40
|
+
) do
|
41
|
+
content_tag(:h1, @heading, class: "gem-c-title__text")
|
42
|
+
end
|
43
|
+
else
|
44
|
+
content_tag(:legend, @heading, class: "govuk-fieldset__legend govuk-fieldset__legend--m")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def checkbox_markup(checkbox, index)
|
49
|
+
checkbox_id = checkbox[:id] || "#{@id}-#{index}"
|
50
|
+
controls = checkbox[:conditional].present? ? "#{checkbox_id}-conditional-#{index || rand(1..100)}" : checkbox[:controls]
|
51
|
+
checkbox_name = checkbox[:name].present? ? checkbox[:name] : @name
|
52
|
+
checked = true if checkbox[:checked].present?
|
53
|
+
data = checkbox[:data_attributes] || {}
|
54
|
+
data[:controls] = controls
|
55
|
+
|
56
|
+
markup = capture do
|
57
|
+
concat check_box_tag checkbox_name, checkbox[:value], checked, class: "govuk-checkboxes__input", id: checkbox_id, data: data
|
58
|
+
concat content_tag(:label, checkbox[:label], for: checkbox_id, class: "govuk-label govuk-checkboxes__label")
|
59
|
+
concat content_tag(:span, checkbox[:hint], id: "#{checkbox_id}-item-hint", class: "govuk-hint govuk-checkboxes__hint") if checkbox[:hint]
|
60
|
+
end
|
61
|
+
|
62
|
+
content_tag(
|
63
|
+
:div,
|
64
|
+
class: "gem-c-checkbox govuk-checkboxes__item",
|
65
|
+
) do
|
66
|
+
markup
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -110,7 +110,7 @@
|
|
110
110
|
"directories": {},
|
111
111
|
"dist": {
|
112
112
|
"shasum": "01e1dfba290fe73deba77ceeacb0f9ba2fec9e0c",
|
113
|
-
"tarball": "
|
113
|
+
"tarball": "http://registry.npmjs.org/jquery/-/jquery-1.12.4.tgz"
|
114
114
|
},
|
115
115
|
"gitHead": "5e89585e0121e72ff47de177c5ef604f3089a53d",
|
116
116
|
"homepage": "http://jquery.com",
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: govuk_publishing_components
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 13.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GOV.UK Dev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-12-
|
11
|
+
date: 2018-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: govspeak
|
@@ -310,7 +310,6 @@ files:
|
|
310
310
|
- app/assets/javascripts/govuk_publishing_components/all_components.js
|
311
311
|
- app/assets/javascripts/govuk_publishing_components/components/accessible-autocomplete.js
|
312
312
|
- app/assets/javascripts/govuk_publishing_components/components/character-count.js
|
313
|
-
- app/assets/javascripts/govuk_publishing_components/components/checkbox.js
|
314
313
|
- app/assets/javascripts/govuk_publishing_components/components/checkboxes.js
|
315
314
|
- app/assets/javascripts/govuk_publishing_components/components/copy-to-clipboard.js
|
316
315
|
- app/assets/javascripts/govuk_publishing_components/components/error-summary.js
|
@@ -331,7 +330,6 @@ files:
|
|
331
330
|
- app/assets/stylesheets/govuk_publishing_components/components/_breadcrumbs.scss
|
332
331
|
- app/assets/stylesheets/govuk_publishing_components/components/_button.scss
|
333
332
|
- app/assets/stylesheets/govuk_publishing_components/components/_character-count.scss
|
334
|
-
- app/assets/stylesheets/govuk_publishing_components/components/_checkbox.scss
|
335
333
|
- app/assets/stylesheets/govuk_publishing_components/components/_checkboxes.scss
|
336
334
|
- app/assets/stylesheets/govuk_publishing_components/components/_contents-list.scss
|
337
335
|
- app/assets/stylesheets/govuk_publishing_components/components/_copy-to-clipboard.scss
|
@@ -442,7 +440,6 @@ files:
|
|
442
440
|
- app/views/govuk_publishing_components/components/_breadcrumbs.html.erb
|
443
441
|
- app/views/govuk_publishing_components/components/_button.html.erb
|
444
442
|
- app/views/govuk_publishing_components/components/_character_count.html.erb
|
445
|
-
- app/views/govuk_publishing_components/components/_checkbox.html.erb
|
446
443
|
- app/views/govuk_publishing_components/components/_checkboxes.html.erb
|
447
444
|
- app/views/govuk_publishing_components/components/_contents_list.html.erb
|
448
445
|
- app/views/govuk_publishing_components/components/_contextual_breadcrumbs.html.erb
|
@@ -505,7 +502,6 @@ files:
|
|
505
502
|
- app/views/govuk_publishing_components/components/docs/breadcrumbs.yml
|
506
503
|
- app/views/govuk_publishing_components/components/docs/button.yml
|
507
504
|
- app/views/govuk_publishing_components/components/docs/character_count.yml
|
508
|
-
- app/views/govuk_publishing_components/components/docs/checkbox.yml
|
509
505
|
- app/views/govuk_publishing_components/components/docs/checkboxes.yml
|
510
506
|
- app/views/govuk_publishing_components/components/docs/contents_list.yml
|
511
507
|
- app/views/govuk_publishing_components/components/docs/contextual_breadcrumbs.yml
|
@@ -584,6 +580,7 @@ files:
|
|
584
580
|
- lib/govuk_publishing_components/minitest/component_guide_test.rb
|
585
581
|
- lib/govuk_publishing_components/presenters/breadcrumbs.rb
|
586
582
|
- lib/govuk_publishing_components/presenters/button_helper.rb
|
583
|
+
- lib/govuk_publishing_components/presenters/checkboxes_helper.rb
|
587
584
|
- lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_parent.rb
|
588
585
|
- lib/govuk_publishing_components/presenters/content_breadcrumbs_based_on_taxons.rb
|
589
586
|
- lib/govuk_publishing_components/presenters/content_item.rb
|
@@ -1,17 +0,0 @@
|
|
1
|
-
window.GOVUK = window.GOVUK || {};
|
2
|
-
window.GOVUK.Modules = window.GOVUK.Modules || {};
|
3
|
-
|
4
|
-
(function (Modules) {
|
5
|
-
'use strict';
|
6
|
-
|
7
|
-
Modules.Checkbox = function () {
|
8
|
-
this.start = function ($element) {
|
9
|
-
var controls = $element.attr('data-aria-controls');
|
10
|
-
|
11
|
-
if (controls) {
|
12
|
-
$element.find('.govuk-checkboxes__input').attr('aria-controls', controls);
|
13
|
-
}
|
14
|
-
};
|
15
|
-
|
16
|
-
};
|
17
|
-
})(window.GOVUK.Modules);
|
@@ -1,11 +0,0 @@
|
|
1
|
-
@import "helpers/govuk-frontend-settings";
|
2
|
-
@import "govuk-frontend/components/checkboxes/checkboxes";
|
3
|
-
|
4
|
-
.gem-c-checkbox.gem-c-checkbox--margin-bottom:last-child,
|
5
|
-
.gem-c-checkbox.gem-c-checkbox--margin-bottom:last-of-type {
|
6
|
-
margin-bottom: $gutter-two-thirds;
|
7
|
-
|
8
|
-
@include media(tablet) {
|
9
|
-
margin-bottom: $gutter;
|
10
|
-
}
|
11
|
-
}
|
@@ -1,27 +0,0 @@
|
|
1
|
-
<%
|
2
|
-
index ||= false
|
3
|
-
id ||= "checkbox-#{SecureRandom.hex(4)}"
|
4
|
-
id = "#{id}-#{index}" if index
|
5
|
-
controls ||= item[:conditional].present? ? "#{id}-conditional-#{index || rand(1..100)}" : nil
|
6
|
-
name = item[:name].present? ? item[:name] : name
|
7
|
-
margin_bottom ||= false
|
8
|
-
margin_bottom_class = "gem-c-checkbox--margin-bottom" if margin_bottom
|
9
|
-
%>
|
10
|
-
|
11
|
-
<%= tag.div class: "gem-c-checkbox govuk-checkboxes__item #{margin_bottom_class}", data: { module: "checkbox", 'aria-controls': controls } do %>
|
12
|
-
<%= tag.input id: id,
|
13
|
-
name: name,
|
14
|
-
type: "checkbox",
|
15
|
-
value: item[:value],
|
16
|
-
class: "govuk-checkboxes__input",
|
17
|
-
checked: item[:checked].present? ? "checked" : nil,
|
18
|
-
data: item[:data_attributes],
|
19
|
-
aria: {
|
20
|
-
describedby: item[:hint].present? ? "#{id}-item-hint" : nil
|
21
|
-
}
|
22
|
-
%>
|
23
|
-
<%= tag.label item[:label], class: "govuk-label govuk-checkboxes__label", for: id %>
|
24
|
-
<% if item[:hint].present? %>
|
25
|
-
<%= tag.span item[:hint], id: "#{id}-item-hint", class: "govuk-hint govuk-checkboxes__hint" %>
|
26
|
-
<% end %>
|
27
|
-
<% end %>
|
@@ -1,86 +0,0 @@
|
|
1
|
-
name: Checkbox
|
2
|
-
description: Let users select one or more options by using the checkboxes component.
|
3
|
-
body: This component is used by [Form checkboxes component](/component-guide/checkboxes).
|
4
|
-
govuk_frontend_components:
|
5
|
-
- checkboxes
|
6
|
-
accessibility_criteria: |
|
7
|
-
The component must:
|
8
|
-
|
9
|
-
- accept focus
|
10
|
-
- be focusable with a keyboard
|
11
|
-
- be usable with a keyboard
|
12
|
-
- be usable with touch
|
13
|
-
- indicate when they have focus
|
14
|
-
- have correctly associated labels
|
15
|
-
|
16
|
-
Labels use the [label component](/component-guide/label).
|
17
|
-
examples:
|
18
|
-
default:
|
19
|
-
data:
|
20
|
-
name: "favourite_colour_default"
|
21
|
-
item:
|
22
|
-
label: "Red"
|
23
|
-
value: "red_colour"
|
24
|
-
checkbox_with_hint:
|
25
|
-
data:
|
26
|
-
name: "favourite_colour_checkbox_with_hint"
|
27
|
-
item:
|
28
|
-
label: "Red"
|
29
|
-
value: "red_colour"
|
30
|
-
hint: "This is the colour red."
|
31
|
-
checkbox_with_checked:
|
32
|
-
data:
|
33
|
-
name: "favourite_colour_checkbox_with_checked"
|
34
|
-
item:
|
35
|
-
label: "Red"
|
36
|
-
value: "red_colour"
|
37
|
-
checked: true
|
38
|
-
checkbox_with_identifier:
|
39
|
-
description: |
|
40
|
-
If no ID is given, a unique ID is generated for the checkbox automatically.
|
41
|
-
|
42
|
-
If an index is given, this is appended onto the end of the ID (given or generated). This is used in the checkboxes component where multiple checkboxes are output.
|
43
|
-
data:
|
44
|
-
name: "with_id"
|
45
|
-
id: "moose"
|
46
|
-
index: 10
|
47
|
-
item:
|
48
|
-
label: "With an id of 'moose-10'"
|
49
|
-
value: "with_id"
|
50
|
-
checkbox_with_data_attributes:
|
51
|
-
description: Data attributes such as tracking can be applied if required. Note that for a checkbox this will not fire tracking events automatically, so if you want your tracking to work you'll need to write some tracking Javascript in the app around the component to detect it.
|
52
|
-
data:
|
53
|
-
name: "With tracking"
|
54
|
-
item:
|
55
|
-
label: "Tracked"
|
56
|
-
value: "tracked"
|
57
|
-
data_attributes: {
|
58
|
-
track_category: "checkboxClicked",
|
59
|
-
track_label: "/news-and-communications",
|
60
|
-
track_action: "news",
|
61
|
-
track_options: {
|
62
|
-
dimension28: 2,
|
63
|
-
dimension29: "Tracked"
|
64
|
-
}
|
65
|
-
}
|
66
|
-
checkbox_with_aria_controls:
|
67
|
-
description: |
|
68
|
-
A value for aria-controls can be passed to the checkbox. This is applied using Javascript.
|
69
|
-
|
70
|
-
If a value is not passed, and a value for conditional has been passed, a value is generated based on the id of the checkbox and the passed index. This is used in the [form checkboxes component](/component-guide/checkboxes/checkbox_items_with_conditional_reveal).
|
71
|
-
data:
|
72
|
-
name: "happy"
|
73
|
-
controls: "wrapper"
|
74
|
-
item:
|
75
|
-
label: "Are you happy?"
|
76
|
-
value: "happy"
|
77
|
-
checkbox_with_bottom_margin:
|
78
|
-
description: By default the component has no bottom margin, this option adds it.
|
79
|
-
data:
|
80
|
-
name: "behold_my_bottom_margin"
|
81
|
-
margin_bottom: true
|
82
|
-
item:
|
83
|
-
label: "Do you like my bottom margin?"
|
84
|
-
value: "bottom_margin"
|
85
|
-
|
86
|
-
|