@ministryofjustice/frontend 3.0.3 → 3.2.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
@@ -77,7 +77,8 @@ MOJFrontend.initAll = function (options) {
77
77
  MOJFrontend.nodeListForEach($multiSelects, function ($multiSelect) {
78
78
  new MOJFrontend.MultiSelect({
79
79
  container: $multiSelect.querySelector($multiSelect.getAttribute('data-multi-select-checkbox')),
80
- checkboxes: $multiSelect.querySelectorAll('tbody .govuk-checkboxes__input')
80
+ checkboxes: $multiSelect.querySelectorAll('tbody .govuk-checkboxes__input'),
81
+ id_prefix: $multiSelect.getAttribute('data-multi-select-idprefix'),
81
82
  });
82
83
  });
83
84
 
@@ -567,7 +568,7 @@ MOJFrontend.ButtonMenu.prototype.mergeConfigs = function (...configObjects) {
567
568
  * @param {DatepickerConfig} config - config object
568
569
  * @constructor
569
570
  */
570
- function Datepicker($module, config) {
571
+ function Datepicker($module, config = {}) {
571
572
  if (!$module) {
572
573
  return this;
573
574
  }
@@ -730,7 +731,7 @@ Datepicker.prototype.initControls = function () {
730
731
  );
731
732
 
732
733
  this.$dialog.addEventListener("keydown", (event) => {
733
- if (event.key == "Escape") {
734
+ if (event.key === "Escape") {
734
735
  this.closeDialog();
735
736
  event.preventDefault();
736
737
  event.stopPropagation();
@@ -973,8 +974,7 @@ Datepicker.prototype.setWeekStartDay = function () {
973
974
  this.config.weekStartDay = "sunday";
974
975
  // Rotate dayLabels array to put Sunday as the first item
975
976
  this.dayLabels.unshift(this.dayLabels.pop());
976
- }
977
- if (weekStartDayParam?.toLowerCase() === "monday") {
977
+ } else {
978
978
  this.config.weekStartDay = "monday";
979
979
  }
980
980
  };
@@ -987,10 +987,13 @@ Datepicker.prototype.setWeekStartDay = function () {
987
987
  *
988
988
  */
989
989
  Datepicker.prototype.isExcludedDate = function (date) {
990
+ // This comparison does not work correctly - it will exclude the mindate itself
991
+ // see: https://github.com/ministryofjustice/moj-frontend/issues/923
990
992
  if (this.minDate && this.minDate > date) {
991
993
  return true;
992
994
  }
993
995
 
996
+ // This comparison works as expected - the maxdate will not be excluded
994
997
  if (this.maxDate && this.maxDate < date) {
995
998
  return true;
996
999
  }
@@ -1430,6 +1433,10 @@ DSCalendarDay.prototype.update = function (day, hidden, disabled) {
1430
1433
  } else {
1431
1434
  this.button.style.display = "block";
1432
1435
  }
1436
+ this.button.setAttribute(
1437
+ "data-testid",
1438
+ this.picker.formattedDateFromDate(day),
1439
+ );
1433
1440
 
1434
1441
  this.button.innerHTML = `<span class="govuk-visually-hidden">${accessibleLabel}</span><span aria-hidden="true">${label}</span>`;
1435
1442
  this.date = new Date(day);
@@ -1941,7 +1948,13 @@ MOJFrontend.MultiSelect = function(options) {
1941
1948
 
1942
1949
  this.container.data('moj-multi-select-initialised', true);
1943
1950
 
1944
- this.toggle = $(this.getToggleHtml());
1951
+ const idPrefix = options.id_prefix;
1952
+ let allId = 'checkboxes-all';
1953
+ if (typeof idPrefix !== 'undefined') {
1954
+ allId = idPrefix + 'checkboxes-all';
1955
+ }
1956
+
1957
+ this.toggle = $(this.getToggleHtml(allId));
1945
1958
  this.toggleButton = this.toggle.find('input');
1946
1959
  this.toggleButton.on('click', $.proxy(this, 'onButtonClick'));
1947
1960
  this.container.append(this.toggle);
@@ -1950,11 +1963,11 @@ MOJFrontend.MultiSelect = function(options) {
1950
1963
  this.checked = options.checked || false;
1951
1964
  };
1952
1965
 
1953
- MOJFrontend.MultiSelect.prototype.getToggleHtml = function() {
1954
- var html = '';
1966
+ MOJFrontend.MultiSelect.prototype.getToggleHtml = function (allId) {
1967
+ let html = '';
1955
1968
  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">';
1969
+ html += ` <input type="checkbox" class="govuk-checkboxes__input" id="${allId}">`;
1970
+ html += ` <label class="govuk-label govuk-checkboxes__label moj-multi-select__toggle-label" for="${allId}">`;
1958
1971
  html += ' <span class="govuk-visually-hidden">Select all</span>';
1959
1972
  html += ' </label>';
1960
1973
  html += '</div>';
@@ -9,6 +9,7 @@
9
9
  @import "filter/filter";
10
10
  @import "header/header";
11
11
  @import "identity-bar/identity-bar";
12
+ @import "interruption-card/interruption-card";
12
13
  @import "messages/messages";
13
14
  @import "multi-file-upload/multi-file-upload";
14
15
  @import "multi-select/multi-select";
@@ -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);