@ministryofjustice/frontend 3.0.3 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/moj/all.js CHANGED
@@ -567,7 +567,7 @@ MOJFrontend.ButtonMenu.prototype.mergeConfigs = function (...configObjects) {
567
567
  * @param {DatepickerConfig} config - config object
568
568
  * @constructor
569
569
  */
570
- function Datepicker($module, config) {
570
+ function Datepicker($module, config = {}) {
571
571
  if (!$module) {
572
572
  return this;
573
573
  }
@@ -730,7 +730,7 @@ Datepicker.prototype.initControls = function () {
730
730
  );
731
731
 
732
732
  this.$dialog.addEventListener("keydown", (event) => {
733
- if (event.key == "Escape") {
733
+ if (event.key === "Escape") {
734
734
  this.closeDialog();
735
735
  event.preventDefault();
736
736
  event.stopPropagation();
@@ -973,8 +973,7 @@ Datepicker.prototype.setWeekStartDay = function () {
973
973
  this.config.weekStartDay = "sunday";
974
974
  // Rotate dayLabels array to put Sunday as the first item
975
975
  this.dayLabels.unshift(this.dayLabels.pop());
976
- }
977
- if (weekStartDayParam?.toLowerCase() === "monday") {
976
+ } else {
978
977
  this.config.weekStartDay = "monday";
979
978
  }
980
979
  };
@@ -987,10 +986,13 @@ Datepicker.prototype.setWeekStartDay = function () {
987
986
  *
988
987
  */
989
988
  Datepicker.prototype.isExcludedDate = function (date) {
989
+ // This comparison does not work correctly - it will exclude the mindate itself
990
+ // see: https://github.com/ministryofjustice/moj-frontend/issues/923
990
991
  if (this.minDate && this.minDate > date) {
991
992
  return true;
992
993
  }
993
994
 
995
+ // This comparison works as expected - the maxdate will not be excluded
994
996
  if (this.maxDate && this.maxDate < date) {
995
997
  return true;
996
998
  }
@@ -1430,6 +1432,10 @@ DSCalendarDay.prototype.update = function (day, hidden, disabled) {
1430
1432
  } else {
1431
1433
  this.button.style.display = "block";
1432
1434
  }
1435
+ this.button.setAttribute(
1436
+ "data-testid",
1437
+ this.picker.formattedDateFromDate(day),
1438
+ );
1433
1439
 
1434
1440
  this.button.innerHTML = `<span class="govuk-visually-hidden">${accessibleLabel}</span><span aria-hidden="true">${label}</span>`;
1435
1441
  this.date = new Date(day);
@@ -1932,71 +1938,6 @@ if(MOJFrontend.dragAndDropSupported() && MOJFrontend.formDataSupported() && MOJF
1932
1938
  };
1933
1939
  }
1934
1940
 
1935
- MOJFrontend.MultiSelect = function(options) {
1936
- this.container = $(options.container);
1937
-
1938
- if (this.container.data('moj-multi-select-initialised')) {
1939
- return
1940
- }
1941
-
1942
- this.container.data('moj-multi-select-initialised', true);
1943
-
1944
- this.toggle = $(this.getToggleHtml());
1945
- this.toggleButton = this.toggle.find('input');
1946
- this.toggleButton.on('click', $.proxy(this, 'onButtonClick'));
1947
- this.container.append(this.toggle);
1948
- this.checkboxes = $(options.checkboxes);
1949
- this.checkboxes.on('click', $.proxy(this, 'onCheckboxClick'));
1950
- this.checked = options.checked || false;
1951
- };
1952
-
1953
- MOJFrontend.MultiSelect.prototype.getToggleHtml = function() {
1954
- var html = '';
1955
- html += '<div class="govuk-checkboxes__item govuk-checkboxes--small moj-multi-select__checkbox">';
1956
- html += ' <input type="checkbox" class="govuk-checkboxes__input" id="checkboxes-all">';
1957
- html += ' <label class="govuk-label govuk-checkboxes__label moj-multi-select__toggle-label" for="checkboxes-all">';
1958
- html += ' <span class="govuk-visually-hidden">Select all</span>';
1959
- html += ' </label>';
1960
- html += '</div>';
1961
- return html;
1962
- };
1963
-
1964
- MOJFrontend.MultiSelect.prototype.onButtonClick = function(e) {
1965
- if(this.checked) {
1966
- this.uncheckAll();
1967
- this.toggleButton[0].checked = false;
1968
- } else {
1969
- this.checkAll();
1970
- this.toggleButton[0].checked = true;
1971
- }
1972
- };
1973
-
1974
- MOJFrontend.MultiSelect.prototype.checkAll = function() {
1975
- this.checkboxes.each($.proxy(function(index, el) {
1976
- el.checked = true;
1977
- }, this));
1978
- this.checked = true;
1979
- };
1980
-
1981
- MOJFrontend.MultiSelect.prototype.uncheckAll = function() {
1982
- this.checkboxes.each($.proxy(function(index, el) {
1983
- el.checked = false;
1984
- }, this));
1985
- this.checked = false;
1986
- };
1987
-
1988
- MOJFrontend.MultiSelect.prototype.onCheckboxClick = function(e) {
1989
- if(!e.target.checked) {
1990
- this.toggleButton[0].checked = false;
1991
- this.checked = false;
1992
- } else {
1993
- if(this.checkboxes.filter(':checked').length === this.checkboxes.length) {
1994
- this.toggleButton[0].checked = true;
1995
- this.checked = true;
1996
- }
1997
- }
1998
- };
1999
-
2000
1941
  MOJFrontend.PasswordReveal = function(element) {
2001
1942
  this.el = element;
2002
1943
  var $el = $(this.el)
@@ -2170,6 +2111,71 @@ if('contentEditable' in document.documentElement) {
2170
2111
 
2171
2112
  }
2172
2113
 
2114
+ MOJFrontend.MultiSelect = function(options) {
2115
+ this.container = $(options.container);
2116
+
2117
+ if (this.container.data('moj-multi-select-initialised')) {
2118
+ return
2119
+ }
2120
+
2121
+ this.container.data('moj-multi-select-initialised', true);
2122
+
2123
+ this.toggle = $(this.getToggleHtml());
2124
+ this.toggleButton = this.toggle.find('input');
2125
+ this.toggleButton.on('click', $.proxy(this, 'onButtonClick'));
2126
+ this.container.append(this.toggle);
2127
+ this.checkboxes = $(options.checkboxes);
2128
+ this.checkboxes.on('click', $.proxy(this, 'onCheckboxClick'));
2129
+ this.checked = options.checked || false;
2130
+ };
2131
+
2132
+ MOJFrontend.MultiSelect.prototype.getToggleHtml = function() {
2133
+ var html = '';
2134
+ html += '<div class="govuk-checkboxes__item govuk-checkboxes--small moj-multi-select__checkbox">';
2135
+ html += ' <input type="checkbox" class="govuk-checkboxes__input" id="checkboxes-all">';
2136
+ html += ' <label class="govuk-label govuk-checkboxes__label moj-multi-select__toggle-label" for="checkboxes-all">';
2137
+ html += ' <span class="govuk-visually-hidden">Select all</span>';
2138
+ html += ' </label>';
2139
+ html += '</div>';
2140
+ return html;
2141
+ };
2142
+
2143
+ MOJFrontend.MultiSelect.prototype.onButtonClick = function(e) {
2144
+ if(this.checked) {
2145
+ this.uncheckAll();
2146
+ this.toggleButton[0].checked = false;
2147
+ } else {
2148
+ this.checkAll();
2149
+ this.toggleButton[0].checked = true;
2150
+ }
2151
+ };
2152
+
2153
+ MOJFrontend.MultiSelect.prototype.checkAll = function() {
2154
+ this.checkboxes.each($.proxy(function(index, el) {
2155
+ el.checked = true;
2156
+ }, this));
2157
+ this.checked = true;
2158
+ };
2159
+
2160
+ MOJFrontend.MultiSelect.prototype.uncheckAll = function() {
2161
+ this.checkboxes.each($.proxy(function(index, el) {
2162
+ el.checked = false;
2163
+ }, this));
2164
+ this.checked = false;
2165
+ };
2166
+
2167
+ MOJFrontend.MultiSelect.prototype.onCheckboxClick = function(e) {
2168
+ if(!e.target.checked) {
2169
+ this.toggleButton[0].checked = false;
2170
+ this.checked = false;
2171
+ } else {
2172
+ if(this.checkboxes.filter(':checked').length === this.checkboxes.length) {
2173
+ this.toggleButton[0].checked = true;
2174
+ this.checked = true;
2175
+ }
2176
+ }
2177
+ };
2178
+
2173
2179
  MOJFrontend.SearchToggle = function (options) {
2174
2180
  this.options = options;
2175
2181
  this.container = $(this.options.search.container);
@@ -15,7 +15,7 @@
15
15
  * @param {DatepickerConfig} config - config object
16
16
  * @constructor
17
17
  */
18
- function Datepicker($module, config) {
18
+ function Datepicker($module, config = {}) {
19
19
  if (!$module) {
20
20
  return this;
21
21
  }
@@ -178,7 +178,7 @@ Datepicker.prototype.initControls = function () {
178
178
  );
179
179
 
180
180
  this.$dialog.addEventListener("keydown", (event) => {
181
- if (event.key == "Escape") {
181
+ if (event.key === "Escape") {
182
182
  this.closeDialog();
183
183
  event.preventDefault();
184
184
  event.stopPropagation();
@@ -421,8 +421,7 @@ Datepicker.prototype.setWeekStartDay = function () {
421
421
  this.config.weekStartDay = "sunday";
422
422
  // Rotate dayLabels array to put Sunday as the first item
423
423
  this.dayLabels.unshift(this.dayLabels.pop());
424
- }
425
- if (weekStartDayParam?.toLowerCase() === "monday") {
424
+ } else {
426
425
  this.config.weekStartDay = "monday";
427
426
  }
428
427
  };
@@ -435,10 +434,13 @@ Datepicker.prototype.setWeekStartDay = function () {
435
434
  *
436
435
  */
437
436
  Datepicker.prototype.isExcludedDate = function (date) {
437
+ // This comparison does not work correctly - it will exclude the mindate itself
438
+ // see: https://github.com/ministryofjustice/moj-frontend/issues/923
438
439
  if (this.minDate && this.minDate > date) {
439
440
  return true;
440
441
  }
441
442
 
443
+ // This comparison works as expected - the maxdate will not be excluded
442
444
  if (this.maxDate && this.maxDate < date) {
443
445
  return true;
444
446
  }
@@ -878,6 +880,10 @@ DSCalendarDay.prototype.update = function (day, hidden, disabled) {
878
880
  } else {
879
881
  this.button.style.display = "block";
880
882
  }
883
+ this.button.setAttribute(
884
+ "data-testid",
885
+ this.picker.formattedDateFromDate(day),
886
+ );
881
887
 
882
888
  this.button.innerHTML = `<span class="govuk-visually-hidden">${accessibleLabel}</span><span aria-hidden="true">${label}</span>`;
883
889
  this.date = new Date(day);