@ukhomeoffice/cop-react-form-renderer 4.69.3 → 4.70.1
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.
|
@@ -86,6 +86,12 @@ var Collection = function Collection(_ref) {
|
|
|
86
86
|
return _ref3.apply(this, arguments);
|
|
87
87
|
};
|
|
88
88
|
}();
|
|
89
|
+
(0, _react.useEffect)(function () {
|
|
90
|
+
if (config.minimumEntries && !value.length) {
|
|
91
|
+
onAddAnother();
|
|
92
|
+
}
|
|
93
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
94
|
+
}, [config.minimumEntries, value.length]);
|
|
89
95
|
var onRemoveItem = /*#__PURE__*/function () {
|
|
90
96
|
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(item) {
|
|
91
97
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
@@ -123,7 +129,7 @@ var Collection = function Collection(_ref) {
|
|
|
123
129
|
var removeLabel = _utils.default.interpolateString(labels.remove, _objectSpread(_objectSpread({}, item), {}, {
|
|
124
130
|
index: labelCount
|
|
125
131
|
}));
|
|
126
|
-
var removeStyle = config.disableAddAndRemove ? '' : (_config$removeLocatio = config.removeLocation) !== null && _config$removeLocatio !== void 0 ? _config$removeLocatio : 'start';
|
|
132
|
+
var removeStyle = config.disableAddAndRemove || index === 0 && config.minimumEntries ? '' : (_config$removeLocatio = config.removeLocation) !== null && _config$removeLocatio !== void 0 ? _config$removeLocatio : 'start';
|
|
127
133
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
128
134
|
className: "".concat(classes('item')),
|
|
129
135
|
key: item.id
|
|
@@ -398,4 +398,57 @@ describe('components.FormComponent.Collection', function () {
|
|
|
398
398
|
}
|
|
399
399
|
}, _callee9);
|
|
400
400
|
})));
|
|
401
|
+
it('should render a collection component with minimumEntries appropriately', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
|
|
402
|
+
var COLLECTION, _renderWithValidation6, container, c, item, _item$childNodes3, title, itemContainer, formGroup, label, hint, input;
|
|
403
|
+
return _regeneratorRuntime().wrap(function _callee10$(_context10) {
|
|
404
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
405
|
+
case 0:
|
|
406
|
+
COLLECTION = {
|
|
407
|
+
id: ID,
|
|
408
|
+
fieldId: ID,
|
|
409
|
+
type: _models.ComponentTypes.COLLECTION,
|
|
410
|
+
item: [TEXT_COMPONENT],
|
|
411
|
+
minimumEntries: 1
|
|
412
|
+
};
|
|
413
|
+
_renderWithValidation6 = (0, _setupTests.renderWithValidation)( /*#__PURE__*/_react2.default.createElement(_FormComponent.default, {
|
|
414
|
+
component: COLLECTION,
|
|
415
|
+
value: [],
|
|
416
|
+
formData: {}
|
|
417
|
+
})), container = _renderWithValidation6.container; // Check the container itself.
|
|
418
|
+
c = container.childNodes[0];
|
|
419
|
+
expect(c.tagName).toEqual('DIV');
|
|
420
|
+
expect(c.classList).toContain(_Collection.DEFAULT_CLASS);
|
|
421
|
+
|
|
422
|
+
// And now check the single text component within it.
|
|
423
|
+
item = c.childNodes[0];
|
|
424
|
+
expect(item.tagName).toEqual('DIV');
|
|
425
|
+
expect(item.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item"));
|
|
426
|
+
_item$childNodes3 = _slicedToArray(item.childNodes, 2), title = _item$childNodes3[0], itemContainer = _item$childNodes3[1];
|
|
427
|
+
expect(title.tagName).toEqual('LABEL');
|
|
428
|
+
expect(title.classList).toContain("".concat(_Collection.DEFAULT_CLASS, "__item-title"));
|
|
429
|
+
expect(itemContainer.tagName).toEqual('DIV');
|
|
430
|
+
expect(itemContainer.classList).toContain(_Container.DEFAULT_CLASS);
|
|
431
|
+
formGroup = itemContainer.childNodes[0];
|
|
432
|
+
expect(formGroup.tagName).toEqual('DIV');
|
|
433
|
+
expect(formGroup.classList).toContain('govuk-form-group');
|
|
434
|
+
label = formGroup.childNodes[0].childNodes[0].childNodes[0];
|
|
435
|
+
expect(label.tagName).toEqual('LABEL');
|
|
436
|
+
expect(label.classList).toContain('govuk-label');
|
|
437
|
+
expect(label.textContent).toEqual("".concat(TEXT_COMPONENT.label, " (optional)"));
|
|
438
|
+
expect(label.getAttribute('for')).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
|
|
439
|
+
hint = formGroup.childNodes[0].childNodes[1];
|
|
440
|
+
expect(hint.tagName).toEqual('DIV');
|
|
441
|
+
expect(hint.classList).toContain('govuk-hint');
|
|
442
|
+
expect(hint.textContent).toEqual(TEXT_COMPONENT.hint);
|
|
443
|
+
input = formGroup.childNodes[0].childNodes[2];
|
|
444
|
+
expect(input.tagName).toEqual('INPUT');
|
|
445
|
+
expect(input.classList).toContain('govuk-input');
|
|
446
|
+
expect(input.id).toEqual("".concat(ID, "[0].").concat(TEXT_ID));
|
|
447
|
+
expect(input.value).toEqual('');
|
|
448
|
+
case 30:
|
|
449
|
+
case "end":
|
|
450
|
+
return _context10.stop();
|
|
451
|
+
}
|
|
452
|
+
}, _callee10);
|
|
453
|
+
})));
|
|
401
454
|
});
|
|
@@ -13,6 +13,7 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
|
|
|
13
13
|
var createMasterPage = function createMasterPage(page) {
|
|
14
14
|
return {
|
|
15
15
|
id: page.id,
|
|
16
|
+
name: page.name,
|
|
16
17
|
collection: _objectSpread({
|
|
17
18
|
masterPage: true
|
|
18
19
|
}, page.collection),
|