govuk_publishing_components 9.6.0 → 9.7.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/radio.js +32 -0
- data/app/assets/stylesheets/govuk_publishing_components/_all_components.scss +1 -1
- data/app/assets/stylesheets/govuk_publishing_components/components/_back-link.scss +4 -31
- data/app/assets/stylesheets/govuk_publishing_components/components/_button.scss +13 -42
- data/app/assets/stylesheets/govuk_publishing_components/components/_input.scss +4 -32
- data/app/assets/stylesheets/govuk_publishing_components/components/_label.scss +4 -23
- data/app/assets/stylesheets/govuk_publishing_components/components/_layout-header.scss +0 -8
- data/app/assets/stylesheets/govuk_publishing_components/components/_radio.scss +5 -129
- data/app/assets/stylesheets/govuk_publishing_components/components/govspeak/_button.scss +5 -3
- data/app/views/govuk_publishing_components/components/_back_link.html.erb +7 -6
- data/app/views/govuk_publishing_components/components/_button.html.erb +2 -2
- data/app/views/govuk_publishing_components/components/_input.html.erb +32 -25
- data/app/views/govuk_publishing_components/components/_label.html.erb +13 -31
- data/app/views/govuk_publishing_components/components/_radio.html.erb +54 -38
- data/app/views/govuk_publishing_components/components/docs/radio.yml +14 -2
- data/lib/govuk_publishing_components/version.rb +1 -1
- data/node_modules/govuk-frontend/all.js +172 -172
- data/node_modules/govuk-frontend/components/checkboxes/README.md +92 -4
- data/node_modules/govuk-frontend/components/checkboxes/_checkboxes.scss +7 -1
- data/node_modules/govuk-frontend/components/checkboxes/checkboxes.js +356 -1
- data/node_modules/govuk-frontend/components/checkboxes/template.njk +15 -3
- data/node_modules/govuk-frontend/components/date-input/README.md +3 -3
- data/node_modules/govuk-frontend/components/file-upload/README.md +3 -3
- data/node_modules/govuk-frontend/components/header/_header.scss +5 -3
- data/node_modules/govuk-frontend/components/input/README.md +3 -3
- data/node_modules/govuk-frontend/components/phase-banner/README.md +1 -1
- data/node_modules/govuk-frontend/components/radios/README.md +176 -3
- data/node_modules/govuk-frontend/components/radios/_radios.scss +15 -1
- data/node_modules/govuk-frontend/components/radios/radios.js +356 -1
- data/node_modules/govuk-frontend/components/radios/template.njk +19 -3
- data/node_modules/govuk-frontend/components/select/README.md +3 -3
- data/node_modules/govuk-frontend/components/tabs/_tabs.scss +4 -4
- data/node_modules/govuk-frontend/components/tabs/tabs.js +1 -1
- data/node_modules/govuk-frontend/components/textarea/README.md +3 -3
- data/node_modules/govuk-frontend/package.json +18 -18
- data/node_modules/govuk-frontend/template.njk +4 -2
- data/node_modules/govuk-frontend/tools/_font-url.scss +1 -1
- data/node_modules/govuk-frontend/tools/_image-url.scss +1 -1
- metadata +3 -2
@@ -1,39 +1,21 @@
|
|
1
1
|
<%
|
2
2
|
classes ||= ''
|
3
|
-
text_classes ||= ''
|
4
|
-
hint_text_classes ||= ''
|
5
3
|
hint_text ||= ''
|
4
|
+
hint_text_classes ||= ''
|
6
5
|
bold ||= false
|
6
|
+
css_classes = %w( gem-c-label govuk-label )
|
7
|
+
css_classes << "govuk-label--s" if bold
|
8
|
+
css_classes << classes if classes
|
9
|
+
hint_text_css_classes = %w( govuk-hint )
|
10
|
+
hint_text_css_classes << hint_text_classes if hint_text_classes
|
7
11
|
%>
|
8
12
|
|
13
|
+
<%= tag.label for: html_for, class: css_classes do %>
|
14
|
+
<%= text %>
|
15
|
+
<% end %>
|
9
16
|
|
10
|
-
|
11
|
-
class
|
12
|
-
|
13
|
-
<%= "gem-c-label--bold" if bold %>
|
14
|
-
<%= classes if classes %>
|
15
|
-
"
|
16
|
-
>
|
17
|
-
<label
|
18
|
-
class="
|
19
|
-
gem-c-label__text
|
20
|
-
<%= text_classes if text_classes %>
|
21
|
-
"
|
22
|
-
<% if html_for %>
|
23
|
-
for="<%= html_for %>"
|
24
|
-
<% end %>
|
25
|
-
>
|
26
|
-
<%= text %>
|
27
|
-
</label>
|
28
|
-
<% if hint_text.present? %>
|
29
|
-
<span
|
30
|
-
class="
|
31
|
-
gem-c-label__hint
|
32
|
-
<%= hint_text_classes if hint_text_classes %>
|
33
|
-
"
|
34
|
-
id="<%= hint_id %>"
|
35
|
-
>
|
36
|
-
<%= hint_text %>
|
37
|
-
</span>
|
17
|
+
<% if hint_text.present? %>
|
18
|
+
<%= tag.span id: hint_id, class: hint_text_css_classes do %>
|
19
|
+
<%= hint_text %>
|
38
20
|
<% end %>
|
39
|
-
|
21
|
+
<% end %>
|
@@ -1,45 +1,61 @@
|
|
1
1
|
<%
|
2
2
|
id_prefix ||= "radio-#{SecureRandom.hex(4)}"
|
3
3
|
items ||= []
|
4
|
+
|
5
|
+
# check if any item is set as being conditional
|
6
|
+
has_conditional = items.any? { |item| item["conditional"] }
|
4
7
|
%>
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
8
|
+
<%= content_tag :div, class: "govuk-form-group" do %>
|
9
|
+
<%= content_tag :div, class: "govuk-radios",
|
10
|
+
data: {
|
11
|
+
module: ('radios' if has_conditional)
|
12
|
+
} do %>
|
13
|
+
<% items.each_with_index do |item, index| %>
|
14
|
+
<% if item === :or %>
|
15
|
+
<div class="govuk-radios__divider">
|
16
|
+
<%= t('components.radio.or') %>
|
17
|
+
</div>
|
18
|
+
<% else %>
|
19
|
+
<%
|
20
|
+
item_next = items[index + 1] unless index === items.size - 1
|
21
|
+
label_id = item[:id] ? item[:id] : "#{id_prefix}-#{index}"
|
22
|
+
label_hint_id = "label-hint-#{SecureRandom.hex(4)}" if item[:hint_text].present?
|
23
|
+
conditional_id = "conditional-#{SecureRandom.hex(4)}" if item[:conditional].present?
|
24
|
+
%>
|
25
|
+
<%= tag.div class: %w( gem-c-radio govuk-radios__item ) do %>
|
26
|
+
<%= check_box_tag name,
|
27
|
+
item[:value],
|
28
|
+
item[:checked],
|
29
|
+
{
|
30
|
+
class: "govuk-radios__input",
|
31
|
+
id: label_id,
|
32
|
+
type: "radio",
|
33
|
+
aria: {
|
34
|
+
describedby: label_hint_id
|
35
|
+
},
|
36
|
+
data: {
|
37
|
+
"aria-controls": conditional_id
|
38
|
+
}
|
39
|
+
}
|
40
|
+
%>
|
41
|
+
<%= render "govuk_publishing_components/components/label", {
|
42
|
+
hint_id: label_hint_id,
|
43
|
+
html_for: label_id,
|
44
|
+
classes: "govuk-radios__label",
|
45
|
+
hint_text_classes: "govuk-radios__hint",
|
46
|
+
hint_text: item[:hint_text],
|
47
|
+
text: item[:text],
|
48
|
+
bold: item[:bold]
|
49
|
+
} %>
|
31
50
|
<% end %>
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
bold: item[:bold]
|
42
|
-
} %>
|
43
|
-
</div>
|
51
|
+
|
52
|
+
<% if item[:conditional] %>
|
53
|
+
<div class="govuk-radios__conditional" id="<%= conditional_id %>">
|
54
|
+
<%= item[:conditional] %>
|
55
|
+
</div>
|
56
|
+
<% end %>
|
57
|
+
|
58
|
+
<% end %>
|
59
|
+
<% end %>
|
44
60
|
<% end %>
|
45
61
|
<% end %>
|
@@ -1,9 +1,9 @@
|
|
1
1
|
name: Radio button
|
2
2
|
description: A radio button is a GOV.UK element that allows users to answer a question by selecting an option. If you have a question with more than one option you should stack radio buttons.
|
3
3
|
body: |
|
4
|
-
|
4
|
+
You can also use 'or' as an item to break up radios.
|
5
5
|
|
6
|
-
|
6
|
+
If JavaScript is disabled a conditionally revealed content expands fully. All of the functionality (including aria attributes) are added using JavaScript.
|
7
7
|
accessibility_criteria: |
|
8
8
|
Radio buttons should
|
9
9
|
|
@@ -32,6 +32,7 @@ accessibility_criteria: |
|
|
32
32
|
|
33
33
|
accessibility_excluded_rules:
|
34
34
|
- radiogroup # Since this is in isolation we don't want to wrap a fieldset here.
|
35
|
+
- aria-expanded # We use aria expanded to reflect the state of a conditionally revealed radio content even if this attribute is not officially supported on this element.
|
35
36
|
examples:
|
36
37
|
default:
|
37
38
|
data:
|
@@ -117,3 +118,14 @@ examples:
|
|
117
118
|
hint_text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus sapien justo, lobortis elementum tortor in, luctus interdum turpis. Nam sit amet nulla nec arcu condimentum dapibus quis varius metus. Suspendisse cursus tristique diam et vestibulum. Proin nec lacinia tortor. Morbi at nisi id lorem aliquam ullamcorper. Pellentesque laoreet sit amet leo sodales ultricies. Suspendisse maximus efficitur odio in tristique."
|
118
119
|
text: "Quisque tincidunt venenatis bibendum. Morbi volutpat magna euismod ipsum consequat cursus. Etiam bibendum interdum ultricies."
|
119
120
|
bold: true
|
121
|
+
conditional:
|
122
|
+
data:
|
123
|
+
name: "radio-group-conditional"
|
124
|
+
id_prefix: "conditional"
|
125
|
+
items:
|
126
|
+
- value: "government-gateway"
|
127
|
+
text: "Use Government Gateway"
|
128
|
+
conditional: "You’ll need to prove your identity using Government Gateway"
|
129
|
+
- value: "govuk-verify"
|
130
|
+
text: "Use GOV.UK Verify"
|
131
|
+
conditional: "You’ll need to prove your identity using GOV.UK Verify"
|
@@ -881,177 +881,6 @@ Details.prototype.destroy = function (node) {
|
|
881
881
|
node.removeEventListener('click');
|
882
882
|
};
|
883
883
|
|
884
|
-
function Checkboxes ($module) {
|
885
|
-
this.$module = $module;
|
886
|
-
this.$inputs = $module.querySelectorAll('input[type="checkbox"]');
|
887
|
-
}
|
888
|
-
|
889
|
-
Checkboxes.prototype.init = function () {
|
890
|
-
var $module = this.$module;
|
891
|
-
var $inputs = this.$inputs;
|
892
|
-
|
893
|
-
/**
|
894
|
-
* Loop over all items with [data-controls]
|
895
|
-
* Check if they have a matching conditional reveal
|
896
|
-
* If they do, assign attributes.
|
897
|
-
**/
|
898
|
-
nodeListForEach($inputs, function ($input) {
|
899
|
-
var controls = $input.getAttribute('data-aria-controls');
|
900
|
-
|
901
|
-
// Check if input controls anything
|
902
|
-
// Check if content exists, before setting attributes.
|
903
|
-
if (!controls || !$module.querySelector('#' + controls)) {
|
904
|
-
return
|
905
|
-
}
|
906
|
-
|
907
|
-
// If we have content that is controlled, set attributes.
|
908
|
-
$input.setAttribute('aria-controls', controls);
|
909
|
-
$input.removeAttribute('data-aria-controls');
|
910
|
-
this.setAttributes($input);
|
911
|
-
}.bind(this));
|
912
|
-
|
913
|
-
// Handle events
|
914
|
-
$module.addEventListener('click', this.handleClick.bind(this));
|
915
|
-
};
|
916
|
-
|
917
|
-
Checkboxes.prototype.setAttributes = function ($input) {
|
918
|
-
var inputIsChecked = $input.checked;
|
919
|
-
$input.setAttribute('aria-expanded', inputIsChecked);
|
920
|
-
|
921
|
-
var $content = document.querySelector('#' + $input.getAttribute('aria-controls'));
|
922
|
-
$content.setAttribute('aria-hidden', !inputIsChecked);
|
923
|
-
};
|
924
|
-
|
925
|
-
Checkboxes.prototype.handleClick = function (event) {
|
926
|
-
var $target = event.target;
|
927
|
-
|
928
|
-
// If a checkbox with aria-controls, handle click
|
929
|
-
var isCheckbox = $target.getAttribute('type') === 'checkbox';
|
930
|
-
var hasAriaControls = $target.getAttribute('aria-controls');
|
931
|
-
if (isCheckbox && hasAriaControls) {
|
932
|
-
this.setAttributes($target);
|
933
|
-
}
|
934
|
-
};
|
935
|
-
|
936
|
-
function ErrorSummary ($module) {
|
937
|
-
this.$module = $module;
|
938
|
-
}
|
939
|
-
|
940
|
-
ErrorSummary.prototype.init = function () {
|
941
|
-
var $module = this.$module;
|
942
|
-
if (!$module) {
|
943
|
-
return
|
944
|
-
}
|
945
|
-
window.addEventListener('load', function () {
|
946
|
-
$module.focus();
|
947
|
-
});
|
948
|
-
};
|
949
|
-
|
950
|
-
function Header ($module) {
|
951
|
-
this.$module = $module;
|
952
|
-
}
|
953
|
-
|
954
|
-
Header.prototype.init = function () {
|
955
|
-
// Check for module
|
956
|
-
var $module = this.$module;
|
957
|
-
if (!$module) {
|
958
|
-
return
|
959
|
-
}
|
960
|
-
|
961
|
-
// Check for button
|
962
|
-
var $toggleButton = $module.querySelector('.js-header-toggle');
|
963
|
-
if (!$toggleButton) {
|
964
|
-
return
|
965
|
-
}
|
966
|
-
|
967
|
-
// Handle $toggleButton click events
|
968
|
-
$toggleButton.addEventListener('click', this.handleClick.bind(this));
|
969
|
-
};
|
970
|
-
|
971
|
-
/**
|
972
|
-
* Toggle class
|
973
|
-
* @param {object} node element
|
974
|
-
* @param {string} className to toggle
|
975
|
-
*/
|
976
|
-
Header.prototype.toggleClass = function (node, className) {
|
977
|
-
if (node.className.indexOf(className) > 0) {
|
978
|
-
node.className = node.className.replace(' ' + className, '');
|
979
|
-
} else {
|
980
|
-
node.className += ' ' + className;
|
981
|
-
}
|
982
|
-
};
|
983
|
-
|
984
|
-
/**
|
985
|
-
* An event handler for click event on $toggleButton
|
986
|
-
* @param {object} event event
|
987
|
-
*/
|
988
|
-
Header.prototype.handleClick = function (event) {
|
989
|
-
var $module = this.$module;
|
990
|
-
var $toggleButton = event.target || event.srcElement;
|
991
|
-
var $target = $module.querySelector('#' + $toggleButton.getAttribute('aria-controls'));
|
992
|
-
|
993
|
-
// If a button with aria-controls, handle click
|
994
|
-
if ($toggleButton && $target) {
|
995
|
-
this.toggleClass($target, 'govuk-header__navigation--open');
|
996
|
-
this.toggleClass($toggleButton, 'govuk-header__menu-button--open');
|
997
|
-
|
998
|
-
$toggleButton.setAttribute('aria-expanded', $toggleButton.getAttribute('aria-expanded') !== 'true');
|
999
|
-
$target.setAttribute('aria-hidden', $target.getAttribute('aria-hidden') === 'false');
|
1000
|
-
}
|
1001
|
-
};
|
1002
|
-
|
1003
|
-
function Radios ($module) {
|
1004
|
-
this.$module = $module;
|
1005
|
-
this.$inputs = $module.querySelectorAll('input[type="radio"]');
|
1006
|
-
}
|
1007
|
-
|
1008
|
-
Radios.prototype.init = function () {
|
1009
|
-
var $module = this.$module;
|
1010
|
-
var $inputs = this.$inputs;
|
1011
|
-
|
1012
|
-
/**
|
1013
|
-
* Loop over all items with [data-controls]
|
1014
|
-
* Check if they have a matching conditional reveal
|
1015
|
-
* If they do, assign attributes.
|
1016
|
-
**/
|
1017
|
-
nodeListForEach($inputs, function ($input) {
|
1018
|
-
var controls = $input.getAttribute('data-aria-controls');
|
1019
|
-
|
1020
|
-
// Check if input controls anything
|
1021
|
-
// Check if content exists, before setting attributes.
|
1022
|
-
if (!controls || !$module.querySelector('#' + controls)) {
|
1023
|
-
return
|
1024
|
-
}
|
1025
|
-
|
1026
|
-
// If we have content that is controlled, set attributes.
|
1027
|
-
$input.setAttribute('aria-controls', controls);
|
1028
|
-
$input.removeAttribute('data-aria-controls');
|
1029
|
-
this.setAttributes($input);
|
1030
|
-
}.bind(this));
|
1031
|
-
|
1032
|
-
// Handle events
|
1033
|
-
$module.addEventListener('click', this.handleClick.bind(this));
|
1034
|
-
};
|
1035
|
-
|
1036
|
-
Radios.prototype.setAttributes = function ($input) {
|
1037
|
-
var inputIsChecked = $input.checked;
|
1038
|
-
$input.setAttribute('aria-expanded', inputIsChecked);
|
1039
|
-
|
1040
|
-
var $content = document.querySelector('#' + $input.getAttribute('aria-controls'));
|
1041
|
-
$content.setAttribute('aria-hidden', !inputIsChecked);
|
1042
|
-
};
|
1043
|
-
|
1044
|
-
Radios.prototype.handleClick = function (event) {
|
1045
|
-
nodeListForEach(this.$inputs, function ($input) {
|
1046
|
-
// If a radio with aria-controls, handle click
|
1047
|
-
var isRadio = $input.getAttribute('type') === 'radio';
|
1048
|
-
var hasAriaControls = $input.getAttribute('aria-controls');
|
1049
|
-
if (isRadio && hasAriaControls) {
|
1050
|
-
this.setAttributes($input);
|
1051
|
-
}
|
1052
|
-
}.bind(this));
|
1053
|
-
};
|
1054
|
-
|
1055
884
|
(function(undefined) {
|
1056
885
|
|
1057
886
|
// Detection from https://raw.githubusercontent.com/Financial-Times/polyfill-service/master/packages/polyfill-library/polyfills/DOMTokenList/detect.js
|
@@ -1407,12 +1236,183 @@ Radios.prototype.handleClick = function (event) {
|
|
1407
1236
|
|
1408
1237
|
}).call('object' === typeof window && window || 'object' === typeof self && self || 'object' === typeof global && global || {});
|
1409
1238
|
|
1239
|
+
function Checkboxes ($module) {
|
1240
|
+
this.$module = $module;
|
1241
|
+
this.$inputs = $module.querySelectorAll('input[type="checkbox"]');
|
1242
|
+
}
|
1243
|
+
|
1244
|
+
Checkboxes.prototype.init = function () {
|
1245
|
+
var $module = this.$module;
|
1246
|
+
var $inputs = this.$inputs;
|
1247
|
+
|
1248
|
+
/**
|
1249
|
+
* Loop over all items with [data-controls]
|
1250
|
+
* Check if they have a matching conditional reveal
|
1251
|
+
* If they do, assign attributes.
|
1252
|
+
**/
|
1253
|
+
nodeListForEach($inputs, function ($input) {
|
1254
|
+
var controls = $input.getAttribute('data-aria-controls');
|
1255
|
+
|
1256
|
+
// Check if input controls anything
|
1257
|
+
// Check if content exists, before setting attributes.
|
1258
|
+
if (!controls || !$module.querySelector('#' + controls)) {
|
1259
|
+
return
|
1260
|
+
}
|
1261
|
+
|
1262
|
+
// If we have content that is controlled, set attributes.
|
1263
|
+
$input.setAttribute('aria-controls', controls);
|
1264
|
+
$input.removeAttribute('data-aria-controls');
|
1265
|
+
this.setAttributes($input);
|
1266
|
+
}.bind(this));
|
1267
|
+
|
1268
|
+
// Handle events
|
1269
|
+
$module.addEventListener('click', this.handleClick.bind(this));
|
1270
|
+
};
|
1271
|
+
|
1272
|
+
Checkboxes.prototype.setAttributes = function ($input) {
|
1273
|
+
var inputIsChecked = $input.checked;
|
1274
|
+
$input.setAttribute('aria-expanded', inputIsChecked);
|
1275
|
+
|
1276
|
+
var $content = document.querySelector('#' + $input.getAttribute('aria-controls'));
|
1277
|
+
$content.classList.toggle('govuk-checkboxes__conditional--hidden', !inputIsChecked);
|
1278
|
+
};
|
1279
|
+
|
1280
|
+
Checkboxes.prototype.handleClick = function (event) {
|
1281
|
+
var $target = event.target;
|
1282
|
+
|
1283
|
+
// If a checkbox with aria-controls, handle click
|
1284
|
+
var isCheckbox = $target.getAttribute('type') === 'checkbox';
|
1285
|
+
var hasAriaControls = $target.getAttribute('aria-controls');
|
1286
|
+
if (isCheckbox && hasAriaControls) {
|
1287
|
+
this.setAttributes($target);
|
1288
|
+
}
|
1289
|
+
};
|
1290
|
+
|
1291
|
+
function ErrorSummary ($module) {
|
1292
|
+
this.$module = $module;
|
1293
|
+
}
|
1294
|
+
|
1295
|
+
ErrorSummary.prototype.init = function () {
|
1296
|
+
var $module = this.$module;
|
1297
|
+
if (!$module) {
|
1298
|
+
return
|
1299
|
+
}
|
1300
|
+
window.addEventListener('load', function () {
|
1301
|
+
$module.focus();
|
1302
|
+
});
|
1303
|
+
};
|
1304
|
+
|
1305
|
+
function Header ($module) {
|
1306
|
+
this.$module = $module;
|
1307
|
+
}
|
1308
|
+
|
1309
|
+
Header.prototype.init = function () {
|
1310
|
+
// Check for module
|
1311
|
+
var $module = this.$module;
|
1312
|
+
if (!$module) {
|
1313
|
+
return
|
1314
|
+
}
|
1315
|
+
|
1316
|
+
// Check for button
|
1317
|
+
var $toggleButton = $module.querySelector('.js-header-toggle');
|
1318
|
+
if (!$toggleButton) {
|
1319
|
+
return
|
1320
|
+
}
|
1321
|
+
|
1322
|
+
// Handle $toggleButton click events
|
1323
|
+
$toggleButton.addEventListener('click', this.handleClick.bind(this));
|
1324
|
+
};
|
1325
|
+
|
1326
|
+
/**
|
1327
|
+
* Toggle class
|
1328
|
+
* @param {object} node element
|
1329
|
+
* @param {string} className to toggle
|
1330
|
+
*/
|
1331
|
+
Header.prototype.toggleClass = function (node, className) {
|
1332
|
+
if (node.className.indexOf(className) > 0) {
|
1333
|
+
node.className = node.className.replace(' ' + className, '');
|
1334
|
+
} else {
|
1335
|
+
node.className += ' ' + className;
|
1336
|
+
}
|
1337
|
+
};
|
1338
|
+
|
1339
|
+
/**
|
1340
|
+
* An event handler for click event on $toggleButton
|
1341
|
+
* @param {object} event event
|
1342
|
+
*/
|
1343
|
+
Header.prototype.handleClick = function (event) {
|
1344
|
+
var $module = this.$module;
|
1345
|
+
var $toggleButton = event.target || event.srcElement;
|
1346
|
+
var $target = $module.querySelector('#' + $toggleButton.getAttribute('aria-controls'));
|
1347
|
+
|
1348
|
+
// If a button with aria-controls, handle click
|
1349
|
+
if ($toggleButton && $target) {
|
1350
|
+
this.toggleClass($target, 'govuk-header__navigation--open');
|
1351
|
+
this.toggleClass($toggleButton, 'govuk-header__menu-button--open');
|
1352
|
+
|
1353
|
+
$toggleButton.setAttribute('aria-expanded', $toggleButton.getAttribute('aria-expanded') !== 'true');
|
1354
|
+
$target.setAttribute('aria-hidden', $target.getAttribute('aria-hidden') === 'false');
|
1355
|
+
}
|
1356
|
+
};
|
1357
|
+
|
1358
|
+
function Radios ($module) {
|
1359
|
+
this.$module = $module;
|
1360
|
+
this.$inputs = $module.querySelectorAll('input[type="radio"]');
|
1361
|
+
}
|
1362
|
+
|
1363
|
+
Radios.prototype.init = function () {
|
1364
|
+
var $module = this.$module;
|
1365
|
+
var $inputs = this.$inputs;
|
1366
|
+
|
1367
|
+
/**
|
1368
|
+
* Loop over all items with [data-controls]
|
1369
|
+
* Check if they have a matching conditional reveal
|
1370
|
+
* If they do, assign attributes.
|
1371
|
+
**/
|
1372
|
+
nodeListForEach($inputs, function ($input) {
|
1373
|
+
var controls = $input.getAttribute('data-aria-controls');
|
1374
|
+
|
1375
|
+
// Check if input controls anything
|
1376
|
+
// Check if content exists, before setting attributes.
|
1377
|
+
if (!controls || !$module.querySelector('#' + controls)) {
|
1378
|
+
return
|
1379
|
+
}
|
1380
|
+
|
1381
|
+
// If we have content that is controlled, set attributes.
|
1382
|
+
$input.setAttribute('aria-controls', controls);
|
1383
|
+
$input.removeAttribute('data-aria-controls');
|
1384
|
+
this.setAttributes($input);
|
1385
|
+
}.bind(this));
|
1386
|
+
|
1387
|
+
// Handle events
|
1388
|
+
$module.addEventListener('click', this.handleClick.bind(this));
|
1389
|
+
};
|
1390
|
+
|
1391
|
+
Radios.prototype.setAttributes = function ($input) {
|
1392
|
+
var inputIsChecked = $input.checked;
|
1393
|
+
$input.setAttribute('aria-expanded', inputIsChecked);
|
1394
|
+
|
1395
|
+
var $content = document.querySelector('#' + $input.getAttribute('aria-controls'));
|
1396
|
+
$content.classList.toggle('govuk-radios__conditional--hidden', !inputIsChecked);
|
1397
|
+
};
|
1398
|
+
|
1399
|
+
Radios.prototype.handleClick = function (event) {
|
1400
|
+
nodeListForEach(this.$inputs, function ($input) {
|
1401
|
+
// If a radio with aria-controls, handle click
|
1402
|
+
var isRadio = $input.getAttribute('type') === 'radio';
|
1403
|
+
var hasAriaControls = $input.getAttribute('aria-controls');
|
1404
|
+
if (isRadio && hasAriaControls) {
|
1405
|
+
this.setAttributes($input);
|
1406
|
+
}
|
1407
|
+
}.bind(this));
|
1408
|
+
};
|
1409
|
+
|
1410
1410
|
function Tabs ($module) {
|
1411
1411
|
this.$module = $module;
|
1412
1412
|
this.$tabs = $module.querySelectorAll('.govuk-tabs__tab');
|
1413
1413
|
|
1414
1414
|
this.keys = { left: 37, right: 39, up: 38, down: 40 };
|
1415
|
-
this.jsHiddenClass = '
|
1415
|
+
this.jsHiddenClass = 'govuk-tabs__panel--hidden';
|
1416
1416
|
}
|
1417
1417
|
|
1418
1418
|
Tabs.prototype.init = function () {
|